From ba7ecbfa7bc34336e378e04522f1079e633ae19f Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Fri, 9 Oct 2015 17:24:23 +0300 Subject: [PATCH] fix basic types --- lib/parser/basic_types.rb | 14 ++++++++------ test/cases/basic_type/class_name.tst | 3 +-- test/cases/basic_type/name.tst | 5 ++--- test/cases/basic_type/name_underscode_middle.tst | 5 ++--- test/cases/basic_type/name_underscode_start.tst | 5 ++--- test/cases/basic_type/number.tst | 5 ++--- test/cases/basic_type/string.tst | 6 ++---- test/cases/basic_type/string_escapes.tst | 6 ++---- 8 files changed, 21 insertions(+), 28 deletions(-) diff --git a/lib/parser/basic_types.rb b/lib/parser/basic_types.rb index f0d0c00..9e86039 100644 --- a/lib/parser/basic_types.rb +++ b/lib/parser/basic_types.rb @@ -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 diff --git a/test/cases/basic_type/class_name.tst b/test/cases/basic_type/class_name.tst index adf9580..1ff5434 100644 --- a/test/cases/basic_type/class_name.tst +++ b/test/cases/basic_type/class_name.tst @@ -1,4 +1,3 @@ FooBar -- -- -- -s(:expressions, - s(:module, "FooBar")) +s(:class_name, :FooBar) diff --git a/test/cases/basic_type/name.tst b/test/cases/basic_type/name.tst index 4d7d6d3..d91a7f4 100644 --- a/test/cases/basic_type/name.tst +++ b/test/cases/basic_type/name.tst @@ -1,4 +1,3 @@ -foo +foo -- -- -- -s(:expressions, - s(:name, :foo)) +s(:name, :foo) diff --git a/test/cases/basic_type/name_underscode_middle.tst b/test/cases/basic_type/name_underscode_middle.tst index f0e328e..8cb86e1 100644 --- a/test/cases/basic_type/name_underscode_middle.tst +++ b/test/cases/basic_type/name_underscode_middle.tst @@ -1,4 +1,3 @@ -foo_bar +foo_bar -- -- -- -s(:expressions, - s(:name, :foo_bar)) +s(:name, :foo_bar) diff --git a/test/cases/basic_type/name_underscode_start.tst b/test/cases/basic_type/name_underscode_start.tst index a9a3224..df26452 100644 --- a/test/cases/basic_type/name_underscode_start.tst +++ b/test/cases/basic_type/name_underscode_start.tst @@ -1,4 +1,3 @@ -_bar +_bar -- -- -- -s(:expressions, - s(:name, :_bar)) +s(:name, :_bar) diff --git a/test/cases/basic_type/number.tst b/test/cases/basic_type/number.tst index d90cc26..6e25c5a 100644 --- a/test/cases/basic_type/number.tst +++ b/test/cases/basic_type/number.tst @@ -1,4 +1,3 @@ -42 +42 -- -- -- -s(:expressions, - s(:int, 42)) +s(:int, 42) diff --git a/test/cases/basic_type/string.tst b/test/cases/basic_type/string.tst index 558f50b..4286aff 100644 --- a/test/cases/basic_type/string.tst +++ b/test/cases/basic_type/string.tst @@ -1,4 +1,2 @@ -"hello" --- -- -- -s(:expressions, - s(:string, "hello")) +"hello"-- -- -- +s(:string, "hello") diff --git a/test/cases/basic_type/string_escapes.tst b/test/cases/basic_type/string_escapes.tst index ec0928e..befb9bf 100644 --- a/test/cases/basic_type/string_escapes.tst +++ b/test/cases/basic_type/string_escapes.tst @@ -1,4 +1,2 @@ -"hello \nyou" --- -- -- -s(:expressions, - s(:string, "hello \\nyou")) +"hello \nyou"-- -- -- +s(:string, "hello \\nyou")