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 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
attr_reader :name attr_reader :name
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

@ -1,24 +1,24 @@
module Ast module Ast
# assignment, like operators are really function calls # assignment, like operators are really function calls
class CallSiteExpression < Expression class CallSiteExpression < Expression
attr_reader :name, :args , :receiver attr_reader :name, :args , :receiver
def initialize name, args , receiver = Ast::NameExpression.new(:self) def initialize name, args , receiver = Ast::NameExpression.new(:self)
@name = name.to_sym @name = name.to_sym
@args = args @args = args
@receiver = receiver @receiver = receiver
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
def attributes def attributes
[:name , :args , :receiver] [:name , :args , :receiver]
end 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 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
end end
end end

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 inspect
self.class.name + ".new(" + cond.inspect + ", "+
if_true.inspect + "," + if_false.inspect + " )"
end
def attributes def attributes
[:cond, :if_true, :if_false] [:cond, :if_true, :if_false]
end end
def inspect
self.class.name + ".new(" + cond.inspect + ", "+
if_true.inspect + "," + if_false.inspect + " )"
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,9 +24,12 @@ 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 + " )"
end end
def derived_from def derived_from
@derived_from ? @derived_from : :Object @derived_from ? @derived_from : :Object
@ -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