mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-03 09:05:13 -07:00
Rename strict2_parse to parse_markup
This commit is contained in:
@@ -3,19 +3,15 @@
|
|||||||
module Liquid
|
module Liquid
|
||||||
module ParserSwitching
|
module ParserSwitching
|
||||||
def parse_with_selected_parser(markup)
|
def parse_with_selected_parser(markup)
|
||||||
strict2_parse_with_error_context(markup)
|
parse_markup(markup)
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def strict2_parse_with_error_context(markup)
|
|
||||||
strict2_parse(markup)
|
|
||||||
rescue SyntaxError => e
|
rescue SyntaxError => e
|
||||||
e.line_number = line_number
|
e.line_number = line_number
|
||||||
e.markup_context = markup_context(markup)
|
e.markup_context = markup_context(markup)
|
||||||
raise e
|
raise e
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
def markup_context(markup)
|
def markup_context(markup)
|
||||||
"in \"#{markup.strip}\""
|
"in \"#{markup.strip}\""
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ module Liquid
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def strict2_parse(markup)
|
def parse_markup(markup)
|
||||||
parser = @parse_context.new_parser(markup)
|
parser = @parse_context.new_parser(markup)
|
||||||
@left = safe_parse_expression(parser)
|
@left = safe_parse_expression(parser)
|
||||||
parser.consume(:end_of_string)
|
parser.consume(:end_of_string)
|
||||||
@@ -92,14 +92,10 @@ module Liquid
|
|||||||
def record_when_condition(markup)
|
def record_when_condition(markup)
|
||||||
body = new_body
|
body = new_body
|
||||||
|
|
||||||
if strict2_mode?
|
parse_when(markup, body)
|
||||||
parse_strict2_when(markup, body)
|
|
||||||
else
|
|
||||||
parse_lax_when(markup, body)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_strict2_when(markup, body)
|
def parse_when(markup, body)
|
||||||
parser = @parse_context.new_parser(markup)
|
parser = @parse_context.new_parser(markup)
|
||||||
|
|
||||||
loop do
|
loop do
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ module Liquid
|
|||||||
private
|
private
|
||||||
|
|
||||||
# cycle [name:] expression(, expression)*
|
# cycle [name:] expression(, expression)*
|
||||||
def strict2_parse(markup)
|
def parse_markup(markup)
|
||||||
p = @parse_context.new_parser(markup)
|
p = @parse_context.new_parser(markup)
|
||||||
|
|
||||||
@variables = []
|
@variables = []
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ module Liquid
|
|||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def strict2_parse(markup)
|
def parse_markup(markup)
|
||||||
p = @parse_context.new_parser(markup)
|
p = @parse_context.new_parser(markup)
|
||||||
@variable_name = p.consume(:id)
|
@variable_name = p.consume(:id)
|
||||||
raise SyntaxError, options[:locale].t("errors.syntax.for_invalid_in") unless p.id?('in')
|
raise SyntaxError, options[:locale].t("errors.syntax.for_invalid_in") unless p.id?('in')
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ module Liquid
|
|||||||
Condition.parse_expression(parse_context, markup, safe: safe)
|
Condition.parse_expression(parse_context, markup, safe: safe)
|
||||||
end
|
end
|
||||||
|
|
||||||
def strict2_parse(markup)
|
def parse_markup(markup)
|
||||||
p = @parse_context.new_parser(markup)
|
p = @parse_context.new_parser(markup)
|
||||||
condition = parse_binary_comparisons(p)
|
condition = parse_binary_comparisons(p)
|
||||||
p.consume(:end_of_string)
|
p.consume(:end_of_string)
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ module Liquid
|
|||||||
alias_method :parse_context, :options
|
alias_method :parse_context, :options
|
||||||
private :parse_context
|
private :parse_context
|
||||||
|
|
||||||
def strict2_parse(markup)
|
def parse_markup(markup)
|
||||||
p = @parse_context.new_parser(markup)
|
p = @parse_context.new_parser(markup)
|
||||||
|
|
||||||
@template_name_expr = safe_parse_expression(p)
|
@template_name_expr = safe_parse_expression(p)
|
||||||
|
|||||||
@@ -84,10 +84,10 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
# render (string) (with|for expression)? (as id)? (key: value)*
|
# render (string) (with|for expression)? (as id)? (key: value)*
|
||||||
def strict2_parse(markup)
|
def parse_markup(markup)
|
||||||
p = @parse_context.new_parser(markup)
|
p = @parse_context.new_parser(markup)
|
||||||
|
|
||||||
@template_name_expr = parse_expression(strict2_template_name(p), safe: true)
|
@template_name_expr = parse_expression(template_name(p), safe: true)
|
||||||
with_or_for = p.id?("for") || p.id?("with")
|
with_or_for = p.id?("for") || p.id?("with")
|
||||||
@variable_name_expr = safe_parse_expression(p) if with_or_for
|
@variable_name_expr = safe_parse_expression(p) if with_or_for
|
||||||
@alias_name = p.consume(:id) if p.id?("as")
|
@alias_name = p.consume(:id) if p.id?("as")
|
||||||
@@ -106,7 +106,7 @@ module Liquid
|
|||||||
p.consume(:end_of_string)
|
p.consume(:end_of_string)
|
||||||
end
|
end
|
||||||
|
|
||||||
def strict2_template_name(p)
|
def template_name(p)
|
||||||
p.consume(:string)
|
p.consume(:string)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ module Liquid
|
|||||||
parse_with_selected_parser(markup)
|
parse_with_selected_parser(markup)
|
||||||
end
|
end
|
||||||
|
|
||||||
def strict2_parse(markup)
|
def parse_markup(markup)
|
||||||
p = @parse_context.new_parser(markup)
|
p = @parse_context.new_parser(markup)
|
||||||
|
|
||||||
@variable_name = p.consume(:id)
|
@variable_name = p.consume(:id)
|
||||||
|
|||||||
@@ -41,14 +41,14 @@ module Liquid
|
|||||||
"in \"{{#{markup}}}\""
|
"in \"{{#{markup}}}\""
|
||||||
end
|
end
|
||||||
|
|
||||||
def strict2_parse(markup)
|
def parse_markup(markup)
|
||||||
@filters = []
|
@filters = []
|
||||||
p = @parse_context.new_parser(markup)
|
p = @parse_context.new_parser(markup)
|
||||||
|
|
||||||
return if p.look(:end_of_string)
|
return if p.look(:end_of_string)
|
||||||
|
|
||||||
@name = parse_context.safe_parse_expression(p)
|
@name = parse_context.safe_parse_expression(p)
|
||||||
@filters << strict2_parse_filter_expressions(p) while p.consume?(:pipe)
|
@filters << parse_filter_expressions(p) while p.consume?(:pipe)
|
||||||
p.consume(:end_of_string)
|
p.consume(:end_of_string)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -99,7 +99,7 @@ module Liquid
|
|||||||
# argument = (positional_argument | keyword_argument)
|
# argument = (positional_argument | keyword_argument)
|
||||||
# positional_argument = expression
|
# positional_argument = expression
|
||||||
# keyword_argument = id ":" expression
|
# keyword_argument = id ":" expression
|
||||||
def strict2_parse_filter_expressions(p)
|
def parse_filter_expressions(p)
|
||||||
filtername = p.consume(:id)
|
filtername = p.consume(:id)
|
||||||
filter_args = []
|
filter_args = []
|
||||||
keyword_args = {}
|
keyword_args = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user