adding tokens to basic types

This commit is contained in:
Torsten Ruger 2015-09-12 19:33:21 +03:00
parent ca8e63d8f3
commit c538679c67
5 changed files with 52 additions and 22 deletions

View File

@ -37,6 +37,3 @@ DEPENDENCIES
rake
rubygems-tasks
salama-reader!
BUNDLED WITH
1.10.5

View File

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

View File

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