improving the string according to kasper

This commit is contained in:
Torsten Ruger
2014-05-09 13:51:47 +03:00
parent e4dce2394c
commit 8e6297dcff
5 changed files with 29 additions and 18 deletions

View File

@ -29,19 +29,16 @@ class TestBasic < MiniTest::Test
def test_string
@string_input = "\"hello\""
@parse_output = {:string=>"hello"}
@parse_output = {:string=>[{:char=>"h"}, {:char=>"e"}, {:char=>"l"}, {:char=>"l"}, {:char=>"o"}]}
@transform_output = Ast::StringExpression.new('hello')
@parser = @parser.string
end
def test_string_escapes
out = "hello nyou"
out[6] = '\\'
@string_input = "\"#{out}\""
# puts will show that this is a string with a \n in it.
# but he who knows the ruby string rules well enough to do this in the input may win a beer at the ...
# puts @string_input
@parse_output = {:string=>out} #chop quotes off
out = 'hello \nyou'
@string_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"}]}
@transform_output = Ast::StringExpression.new(out)
@parser = @parser.string
end

View File

@ -24,7 +24,8 @@ class TestFunctionCall < MiniTest::Test
def test_function_call_string
@string_input = 'puts( "hello")'
@parse_output = {:function_call => {:name => 'puts' },
:argument_list => [{:argument => {:string => 'hello'}}]}
:argument_list => [{:argument =>
{:string=>[{:char=>"h"}, {:char=>"e"}, {:char=>"l"}, {:char=>"l"}, {:char=>"o"}]}}]}
@transform_output = Ast::FuncallExpression.new "puts", [Ast::StringExpression.new("hello")]
@parser = @parser.function_call
end

View File

@ -20,7 +20,7 @@ class TestRunner < MiniTest::Test
def execute file
string = File.read(file)
parser = Parser::Composed.new
syntax = parser.function_definition.parse_with_debug(string)
syntax = parser.parse_with_debug(string)
program = Vm::Program.new "Arm"
main = Parser::Transform.new.apply(syntax)