mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-29 15:15:19 -07:00
Abstract parser switching into tag
This commit is contained in:
@@ -22,5 +22,20 @@ module Liquid
|
|||||||
def blank?
|
def blank?
|
||||||
@blank || true
|
@blank || true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def switch_parse(markup)
|
||||||
|
case Template.error_mode
|
||||||
|
when :strict then strict_parse(markup)
|
||||||
|
when :lax then lax_parse(markup)
|
||||||
|
when :warn
|
||||||
|
begin
|
||||||
|
return strict_parse(markup)
|
||||||
|
rescue SyntaxError => e
|
||||||
|
@warnings ||= []
|
||||||
|
@warnings << e
|
||||||
|
return lax_parse(markup)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end # Tag
|
end # Tag
|
||||||
end # Liquid
|
end # Liquid
|
||||||
|
|||||||
+1
-16
@@ -46,28 +46,13 @@ module Liquid
|
|||||||
block = if tag == 'else'
|
block = if tag == 'else'
|
||||||
ElseCondition.new
|
ElseCondition.new
|
||||||
else
|
else
|
||||||
parse_condition(markup)
|
switch_parse(markup)
|
||||||
end
|
end
|
||||||
|
|
||||||
@blocks.push(block)
|
@blocks.push(block)
|
||||||
@nodelist = block.attach(Array.new)
|
@nodelist = block.attach(Array.new)
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_condition(markup)
|
|
||||||
case Template.error_mode
|
|
||||||
when :strict then strict_parse(markup)
|
|
||||||
when :lax then lax_parse(markup)
|
|
||||||
when :warn
|
|
||||||
begin
|
|
||||||
return strict_parse(markup)
|
|
||||||
rescue SyntaxError => e
|
|
||||||
@warnings ||= []
|
|
||||||
@warnings << e
|
|
||||||
return lax_parse(markup)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def lax_parse(markup)
|
def lax_parse(markup)
|
||||||
expressions = markup.scan(ExpressionsAndOperators).reverse
|
expressions = markup.scan(ExpressionsAndOperators).reverse
|
||||||
raise(SyntaxError, SyntaxHelp) unless expressions.shift =~ Syntax
|
raise(SyntaxError, SyntaxHelp) unless expressions.shift =~ Syntax
|
||||||
|
|||||||
Reference in New Issue
Block a user