From 8bd6c8b0cdb7d37dec0ed37eefbe80e4bd09c742 Mon Sep 17 00:00:00 2001 From: inglorion Date: Sat, 19 Oct 2013 05:01:26 -0700 Subject: [PATCH] fixed parsing of numbers after line continuations --- lib/voodoo/parser.rb | 20 ++++++++++++++++++-- test/test_parser.rb | 4 ++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/voodoo/parser.rb b/lib/voodoo/parser.rb index 2ec79c8..776fd41 100644 --- a/lib/voodoo/parser.rb +++ b/lib/voodoo/parser.rb @@ -320,8 +320,13 @@ module Voodoo # This method should be called while the lookahead is the first # character of the symbol name. def parse_symbol + parse_symbol1 '' + end + + # Continues parsing a symbol. + # +name+ the part of the symbol that has already been parsed. + def parse_symbol1 name wrap_exceptions do - name = '' while lookahead != :eof case lookahead when "\\" @@ -547,9 +552,20 @@ module Voodoo when NUMBER_STARTER # Digit; parse number parse_number + when "\\" + # Check if this is the line continuation escape or some other escape. + decoded = parse_escape + if decoded == '' + # Line continuation. Now that we've parsed that, try again. + try_parse_token + else + # Some other escape. That means it's a symbol. + parse_symbol1 decoded + end when SYMBOL_STARTER # Letter, underscore, or backslash; parse symbol - # Note: \w matches digits, too, so keep this case after \d + # Note: SYMBOL_STARTER matches digits and backslashes, too, so + # keep it after the cases that match those. parse_symbol when STRING_STARTER # Double quote; parse string diff --git a/test/test_parser.rb b/test/test_parser.rb index 0aefe7e..93c2192 100755 --- a/test/test_parser.rb +++ b/test/test_parser.rb @@ -180,6 +180,10 @@ def test_parser "function x y\nreturn add x y\nend function\n", [[:function, [:x, :y], [:return, :add, :x, :y]]] + parser_test "continued", "call foo \\\n bar", [[:call, :foo, :bar]] + + parser_test "continued_number", "call foo \\\n 42", [[:call, :foo, 42]] + parser_test_error("io_error_start", BrokenStringReader.new("section data", 0), Voodoo::Parser::ParserInternalError, -- 2.11.4.GIT