basics back

This commit is contained in:
Torsten Ruger 2015-08-29 16:30:15 +03:00
parent 4b82189255
commit b3b2d1be6a
2 changed files with 17 additions and 12 deletions

View File

@ -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

View File

@ -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