diff options
| author | Benjamin Sanders <ben@Benjamins-MacBook-Pro.local> | 2025-10-11 10:34:24 -0400 |
|---|---|---|
| committer | Benjamin Sanders <ben@Benjamins-MacBook-Pro.local> | 2025-10-11 10:34:24 -0400 |
| commit | 5571dc766e2143e39762ff0b47c41d1c2e154f4c (patch) | |
| tree | f4f124d314a7e76c04484515aa0fd1f2e271a601 /vendor/bundle/ruby/3.4.0/gems/liquid-4.0.4/lib/liquid/lexer.rb | |
| parent | 359f3309c97fc894b63e0a295c76ab298504d635 (diff) | |
Vendor bundled gems for deployment
Diffstat (limited to 'vendor/bundle/ruby/3.4.0/gems/liquid-4.0.4/lib/liquid/lexer.rb')
| -rw-r--r-- | vendor/bundle/ruby/3.4.0/gems/liquid-4.0.4/lib/liquid/lexer.rb | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/vendor/bundle/ruby/3.4.0/gems/liquid-4.0.4/lib/liquid/lexer.rb b/vendor/bundle/ruby/3.4.0/gems/liquid-4.0.4/lib/liquid/lexer.rb new file mode 100644 index 0000000..f290744 --- /dev/null +++ b/vendor/bundle/ruby/3.4.0/gems/liquid-4.0.4/lib/liquid/lexer.rb @@ -0,0 +1,55 @@ +require "strscan" +module Liquid + class Lexer + SPECIALS = { + '|'.freeze => :pipe, + '.'.freeze => :dot, + ':'.freeze => :colon, + ','.freeze => :comma, + '['.freeze => :open_square, + ']'.freeze => :close_square, + '('.freeze => :open_round, + ')'.freeze => :close_round, + '?'.freeze => :question, + '-'.freeze => :dash + }.freeze + IDENTIFIER = /[a-zA-Z_][\w-]*\??/ + SINGLE_STRING_LITERAL = /'[^\']*'/ + DOUBLE_STRING_LITERAL = /"[^\"]*"/ + NUMBER_LITERAL = /-?\d+(\.\d+)?/ + DOTDOT = /\.\./ + COMPARISON_OPERATOR = /==|!=|<>|<=?|>=?|contains(?=\s)/ + WHITESPACE_OR_NOTHING = /\s*/ + + def initialize(input) + @ss = StringScanner.new(input) + end + + def tokenize + @output = [] + + until @ss.eos? + @ss.skip(WHITESPACE_OR_NOTHING) + break if @ss.eos? + tok = case + when t = @ss.scan(COMPARISON_OPERATOR) then [:comparison, t] + when t = @ss.scan(SINGLE_STRING_LITERAL) then [:string, t] + when t = @ss.scan(DOUBLE_STRING_LITERAL) then [:string, t] + when t = @ss.scan(NUMBER_LITERAL) then [:number, t] + when t = @ss.scan(IDENTIFIER) then [:id, t] + when t = @ss.scan(DOTDOT) then [:dotdot, t] + else + c = @ss.getch + if s = SPECIALS[c] + [s, c] + else + raise SyntaxError, "Unexpected character #{c}" + end + end + @output << tok + end + + @output << [:end_of_string] + end + end +end |
