Remove parser switching duplication

This commit is contained in:
Tristan Hume
2014-09-05 14:12:29 +00:00
committed by Florian Weingarten
parent 5eff375094
commit 3a0ee6ae91
4 changed files with 38 additions and 39 deletions
+6 -15
View File
@@ -15,30 +15,24 @@ module Liquid
EasyParse = /\A *(\w+(?:\.\w+)*) *\z/
attr_accessor :filters, :name, :warnings
attr_accessor :line_number
include ParserSwitching
def initialize(markup, options = {})
@markup = markup
@name = nil
@options = options || {}
case @options[:error_mode] || Template.error_mode
when :strict then strict_parse(markup)
when :lax then lax_parse(markup)
when :warn
begin
strict_parse(markup)
rescue SyntaxError => e
@warnings ||= []
@warnings << e
lax_parse(markup)
end
end
parse_with_selected_parser(markup)
end
def raw
@markup
end
def markup_context(markup)
" in \"{{#{markup}}}\""
end
def lax_parse(markup)
@filters = []
if markup =~ /\s*(#{QuotedFragment})(.*)/om
@@ -74,9 +68,6 @@ module Liquid
@filters << [filtername, filterargs]
end
p.consume(:end_of_string)
rescue SyntaxError => e
e.message << " in \"{{#{markup}}}\""
raise e
end
def parse_filterargs(p)