fix basic types

This commit is contained in:
Torsten Ruger 2015-10-09 17:24:23 +03:00
parent 97cf5e5bea
commit ba7ecbfa7b
8 changed files with 21 additions and 28 deletions

View File

@ -38,11 +38,10 @@ module Parser
rule(:type) { (str("int") | str("ref")).as(:type) >> space }
# identifier must start with lower case
# TODO rule forbit names like if_true, because it starts with a keyword. a little looser please!
# TODO rule forbit names like true_statements, because it starts with a keyword. a little looser please!
rule(:name) { (keyword|type).absent? >> (match['a-z_'] >> match['a-zA-Z0-9_'].repeat).as(:name) >> space? }
# fields have type
rule(:field) { type >> name >> (assign >> r_value.as(:value) ).maybe}
rule(:class_field) { keyword_field >> field }
# and class/module names must start with capital
rule(:class_name) { keyword.absent? >> (match['A-Z'] >> match['a-zA-Z0-9_'].repeat).as(:class_name) >> space? }
@ -50,13 +49,16 @@ module Parser
rule(:string) { quote >> (
escape |
nonquote.as(:char)
).repeat(1).as(:string) >> quote }
).repeat(1).as(:string) >> quote >> space? }
rule(:integer) { sign.maybe >> digit.repeat(1).as(:integer) >> space? }
rule(:float) { integer >> dot >> integer >>
(exponent >> sign.maybe >> digit.repeat(1,3)).maybe >> space?}
rule(:basic_type){ integer | name | string | float | field | class_name |
keyword_true | keyword_false | keyword_nil }
rule(:field_access) { name.as(:receiver) >> str(".") >> name.as(:field) }
rule(:basic_type){ integer | name | string | float | class_name |
((keyword_true | keyword_false | keyword_nil) >> space? ) }
end
end

View File

@ -1,4 +1,3 @@
FooBar
-- -- --
s(:expressions,
s(:module, "FooBar"))
s(:class_name, :FooBar)

View File

@ -1,4 +1,3 @@
foo
foo
-- -- --
s(:expressions,
s(:name, :foo))
s(:name, :foo)

View File

@ -1,4 +1,3 @@
foo_bar
foo_bar
-- -- --
s(:expressions,
s(:name, :foo_bar))
s(:name, :foo_bar)

View File

@ -1,4 +1,3 @@
_bar
_bar
-- -- --
s(:expressions,
s(:name, :_bar))
s(:name, :_bar)

View File

@ -1,4 +1,3 @@
42
42
-- -- --
s(:expressions,
s(:int, 42))
s(:int, 42)

View File

@ -1,4 +1,2 @@
"hello"
-- -- --
s(:expressions,
s(:string, "hello"))
"hello"-- -- --
s(:string, "hello")

View File

@ -1,4 +1,2 @@
"hello \nyou"
-- -- --
s(:expressions,
s(:string, "hello \\nyou"))
"hello \nyou"-- -- --
s(:string, "hello \\nyou")