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,31 +7,40 @@ module Ast
def initialize val def initialize val
@value = val @value = val
end end
def attributes
[:value]
end
def inspect def inspect
self.class.name + ".new(" + value.to_s+ ")" self.class.name + ".new(" + value.to_s+ ")"
end end
def to_s def to_s
value.to_s value.to_s
end end
def attributes
[:value]
end
end end
class TrueExpression < Expression class TrueExpression < Expression
def to_s def to_s
"true" "true"
end end
def attributes
[]
end
end end
class FalseExpression < Expression class FalseExpression < Expression
def to_s def to_s
"false" "false"
end end
def attributes
[]
end
end end
class NilExpression < Expression class NilExpression < Expression
def to_s def to_s
"nil" "nil"
end end
def attributes
[]
end
end end
class NameExpression < Expression class NameExpression < Expression
@ -39,15 +48,15 @@ module Ast
def initialize name def initialize name
@name = name.to_sym @name = name.to_sym
end end
def attributes
[:name]
end
def inspect def inspect
"#{self.class.name}.new(#{name.inspect})" "#{self.class.name}.new(#{name.inspect})"
end end
def to_s def to_s
name.to_s name.to_s
end end
def attributes
[:name]
end
end end
class VariableExpression < NameExpression class VariableExpression < NameExpression
@ -61,15 +70,15 @@ module Ast
def initialize str def initialize str
@string = str @string = str
end end
def attributes
[:string]
end
def inspect def inspect
self.class.name + '.new("' + string + '")' self.class.name + '.new("' + string + '")'
end end
def to_s def to_s
'"' + string.to_s + '"' '"' + string.to_s + '"'
end end
def attributes
[:string]
end
end end
end end

View File

@ -9,6 +9,9 @@ module Ast
@args = args @args = args
@receiver = receiver @receiver = receiver
end end
def attributes
[:name , :args , :receiver]
end
def inspect def inspect
self.class.name + ".new(" + name.inspect + ", ["+ self.class.name + ".new(" + name.inspect + ", ["+
@ -17,8 +20,5 @@ module Ast
def to_s def to_s
"#{name}(" + args.join(",") + ")" "#{name}(" + args.join(",") + ")"
end end
def attributes
[:name , :args , :receiver]
end
end end
end end

View File

@ -2,27 +2,28 @@ module Ast
class ArrayExpression < Expression class ArrayExpression < Expression
attr_reader :values attr_reader :values
def attributes
[:values]
end
def initialize vals def initialize vals
@values = vals @values = vals
end end
def inspect def inspect
self.class.name + ".new(" + values.to_s+ ")" self.class.name + ".new(" + values.to_s+ ")"
end end
def attributes
[:values]
end
end end
class AssociationExpression < Expression class AssociationExpression < Expression
attr_reader :key , :value attr_reader :key , :value
def initialize key , value def initialize key , value
@key , @value = key , value @key , @value = key , value
end end
def inspect
self.class.name + ".new(" + key.inspect + " , " + value.inspect + ")"
end
def attributes def attributes
[:key , :value] [:key , :value]
end end
def inspect
self.class.name + ".new(" + key.inspect + " , " + value.inspect + ")"
end
end end
class HashExpression < ArrayExpression class HashExpression < ArrayExpression

View File

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

View File

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

View File

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