Class: JSONP3::Lexer
- Inherits:
-
Object
- Object
- JSONP3::Lexer
- Defined in:
- lib/json_p3/lexer.rb
Overview
JSONPath query expression lexical scanner.
Constant Summary collapse
- RE_INT =
/-?[0-9]+/
- RE_NAME =
/[\u0080-\uFFFFa-zA-Z_][\u0080-\uFFFFa-zA-Z0-9_-]*/
- RE_WHITESPACE =
/[ \n\r\t]+/
- S_ESCAPES =
Set["b", "f", "n", "r", "t", "u", "/", "\\"].freeze
Instance Attribute Summary collapse
-
#bracket_stack ⇒ Object
readonly
Returns the value of attribute bracket_stack.
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(query) ⇒ Lexer
constructor
A new instance of Lexer.
- #run ⇒ Object
Constructor Details
#initialize(query) ⇒ Lexer
Returns a new instance of Lexer.
44 45 46 47 48 49 50 51 52 |
# File 'lib/json_p3/lexer.rb', line 44 def initialize(query) @filter_depth = 0 @func_call_stack = [] @bracket_stack = [] @tokens = [] @start = 0 @query = query.freeze @scanner = StringScanner.new(query) end |
Instance Attribute Details
#bracket_stack ⇒ Object (readonly)
Returns the value of attribute bracket_stack.
42 43 44 |
# File 'lib/json_p3/lexer.rb', line 42 def bracket_stack @bracket_stack end |
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens.
42 43 44 |
# File 'lib/json_p3/lexer.rb', line 42 def tokens @tokens end |
Class Method Details
.lex_string_factory(quote, state, token) ⇒ Object
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 |
# File 'lib/json_p3/lexer.rb', line 396 def lex_string_factory(quote, state, token) proc { # @type self: Lexer ignore # move past opening quote loop do c = self.next case c when "" error "unclosed string starting at index #{@start}" return nil when "\\" peeked = peek if S_ESCAPES.member?(peeked) || peeked == quote self.next else error "invalid escape" return nil end when quote backup emit(token) self.next ignore # move past closing quote return state end end } end |
Instance Method Details
#run ⇒ Object
54 55 56 57 |
# File 'lib/json_p3/lexer.rb', line 54 def run state = :lex_root state = send(state) until state.nil? end |