Sha256: 92a5f3283169d7fa604ad9e2f7d96bcf574436c14a0e75d189a58905709d18c3
Contents?: true
Size: 1.44 KB
Versions: 4
Compression:
Stored size: 1.44 KB
Contents
# Collection of nodes each one representing an expression. class Nodes < Struct.new(:nodes) def <<(node) nodes << node self end end # Literals are static values that have a Ruby representation, eg.: a string, a number, # true, false, nil, etc. class LiteralNode < Struct.new(:value); end class NumberNode < LiteralNode; end class StringNode < LiteralNode; end class TrueNode < LiteralNode def initialize super(true) end end class FalseNode < LiteralNode def initialize super(false) end end class NilNode < LiteralNode def initialize super(nil) end end # Node of a method call or local variable access, can take any of these forms: # # method # this form can also be a local variable # method(argument1, argument2) # receiver.method # receiver.method(argument1, argument2) # class CallNode < Struct.new(:receiver, :method, :arguments); end # Retrieving the value of a constant. class GetConstantNode < Struct.new(:name); end # Setting the value of a constant. class SetConstantNode < Struct.new(:name, :value); end # Setting the value of a local variable. class SetLocalNode < Struct.new(:name, :value); end # Method definition. class DefNode < Struct.new(:name, :params, :body); end # Class definition. class ClassNode < Struct.new(:name, :body); end # "if" control structure. Look at this node if you want to implement other control # structures like while, for, loop, etc. class IfNode < Struct.new(:condition, :body); end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
sweet-lang-0.3.7 | lib/nodes.rb |
sweet-lang-0.2.2 | lib/nodes.rb |
sweet-lang-0.1.9 | lib/nodes.rb |
sweet-lang-0.1.0 | lib/nodes.rb |