mirror of
https://github.com/kemko/liquid.git
synced 2026-01-01 15:55:40 +03:00
Separate ? and - into special tokens
This commit is contained in:
@@ -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+)?/
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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\"")
|
||||
|
||||
Reference in New Issue
Block a user