move attributes under contractor

as it is essential that attributes are in the same order for the json
to work
This commit is contained in:
Torsten Ruger 2015-07-11 22:00:11 +03:00
parent 657d6319ad
commit 95fbc3de1a
6 changed files with 58 additions and 46 deletions

View File

@ -7,47 +7,56 @@ module Ast
def initialize val
@value = val
end
def attributes
[:value]
end
def inspect
self.class.name + ".new(" + value.to_s+ ")"
end
def to_s
value.to_s
end
def attributes
[:value]
end
end
class TrueExpression < Expression
def to_s
"true"
end
def attributes
[]
end
end
class FalseExpression < Expression
def to_s
"false"
end
def attributes
[]
end
end
class NilExpression < Expression
def to_s
"nil"
end
def attributes
[]
end
end
class NameExpression < Expression
attr_reader :name
def initialize name
@name = name.to_sym
end
def attributes
[:name]
end
def inspect
"#{self.class.name}.new(#{name.inspect})"
end
def to_s
name.to_s
end
def attributes
[:name]
end
end
class VariableExpression < NameExpression
@ -61,15 +70,15 @@ module Ast
def initialize str
@string = str
end
def attributes
[:string]
end
def inspect
self.class.name + '.new("' + string + '")'
end
def to_s
'"' + string.to_s + '"'
end
def attributes
[:string]
end
end
end
end

View File

@ -1,24 +1,24 @@
module Ast
# assignment, like operators are really function calls
class CallSiteExpression < Expression
attr_reader :name, :args , :receiver
def initialize name, args , receiver = Ast::NameExpression.new(:self)
@name = name.to_sym
@args = args
@args = args
@receiver = receiver
end
def inspect
self.class.name + ".new(" + name.inspect + ", ["+
args.collect{|m| m.inspect }.join( ",") + "] ," + receiver.inspect + ")"
end
def to_s
"#{name}(" + args.join(",") + ")"
end
def attributes
[:name , :args , :receiver]
end
end
end
def inspect
self.class.name + ".new(" + name.inspect + ", ["+
args.collect{|m| m.inspect }.join( ",") + "] ," + receiver.inspect + ")"
end
def to_s
"#{name}(" + args.join(",") + ")"
end
end
end

View File

@ -2,29 +2,30 @@ module Ast
class ArrayExpression < Expression
attr_reader :values
def attributes
[:values]
end
def initialize vals
@values = vals
end
def inspect
self.class.name + ".new(" + values.to_s+ ")"
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 attributes
[:key , :value]
end
def inspect
self.class.name + ".new(" + key.inspect + " , " + value.inspect + ")"
end
end
class HashExpression < ArrayExpression
end
end
end

View File

@ -14,5 +14,7 @@ module Ast
def to_s
expressions.collect(&:inspect).join("\n")
end
end
end
end

View File

@ -4,12 +4,12 @@ module Ast
def initialize cond, if_true, if_false
@cond, @if_true, @if_false = cond, if_true, if_false
end
def inspect
self.class.name + ".new(" + cond.inspect + ", "+
if_true.inspect + "," + if_false.inspect + " )"
end
def attributes
[:cond, :if_true, :if_false]
end
def inspect
self.class.name + ".new(" + cond.inspect + ", "+
if_true.inspect + "," + if_false.inspect + " )"
end
end
end
end

View File

@ -7,15 +7,15 @@ module Ast
@name = name.to_sym
@expressions = expressions
end
def attributes
[:name , :expressions]
end
def inspect
self.class.name + ".new(" + @name.inspect + " ," + @expressions.inspect + " )"
self.class.name + ".new(" + @name.inspect + " ," + @expressions.inspect + " )"
end
def to_s
"module #{name}\n #{expressions}\nend\n"
end
def attributes
[:name , :expressions]
end
end
class ClassExpression < ModuleExpression
@ -24,9 +24,12 @@ module Ast
super(name , expressions)
@derived_from = derived
end
def attributes
[:name , :derived_from , :expressions]
end
def inspect
self.class.name + ".new(" + @name.inspect + " ," +
@derived_from.inspect + ", " + @expressions.inspect + " )"
self.class.name + ".new(" + @name.inspect + " ," +
@derived_from.inspect + ", " + @expressions.inspect + " )"
end
def derived_from
@derived_from ? @derived_from : :Object
@ -34,8 +37,5 @@ module Ast
def to_s
s = "class #{name} < #{derived_from}\n #{expressions}\nend\n"
end
def attributes
[:name , :derived_from , :expressions]
end
end
end
end