From b3b2d1be6ac94d4960b758f2c3712eb7db013ef6 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 29 Aug 2015 16:30:15 +0300 Subject: [PATCH] basics back --- lib/parser/basic.citrus | 12 +++++++++++- test/unit/test_basic.rb | 17 ++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/parser/basic.citrus b/lib/parser/basic.citrus index e7cefb1..e2b5a44 100644 --- a/lib/parser/basic.citrus +++ b/lib/parser/basic.citrus @@ -15,6 +15,10 @@ grammar BasicTypes (name:([a-z_] [a-zA-Z0-9_]*) space?) { Ast::NameExpression.new(capture(:name).to_str)} end + rule module_name_expression + (name:([A-Z] [a-zA-Z0-9_]*) space?) { Ast::ModuleName.new(capture(:name).to_str)} + end + rule digits [0-9] [0-9]* end @@ -23,11 +27,17 @@ grammar BasicTypes (digits space?) { Ast::IntegerExpression.new(to_str.to_i) } end + 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 } end rule basic_expression - name_expression | integer_expression | instance_variable + name_expression | integer_expression | instance_variable | + module_name_expression | string_expression end end diff --git a/test/unit/test_basic.rb b/test/unit/test_basic.rb index 0478b30..6607986 100644 --- a/test/unit/test_basic.rb +++ b/test/unit/test_basic.rb @@ -60,33 +60,28 @@ class TestBasic < MiniTest::Test check end - def ttest_module_name + def test_module_name @input = 'FooBar ' - @parse_output = {:module_name=>"FooBar"} @output = Ast::ModuleName.new("FooBar") check end - def ttest_comment + 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 - @parse_output = out - @output = @parse_output #dont transform + @output = @output #dont transform check end - def ttest_string - @input = "\"hello\"" - @parse_output = {:string=>[{:char=>"h"}, {:char=>"e"}, {:char=>"l"}, {:char=>"l"}, {:char=>"o"}]} + def test_string + @input = '"hello"' @output = Ast::StringExpression.new('hello') check end - def ttest_string_escapes + def test_string_escapes out = 'hello \nyou' @input = '"' + out + '"' - @parse_output = {:string=>[{:char=>"h"}, {:char=>"e"}, {:char=>"l"}, {:char=>"l"}, {:char=>"o"}, - {:char=>" "}, {:char=>" "}, {:esc=>"n"}, {:char=>"y"}, {:char=>"o"}, {:char=>"u"}]} @output = Ast::StringExpression.new(out) check end