From c538679c67fd28fd891c1ca70b3348f4d85b00a8 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 12 Sep 2015 19:33:21 +0300 Subject: [PATCH] adding tokens to basic types --- Gemfile.lock | 3 -- lib/parser/basic.citrus | 58 ++++++++++++++++++++++++++--- lib/{parser => skip}/basic_types.rb | 0 lib/{parser => skip}/tokens.rb | 0 test/unit/test_basic.rb | 13 ------- 5 files changed, 52 insertions(+), 22 deletions(-) rename lib/{parser => skip}/basic_types.rb (100%) rename lib/{parser => skip}/tokens.rb (100%) diff --git a/Gemfile.lock b/Gemfile.lock index 0e83c6e..fe0aa4a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -37,6 +37,3 @@ DEPENDENCIES rake rubygems-tasks salama-reader! - -BUNDLED WITH - 1.10.5 diff --git a/lib/parser/basic.citrus b/lib/parser/basic.citrus index d472748..cd3d3a9 100644 --- a/lib/parser/basic.citrus +++ b/lib/parser/basic.citrus @@ -42,19 +42,65 @@ grammar BasicTypes rule string_expression #"'" (/.*/ !"'") "'" - ('"' str:(!'"' .)* '"') {Ast::StringExpression.new capture(:str).to_str } - end - - rule instance_variable - ('@' ivar:name_expression) { Ast::VariableExpression.new (capture(:ivar).value).name } + ('"' str:(!'"' .)* '"') {Ast::StringExpression.new(capture(:str).to_str) } end rule basic_expression - name_expression | integer_expression | instance_variable | + name_expression | integer_expression | module_name_expression | string_expression end + # Tokens are single or double character combinations with "meaning" + # braces, comman, point, questionmark , quotes, that kind of thing + # operator symbols are separate in Opreators + rule left_parenthesis + '(' space? + end + + rule right_parenthesis + ')' space? + end + + rule left_brace + '{' space? + end + + rule right_brace + '}' space? + end + + rule left_bracket + '[' space? + end + + rule right_bracket + ']' space? + end + + rule association + "=>" space? + end + + rule comma + ',' space? + end + + rule colon + ':' space? + end + + rule semicolon + ';' space? + end + + rule question_mark + '?' space? + end + + rule excamation_mark + '!' space? + end end diff --git a/lib/parser/basic_types.rb b/lib/skip/basic_types.rb similarity index 100% rename from lib/parser/basic_types.rb rename to lib/skip/basic_types.rb diff --git a/lib/parser/tokens.rb b/lib/skip/tokens.rb similarity index 100% rename from lib/parser/tokens.rb rename to lib/skip/tokens.rb diff --git a/test/unit/test_basic.rb b/test/unit/test_basic.rb index 6607986..c17160f 100644 --- a/test/unit/test_basic.rb +++ b/test/unit/test_basic.rb @@ -54,25 +54,12 @@ class TestBasic < MiniTest::Test check end - def test_instance_variable - @input = '@foo_bar ' - @output = Ast::VariableExpression.new(:foo_bar) - check - end - def test_module_name @input = 'FooBar ' @output = Ast::ModuleName.new("FooBar") check end - def ttest_comment # maybe a non test at this point (higher up) - out = "# i am a comment \n" - @input = out.dup #NEEDS the return, which is what delimits the comment - @output = @output #dont transform - check - end - def test_string @input = '"hello"' @output = Ast::StringExpression.new('hello')