Class: JMESPath::Lexer Private
- Inherits:
-
Object
- Object
- JMESPath::Lexer
- Defined in:
- lib/jmespath/lexer.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- TOKEN_PATTERNS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{}
- TOKEN_TYPES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{}
- TOKEN_REGEX =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
/(#{TOKEN_PATTERNS.values.join(')|(')})/
- JSON_VALUE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
/^[\["{]/
- JSON_NUMBER =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
/^\-?[0-9]*(\.[0-9]+)?([e|E][+|\-][0-9]+)?$/
Instance Method Summary collapse
Instance Method Details
#tokenize(expression) ⇒ Array<Hash>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/jmespath/lexer.rb', line 57 def tokenize(expression) offset = 0 tokens = [] expression.scan(TOKEN_REGEX).each do |match| match_index = match.find_index { |token| !token.nil? } match_value = match[match_index] type = TOKEN_TYPES[match_index] token = Token.new(type, match_value, offset) if token.type != :skip case token.type when :number then token_number(token, expression, offset) when :literal then token_literal(token, expression, offset) when :quoted_identifier token_quoted_identifier(token, expression, offset) end tokens << token end offset += match_value.size end tokens << Token.new(:eof, nil, offset) unless expression.size == offset syntax_error('invalid expression', expression, offset) end tokens end |