mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
refactor Lexer to only take StringScanner
This commit is contained in:
+2
-4
@@ -26,8 +26,7 @@ module Liquid
|
|||||||
WHITESPACE_OR_NOTHING = /\s*/
|
WHITESPACE_OR_NOTHING = /\s*/
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def tokenize(input, ss = StringScanner.new(input))
|
def tokenize(ss)
|
||||||
ss.string = input
|
|
||||||
output = []
|
output = []
|
||||||
|
|
||||||
until ss.eos?
|
until ss.eos?
|
||||||
@@ -158,8 +157,7 @@ module Liquid
|
|||||||
|
|
||||||
# rubocop:disable Metrics/BlockNesting
|
# rubocop:disable Metrics/BlockNesting
|
||||||
class << self
|
class << self
|
||||||
def tokenize(input, ss)
|
def tokenize(ss)
|
||||||
ss.string = input
|
|
||||||
output = []
|
output = []
|
||||||
|
|
||||||
until ss.eos?
|
until ss.eos?
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
module Liquid
|
module Liquid
|
||||||
class ParseContext
|
class ParseContext
|
||||||
attr_accessor :locale, :line_number, :trim_whitespace, :depth
|
attr_accessor :locale, :line_number, :trim_whitespace, :depth
|
||||||
attr_reader :partial, :warnings, :error_mode, :environment, :string_scanner, :expression_cache
|
attr_reader :partial, :warnings, :error_mode, :environment
|
||||||
|
|
||||||
def initialize(options = Const::EMPTY_HASH)
|
def initialize(options = Const::EMPTY_HASH)
|
||||||
@environment = options.fetch(:environment, Environment.default)
|
@environment = options.fetch(:environment, Environment.default)
|
||||||
@@ -44,7 +44,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def parse_expression(markup)
|
def parse_expression(markup)
|
||||||
Expression.parse(markup, string_scanner, expression_cache)
|
Expression.parse(markup, @string_scanner, @expression_cache)
|
||||||
end
|
end
|
||||||
|
|
||||||
def partial=(value)
|
def partial=(value)
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
module Liquid
|
module Liquid
|
||||||
class Parser
|
class Parser
|
||||||
def initialize(input)
|
def initialize(input)
|
||||||
input = input.is_a?(StringScanner) ? input : StringScanner.new(input.to_s)
|
ss = input.is_a?(StringScanner) ? input : StringScanner.new(input)
|
||||||
@tokens = Lexer.tokenize(input, string_scanner)
|
@tokens = Lexer.tokenize(ss)
|
||||||
@p = 0 # pointer to current location
|
@p = 0 # pointer to current location
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -134,6 +134,6 @@ class LexerUnitTest < Minitest::Test
|
|||||||
private
|
private
|
||||||
|
|
||||||
def tokenize(input)
|
def tokenize(input)
|
||||||
Lexer.tokenize(input, StringScanner.new(""))
|
Lexer.tokenize(StringScanner.new(input))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -85,6 +85,6 @@ class ParserUnitTest < Minitest::Test
|
|||||||
private
|
private
|
||||||
|
|
||||||
def new_parser(str)
|
def new_parser(str)
|
||||||
Parser.new(str, StringScanner.new(""))
|
Parser.new(StringScanner.new(str))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user