add instance variables and module name as basic types (as name was there already) and add tests

This commit is contained in:
Torsten Ruger
2014-05-30 14:25:08 +03:00
parent 497211f027
commit 3156887a81
4 changed files with 29 additions and 6 deletions

View File

@ -28,7 +28,7 @@ module Parser
# TODO rule forbit names like if_true, because it starts with a keyword. a little looser please!
rule(:name) { keyword.absent? >> (match['a-z_'] >> match['a-zA-Z0-9_'].repeat).as(:name) >> space? }
# instance variables must have the @
rule(:instance_variable) { (match('@') >> name).as(:instance_variable) }
rule(:instance_variable) { (str('@') >> name).as(:instance_variable) }
# and class/module names must start with capital
# (admittatly the rule matches constants too, but one step at a time)
rule(:module_name) { keyword.absent? >> (match['A-Z'] >> match['a-zA-Z0-9_'].repeat).as(:module_name) >> space? }
@ -43,6 +43,6 @@ module Parser
rule(:float) { integer >> dot >> integer >>
(exponent >> sign.maybe >> digit.repeat(1,3)).maybe >> space?}
rule(:basic_type){ integer | name | string | float }
rule(:basic_type){ integer | name | string | float | instance_variable | module_name }
end
end