add bools and nil

This commit is contained in:
Torsten Ruger
2014-06-30 17:51:07 +03:00
parent 040b842333
commit bc8697c733
10 changed files with 85 additions and 4 deletions

View File

@ -18,6 +18,22 @@ module Ast
end
end
class TrueExpression < Expression
def to_s
"true"
end
end
class FalseExpression < Expression
def to_s
"false"
end
end
class NilExpression < Expression
def to_s
"nil"
end
end
class NameExpression < Expression
attr_reader :name
def initialize name

View File

@ -10,7 +10,10 @@
module Ast
class Expression
def attributes
raise "abstract #{self}"
[]
end
def inspect
self.class.name + ".new()"
end
def == other
return false unless other.class == self.class

View File

@ -43,6 +43,7 @@ module Parser
rule(:float) { integer >> dot >> integer >>
(exponent >> sign.maybe >> digit.repeat(1,3)).maybe >> space?}
rule(:basic_type){ integer | name | string | float | instance_variable | module_name }
rule(:basic_type){ integer | name | string | float | instance_variable | module_name |
keyword_true | keyword_false | keyword_nil }
end
end

View File

@ -6,7 +6,10 @@ module Parser
rule(:string => sequence(:chars)) { Ast::StringExpression.new chars.join }
rule(:esc => simple(:esc)) { '\\' + esc }
rule(char: simple(:char)) { char }
rule(:true => simple(:true)) { Ast::TrueExpression.new() }
rule(:false => simple(:false)) { Ast::FalseExpression.new() }
rule(:nil => simple(:nil)) { Ast::NilExpression.new() }
rule(:integer => simple(:value)) { Ast::IntegerExpression.new(value.to_i) }
rule(:name => simple(:name)) { Ast::NameExpression.new(name.to_s) }
rule(:instance_variable => simple(:instance_variable)) { Ast::VariableExpression.new(instance_variable.name) }