mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
remove dead BlockBody.parse_tag_token and If SIMPLE_CONDITION - now in Cursor
This commit is contained in:
@@ -12,78 +12,6 @@ module Liquid
|
||||
TAGSTART = "{%"
|
||||
VARSTART = "{{"
|
||||
|
||||
# Fast manual tag token parser - avoids regex MatchData allocation
|
||||
# Parses "{%[-] tag_name markup [-]%}" and returns [pre_ws, tag_name, post_ws, markup] or nil
|
||||
NEWLINE_BYTE = 10 # "\n".ord
|
||||
|
||||
class << self
|
||||
attr_reader :_last_markup, :_last_newlines
|
||||
end
|
||||
|
||||
# Fast manual tag token parser - avoids regex MatchData allocation
|
||||
# Parses "{%[-] tag_name markup [-]%}" directly into parse_context fields
|
||||
# Returns tag_name string or nil on failure. Sets @_tag_markup and @_tag_newlines.
|
||||
def self.parse_tag_token(token)
|
||||
# token starts with "{%"
|
||||
pos = 2
|
||||
len = token.length
|
||||
newlines = 0
|
||||
|
||||
# skip optional whitespace control '-'
|
||||
pos += 1 if pos < len && token.getbyte(pos) == 45 # '-'
|
||||
|
||||
# skip pre-whitespace, counting newlines
|
||||
while pos < len
|
||||
b = token.getbyte(pos)
|
||||
if b == NEWLINE_BYTE
|
||||
newlines += 1
|
||||
pos += 1
|
||||
elsif b == 32 || b == 9 || b == 13 # space, tab, \r
|
||||
pos += 1
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
# parse tag name: # or \w+
|
||||
name_start = pos
|
||||
if pos < len && token.getbyte(pos) == 35 # '#'
|
||||
pos += 1
|
||||
else
|
||||
while pos < len
|
||||
b = token.getbyte(pos)
|
||||
break unless (b >= 97 && b <= 122) || (b >= 65 && b <= 90) || (b >= 48 && b <= 57) || b == 95
|
||||
pos += 1
|
||||
end
|
||||
end
|
||||
return nil if pos == name_start
|
||||
tag_name = token.byteslice(name_start, pos - name_start)
|
||||
|
||||
# skip post-whitespace, counting newlines
|
||||
while pos < len
|
||||
b = token.getbyte(pos)
|
||||
if b == NEWLINE_BYTE
|
||||
newlines += 1
|
||||
pos += 1
|
||||
elsif b == 32 || b == 9 || b == 13
|
||||
pos += 1
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
# the rest is markup, up to optional '-' and '%}'
|
||||
markup_end = len - 2
|
||||
markup_end -= 1 if markup_end > pos && token.getbyte(markup_end - 1) == 45
|
||||
markup = pos >= markup_end ? "" : token.byteslice(pos, markup_end - pos)
|
||||
|
||||
# Store extra results to avoid array allocation for the return value
|
||||
@_last_markup = markup
|
||||
@_last_newlines = newlines
|
||||
|
||||
tag_name
|
||||
end
|
||||
|
||||
attr_reader :nodelist
|
||||
|
||||
def initialize
|
||||
|
||||
@@ -85,8 +85,6 @@ module Liquid
|
||||
Condition.parse_expression(parse_context, markup, safe: safe)
|
||||
end
|
||||
|
||||
# Fast path regex for simple conditions: "expr", "expr op expr" (no and/or)
|
||||
SIMPLE_CONDITION = /\A\s*(#{QuotedFragment})\s*(?:([=!<>a-z_]+)\s*(#{QuotedFragment}))?\s*\z/o
|
||||
|
||||
def lax_parse(markup)
|
||||
# Fastest path: simple identifier truthiness like "product.available" or "forloop.first"
|
||||
|
||||
Reference in New Issue
Block a user