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*/
|
||||
|
||||
class << self
|
||||
def tokenize(input, ss = StringScanner.new(input))
|
||||
ss.string = input
|
||||
def tokenize(ss)
|
||||
output = []
|
||||
|
||||
until ss.eos?
|
||||
@@ -158,8 +157,7 @@ module Liquid
|
||||
|
||||
# rubocop:disable Metrics/BlockNesting
|
||||
class << self
|
||||
def tokenize(input, ss)
|
||||
ss.string = input
|
||||
def tokenize(ss)
|
||||
output = []
|
||||
|
||||
until ss.eos?
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
module Liquid
|
||||
class ParseContext
|
||||
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)
|
||||
@environment = options.fetch(:environment, Environment.default)
|
||||
@@ -44,7 +44,7 @@ module Liquid
|
||||
end
|
||||
|
||||
def parse_expression(markup)
|
||||
Expression.parse(markup, string_scanner, expression_cache)
|
||||
Expression.parse(markup, @string_scanner, @expression_cache)
|
||||
end
|
||||
|
||||
def partial=(value)
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
module Liquid
|
||||
class Parser
|
||||
def initialize(input)
|
||||
input = input.is_a?(StringScanner) ? input : StringScanner.new(input.to_s)
|
||||
@tokens = Lexer.tokenize(input, string_scanner)
|
||||
ss = input.is_a?(StringScanner) ? input : StringScanner.new(input)
|
||||
@tokens = Lexer.tokenize(ss)
|
||||
@p = 0 # pointer to current location
|
||||
end
|
||||
|
||||
|
||||
@@ -134,6 +134,6 @@ class LexerUnitTest < Minitest::Test
|
||||
private
|
||||
|
||||
def tokenize(input)
|
||||
Lexer.tokenize(input, StringScanner.new(""))
|
||||
Lexer.tokenize(StringScanner.new(input))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -85,6 +85,6 @@ class ParserUnitTest < Minitest::Test
|
||||
private
|
||||
|
||||
def new_parser(str)
|
||||
Parser.new(str, StringScanner.new(""))
|
||||
Parser.new(StringScanner.new(str))
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user