a good stab at array anf hash constants
This commit is contained in:
39
lib/ast/compound_expressions.rb
Normal file
39
lib/ast/compound_expressions.rb
Normal file
@ -0,0 +1,39 @@
|
||||
module Ast
|
||||
|
||||
class ArrayExpression < Expression
|
||||
attr_reader :values
|
||||
def initialize vals
|
||||
@values = vals
|
||||
end
|
||||
def inspect
|
||||
self.class.name + ".new(" + values.to_s+ ")"
|
||||
end
|
||||
def compile context
|
||||
to.do
|
||||
end
|
||||
def attributes
|
||||
[:values]
|
||||
end
|
||||
end
|
||||
class AssociationExpression < Expression
|
||||
attr_reader :key , :value
|
||||
def initialize key , value
|
||||
@key , @value = key , value
|
||||
end
|
||||
def inspect
|
||||
self.class.name + ".new(" + key.inspect + " , " + value.inspect + ")"
|
||||
end
|
||||
def compile context
|
||||
to.do
|
||||
end
|
||||
def attributes
|
||||
[:key , :value]
|
||||
end
|
||||
|
||||
end
|
||||
class HashExpression < ArrayExpression
|
||||
def compile context
|
||||
to.do
|
||||
end
|
||||
end
|
||||
end
|
@ -15,9 +15,6 @@ module Ast
|
||||
def compile context
|
||||
raise "abstract #{self}"
|
||||
end
|
||||
def inspectt
|
||||
self.class.name + ".new(" + self.attributes.collect{|m| self.send(m).inspect }.join( ",") +")"
|
||||
end
|
||||
def attributes
|
||||
raise "abstract #{self}"
|
||||
end
|
||||
@ -36,6 +33,7 @@ module Ast
|
||||
end
|
||||
|
||||
require_relative "basic_expressions"
|
||||
require_relative "compound_expressions"
|
||||
require_relative "conditional_expression"
|
||||
require_relative "while_expression"
|
||||
require_relative "function_expression"
|
||||
|
Reference in New Issue
Block a user