Module: Liquidscript::Scanner::Base::Lexer
- Included in:
- Liquidscript::Scanner::Base
- Defined in:
- lib/liquidscript/scanner/base/lexer.rb
Instance Method Summary collapse
- #error(scanner = @scanner, context = @context, file = ) ⇒ Object
- #lex(*args) ⇒ Object
- #perform_with_context(context, scanner = @scanner) ⇒ Object
Instance Method Details
#error(scanner = @scanner, context = @context, file = ) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/liquidscript/scanner/base/lexer.rb', line 43 def error(scanner = @scanner, context = @context, file = @metadata[:file]) raise SyntaxError, "Unexpected " + "#{scanner.matched}#{scanner.peek(2)}".inspect + " (line: #{line}, column: #{column}, file: #{file})" end |
#lex(*args) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/liquidscript/scanner/base/lexer.rb', line 16 def lex(*args) args.flatten! to_lex = args.pop context, body = if to_lex.is_a? Hash to_lex.to_a.first else [to_lex, nil] end scanner = if body StringScanner.new(body) else @scanner end out = [] context = find_context(context) instance_exec(*args, &context.init) while scanner.rest? && out.last != EXIT out << perform_with_context(context, scanner) end out end |
#perform_with_context(context, scanner = @scanner) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/liquidscript/scanner/base/lexer.rb', line 6 def perform_with_context(context, scanner = @scanner) key, value = context.find_matcher(scanner) if value.nil? && scanner.rest? error scanner, context end normalize_action key, value, scanner if scanner.rest? end |