diff --git a/lib/liquid/lexer.rb b/lib/liquid/lexer.rb index 0ecd8e0..cb8e591 100644 --- a/lib/liquid/lexer.rb +++ b/lib/liquid/lexer.rb @@ -9,9 +9,11 @@ module Liquid '['.freeze => :open_square, ']'.freeze => :close_square, '('.freeze => :open_round, - ')'.freeze => :close_round + ')'.freeze => :close_round, + '?'.freeze => :question, + '-'.freeze => :dash } - IDENTIFIER = /[\w\-?!]+/ + IDENTIFIER = /\w+/ SINGLE_STRING_LITERAL = /'[^\']*'/ DOUBLE_STRING_LITERAL = /"[^\"]*"/ NUMBER_LITERAL = /-?\d+(\.\d+)?/ diff --git a/lib/liquid/parser.rb b/lib/liquid/parser.rb index d2006f3..d819156 100644 --- a/lib/liquid/parser.rb +++ b/lib/liquid/parser.rb @@ -75,6 +75,13 @@ module Liquid def variable_signature str = consume(:id) + while consume?(:dash) + str << "-".freeze + str << consume(:id) if look(:id) + end + if consume?(:question) + str << "?".freeze + end if look(:open_square) str << consume str << expression diff --git a/test/unit/lexer_unit_test.rb b/test/unit/lexer_unit_test.rb index 96dadee..ef341a1 100644 --- a/test/unit/lexer_unit_test.rb +++ b/test/unit/lexer_unit_test.rb @@ -31,8 +31,8 @@ class LexerUnitTest < Minitest::Test end def test_fancy_identifiers - tokens = Lexer.new('hi! five?').tokenize - assert_equal [[:id,'hi!'], [:id, 'five?'], [:end_of_string]], tokens + tokens = Lexer.new('hi five?').tokenize + assert_equal [[:id,'hi'], [:id, 'five'], [:question, '?'], [:end_of_string]], tokens end def test_whitespace diff --git a/test/unit/parser_unit_test.rb b/test/unit/parser_unit_test.rb index d483367..9f23337 100644 --- a/test/unit/parser_unit_test.rb +++ b/test/unit/parser_unit_test.rb @@ -44,9 +44,9 @@ class ParserUnitTest < Minitest::Test end def test_expressions - p = Parser.new("hi.there hi[5].! hi.there.bob") + p = Parser.new("hi.there hi?[5].there? hi.there.bob") assert_equal 'hi.there', p.expression - assert_equal 'hi[5].!', p.expression + assert_equal 'hi?[5].there?', p.expression assert_equal 'hi.there.bob', p.expression p = Parser.new("567 6.0 'lol' \"wut\"")