mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-16 09:20:42 -07:00
Use a single token for identifiers
This commit is contained in:
+1
-1
@@ -13,7 +13,7 @@ module Liquid
|
||||
'?'.freeze => :question,
|
||||
'-'.freeze => :dash
|
||||
}
|
||||
IDENTIFIER = /\w+/
|
||||
IDENTIFIER = /[\w-]+\??/
|
||||
SINGLE_STRING_LITERAL = /'[^\']*'/
|
||||
DOUBLE_STRING_LITERAL = /"[^\"]*"/
|
||||
NUMBER_LITERAL = /-?\d+(\.\d+)?/
|
||||
|
||||
@@ -75,13 +75,6 @@ module Liquid
|
||||
|
||||
def variable_signature
|
||||
str = consume(:id)
|
||||
while consume?(:dash)
|
||||
str << "-".freeze
|
||||
str << consume(:id)
|
||||
end
|
||||
if consume?(:question)
|
||||
str << "?".freeze
|
||||
end
|
||||
if look(:open_square)
|
||||
str << consume
|
||||
str << expression
|
||||
|
||||
@@ -32,7 +32,7 @@ class LexerUnitTest < Minitest::Test
|
||||
|
||||
def test_fancy_identifiers
|
||||
tokens = Lexer.new('hi five?').tokenize
|
||||
assert_equal [[:id,'hi'], [:id, 'five'], [:question, '?'], [:end_of_string]], tokens
|
||||
assert_equal [[:id,'hi'], [:id, 'five?'], [:end_of_string]], tokens
|
||||
end
|
||||
|
||||
def test_whitespace
|
||||
|
||||
@@ -102,6 +102,15 @@ class VariableUnitTest < Minitest::Test
|
||||
assert_equal 1000.01, var.name
|
||||
end
|
||||
|
||||
def test_dashes
|
||||
assert_equal VariableLookup.new('foo-bar'), Variable.new('foo-bar').name
|
||||
assert_equal VariableLookup.new('foo-bar-2'), Variable.new('foo-bar-2').name
|
||||
|
||||
with_error_mode :strict do
|
||||
assert_raises(Liquid::SyntaxError) { Variable.new('foo - bar') }
|
||||
end
|
||||
end
|
||||
|
||||
def test_string_with_special_chars
|
||||
var = Variable.new(%| 'hello! $!@.;"ddasd" ' |)
|
||||
assert_equal 'hello! $!@.;"ddasd" ', var.name
|
||||
|
||||
Reference in New Issue
Block a user