mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-19 02:40:41 -07:00
Add rigid_parse_with_error_context and clarifications
This commit is contained in:
committed by
Guilherme Carreiro
parent
edf06c2882
commit
6d585a24f1
@@ -2,14 +2,17 @@
|
|||||||
|
|
||||||
module Liquid
|
module Liquid
|
||||||
module ParserSwitching
|
module ParserSwitching
|
||||||
|
# Do not use this. Use parse_with_selected_parser instead.
|
||||||
|
# It's basically doing the same thing, except this will use strict_parse regardless
|
||||||
|
# of the error mode and fallback only if strict throws.
|
||||||
def strict_parse_with_error_mode_fallback(markup)
|
def strict_parse_with_error_mode_fallback(markup)
|
||||||
strict_parse_with_error_context(markup)
|
strict_parse_with_error_context(markup)
|
||||||
rescue SyntaxError => e
|
rescue SyntaxError => e
|
||||||
case parse_context.error_mode
|
case parse_context.error_mode
|
||||||
when :strict
|
|
||||||
raise
|
|
||||||
when :rigid
|
when :rigid
|
||||||
raise
|
raise
|
||||||
|
when :strict
|
||||||
|
raise
|
||||||
when :warn
|
when :warn
|
||||||
parse_context.warnings << e
|
parse_context.warnings << e
|
||||||
end
|
end
|
||||||
@@ -18,8 +21,8 @@ module Liquid
|
|||||||
|
|
||||||
def parse_with_selected_parser(markup)
|
def parse_with_selected_parser(markup)
|
||||||
case parse_context.error_mode
|
case parse_context.error_mode
|
||||||
|
when :rigid then rigid_parse_with_error_context(markup)
|
||||||
when :strict then strict_parse_with_error_context(markup)
|
when :strict then strict_parse_with_error_context(markup)
|
||||||
when :rigid then strict_parse_with_error_context(markup)
|
|
||||||
when :lax then lax_parse(markup)
|
when :lax then lax_parse(markup)
|
||||||
when :warn
|
when :warn
|
||||||
begin
|
begin
|
||||||
@@ -33,6 +36,14 @@ module Liquid
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def rigid_parse_with_error_context(markup)
|
||||||
|
respond_to?(:rigid_parse) ? rigid_parse(markup) : strict_parse(markup)
|
||||||
|
rescue SyntaxError => e
|
||||||
|
e.line_number = line_number
|
||||||
|
e.markup_context = markup_context(markup)
|
||||||
|
raise e
|
||||||
|
end
|
||||||
|
|
||||||
def strict_parse_with_error_context(markup)
|
def strict_parse_with_error_context(markup)
|
||||||
strict_parse(markup)
|
strict_parse(markup)
|
||||||
rescue SyntaxError => e
|
rescue SyntaxError => e
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ module Liquid
|
|||||||
# :lax acts like liquid 2.5 and silently ignores malformed tags in most cases.
|
# :lax acts like liquid 2.5 and silently ignores malformed tags in most cases.
|
||||||
# :warn is the default and will give deprecation warnings when invalid syntax is used.
|
# :warn is the default and will give deprecation warnings when invalid syntax is used.
|
||||||
# :strict will enforce correct syntax.
|
# :strict will enforce correct syntax.
|
||||||
|
# :rigid is stricter even.
|
||||||
def error_mode=(mode)
|
def error_mode=(mode)
|
||||||
Deprecations.warn("Template.error_mode=", "Environment#error_mode=")
|
Deprecations.warn("Template.error_mode=", "Environment#error_mode=")
|
||||||
Environment.default.error_mode = mode
|
Environment.default.error_mode = mode
|
||||||
|
|||||||
Reference in New Issue
Block a user