mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-15 08:50:45 -07:00
more opt
This commit is contained in:
committed by
Michael Go
parent
d76663f570
commit
be8e329cef
+27
-7
@@ -14,6 +14,9 @@ module Liquid
|
||||
CLOSE_CURLEY = "}".ord
|
||||
PERCENTAGE = "%".ord
|
||||
|
||||
CLOSE_CURLEY_FOLLOWED_BY_CLOSE_CURLEY = (CLOSE_CURLEY << 8) | CLOSE_CURLEY
|
||||
OPEN_CURLEY_FOLLOWED_BY_PERCENTAGE = (OPEN_CURLEY << 8) | PERCENTAGE
|
||||
|
||||
def initialize(source, line_numbers = false, line_number: nil, for_liquid_tag: false)
|
||||
@line_number = line_number || (line_numbers ? 1 : nil)
|
||||
@for_liquid_tag = for_liquid_tag
|
||||
@@ -24,18 +27,34 @@ module Liquid
|
||||
def shift
|
||||
return if @ss.eos?
|
||||
|
||||
token = @for_liquid_tag ? next_liquid_token : next_token
|
||||
@for_liquid_tag ? shift_liquid_tag : shift_normal
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def shift_normal
|
||||
token = next_token
|
||||
|
||||
return nil unless token
|
||||
|
||||
if @line_number
|
||||
@line_number += @for_liquid_tag ? 1 : token.count("\n")
|
||||
@line_number += token.count("\n")
|
||||
end
|
||||
|
||||
token
|
||||
end
|
||||
|
||||
private
|
||||
def shift_liquid_tag
|
||||
token = next_liquid_token
|
||||
|
||||
return (@ss = nil) unless token
|
||||
|
||||
if @line_number
|
||||
@line_number += 1
|
||||
end
|
||||
|
||||
token
|
||||
end
|
||||
|
||||
def next_liquid_token
|
||||
# read until we find a \n
|
||||
@@ -93,20 +112,21 @@ module Liquid
|
||||
byte_b = byte_a
|
||||
|
||||
while byte_b
|
||||
byte_a = @ss.scan_byte while byte_a && byte_a != CLOSE_CURLEY && byte_a != OPEN_CURLEY
|
||||
byte_a = @ss.scan_byte while byte_a && (byte_a != CLOSE_CURLEY && byte_a != OPEN_CURLEY)
|
||||
|
||||
break unless byte_a
|
||||
|
||||
byte_b = @ss.scan_byte
|
||||
|
||||
if byte_b != CLOSE_CURLEY && byte_b != PERCENTAGE
|
||||
if byte_b > CLOSE_CURLEY || (byte_b != CLOSE_CURLEY && byte_b != PERCENTAGE)
|
||||
byte_a = byte_b
|
||||
next
|
||||
end
|
||||
|
||||
if byte_a == CLOSE_CURLEY && byte_b == CLOSE_CURLEY
|
||||
val = (byte_a << 8) | byte_b
|
||||
if val == CLOSE_CURLEY_FOLLOWED_BY_CLOSE_CURLEY
|
||||
return @source.byteslice(start, @ss.pos - start)
|
||||
elsif byte_a == OPEN_CURLEY && byte_b == PERCENTAGE
|
||||
elsif val == OPEN_CURLEY_FOLLOWED_BY_PERCENTAGE
|
||||
return next_tag_token_with_start(start)
|
||||
end
|
||||
end
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ if (env_mode = ENV['LIQUID_PARSER_MODE'])
|
||||
puts "-- #{env_mode.upcase} ERROR MODE"
|
||||
mode = env_mode.to_sym
|
||||
end
|
||||
Liquid::Template.error_mode = mode
|
||||
Liquid::Environment.default.error_mode = mode
|
||||
|
||||
if ENV['LIQUID_C'] == '1'
|
||||
puts "-- LIQUID C"
|
||||
|
||||
Reference in New Issue
Block a user