mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Collapse float and int into 'number'
This commit is contained in:
+2
-4
@@ -12,8 +12,7 @@ module Liquid
|
||||
IDENTIFIER = /[\w\-?!]+/
|
||||
SINGLE_STRING_LITERAL = /'[^\']*'/
|
||||
DOUBLE_STRING_LITERAL = /"[^\"]*"/
|
||||
INTEGER_LITERAL = /-?\d+/
|
||||
FLOAT_LITERAL = /-?\d+\.\d+/
|
||||
NUMBER_LITERAL = /-?\d+(\.\d+)?/
|
||||
COMPARISON_OPERATOR = /==|!=|<>|<=?|>=?|contains/
|
||||
|
||||
def initialize(input)
|
||||
@@ -31,8 +30,7 @@ module Liquid
|
||||
when t = @ss.scan(COMPARISON_OPERATOR) then [:comparison, t]
|
||||
when t = @ss.scan(SINGLE_STRING_LITERAL) then [:string, t]
|
||||
when t = @ss.scan(DOUBLE_STRING_LITERAL) then [:string, t]
|
||||
when t = @ss.scan(FLOAT_LITERAL) then [:float, t]
|
||||
when t = @ss.scan(INTEGER_LITERAL) then [:integer, t]
|
||||
when t = @ss.scan(NUMBER_LITERAL) then [:number, t]
|
||||
when t = @ss.scan(IDENTIFIER) then [:id, t]
|
||||
else
|
||||
c = @ss.getch
|
||||
|
||||
@@ -52,7 +52,7 @@ module Liquid
|
||||
token = @tokens[@p]
|
||||
if token[0] == :id
|
||||
variable_signature
|
||||
elsif [:string, :integer, :float].include? token[0]
|
||||
elsif [:string, :number].include? token[0]
|
||||
consume
|
||||
token[1]
|
||||
else
|
||||
|
||||
@@ -10,12 +10,12 @@ class LexerTest < Test::Unit::TestCase
|
||||
|
||||
def test_integer
|
||||
tokens = Lexer.new('hi 50').tokenize
|
||||
assert_equal [[:id,'hi'], [:integer, '50'], [:end_of_string]], tokens
|
||||
assert_equal [[:id,'hi'], [:number, '50'], [:end_of_string]], tokens
|
||||
end
|
||||
|
||||
def test_float
|
||||
tokens = Lexer.new('hi 5.0').tokenize
|
||||
assert_equal [[:id,'hi'], [:float, '5.0'], [:end_of_string]], tokens
|
||||
assert_equal [[:id,'hi'], [:number, '5.0'], [:end_of_string]], tokens
|
||||
end
|
||||
|
||||
def test_comparison
|
||||
|
||||
@@ -7,13 +7,13 @@ class ParserTest < Test::Unit::TestCase
|
||||
p = Parser.new("wat: 7")
|
||||
assert_equal 'wat', p.consume(:id)
|
||||
assert_equal ':', p.consume(:colon)
|
||||
assert_equal '7', p.consume(:integer)
|
||||
assert_equal '7', p.consume(:number)
|
||||
end
|
||||
|
||||
def test_jump
|
||||
p = Parser.new("wat: 7")
|
||||
p.jump(2)
|
||||
assert_equal '7', p.consume(:integer)
|
||||
assert_equal '7', p.consume(:number)
|
||||
end
|
||||
|
||||
def test_consume?
|
||||
@@ -21,14 +21,14 @@ class ParserTest < Test::Unit::TestCase
|
||||
assert_equal 'wat', p.consume?(:id)
|
||||
assert_equal false, p.consume?(:dot)
|
||||
assert_equal ':', p.consume(:colon)
|
||||
assert_equal '7', p.consume?(:integer)
|
||||
assert_equal '7', p.consume?(:number)
|
||||
end
|
||||
|
||||
def test_id?
|
||||
p = Parser.new("wat 6 Peter Hegemon")
|
||||
assert_equal 'wat', p.id?('wat')
|
||||
assert_equal false, p.id?('endgame')
|
||||
assert_equal '6', p.consume(:integer)
|
||||
assert_equal '6', p.consume(:number)
|
||||
assert_equal 'Peter', p.id?('Peter')
|
||||
assert_equal false, p.id?('Achilles')
|
||||
end
|
||||
@@ -37,10 +37,10 @@ class ParserTest < Test::Unit::TestCase
|
||||
p = Parser.new("wat 6 Peter Hegemon")
|
||||
assert_equal true, p.look(:id)
|
||||
assert_equal 'wat', p.consume(:id)
|
||||
assert_equal false, p.look(:float)
|
||||
assert_equal true, p.look(:integer)
|
||||
assert_equal false, p.look(:comparison)
|
||||
assert_equal true, p.look(:number)
|
||||
assert_equal true, p.look(:id, 1)
|
||||
assert_equal false, p.look(:float, 1)
|
||||
assert_equal false, p.look(:number, 1)
|
||||
end
|
||||
|
||||
def test_expressions
|
||||
|
||||
Reference in New Issue
Block a user