Documentation

Lexer
in package

Tokenizes JMESPath expressions

Table of Contents

STATE_AND  = 13
STATE_EQ  = 11
STATE_GT  = 10
STATE_IDENTIFIER  = 0
STATE_JSON_LITERAL  = 6
STATE_LBRACKET  = 7
STATE_LT  = 9
STATE_NOT  = 12
STATE_NUMBER  = 1
STATE_PIPE  = 8
STATE_QUOTED_STRING  = 5
STATE_SINGLE_CHAR  = 2
STATE_STRING_LITERAL  = 4
STATE_WHITESPACE  = 3
T_AND  = 'and'
T_COLON  = 'colon'
T_COMMA  = 'comma'
T_COMPARATOR  = 'comparator'
T_CURRENT  = 'current'
T_DOT  = 'dot'
T_EOF  = 'eof'
T_EXPREF  = 'expref'
T_FILTER  = 'filter'
T_FLATTEN  = 'flatten'
T_IDENTIFIER  = 'identifier'
T_LBRACE  = 'lbrace'
T_LBRACKET  = 'lbracket'
T_LITERAL  = 'literal'
T_LPAREN  = 'lparen'
T_NOT  = 'not'
T_NUMBER  = 'number'
T_OR  = 'or'
T_PIPE  = 'pipe'
T_QUOTED_IDENTIFIER  = 'quoted_identifier'
T_RBRACE  = 'rbrace'
T_RBRACKET  = 'rbracket'
T_RPAREN  = 'rparen'
T_STAR  = 'star'
T_UNKNOWN  = 'unknown'
$numbers  : array<string|int, mixed>
$simpleTokens  : array<string|int, mixed>
$transitionTable  : array<string|int, mixed>
$validIdentifier  : array<string|int, mixed>
tokenize()  : array<string|int, mixed>
Tokenize the JMESPath expression into an array of tokens hashes that contain a 'type', 'value', and 'key'.
inside()  : array<string|int, mixed>
Returns a token the is the result of consuming inside of delimiter characters. Escaped delimiters will be adjusted before returning a value. If the token is not closed, "unknown" is returned.
matchOr()  : array<string|int, mixed>
Returns a token based on whether or not the next token matches the expected value. If it does, a token of "$type" is returned. Otherwise, a token of "$orElse" type is returned.
parseJson()  : array<string|int, mixed>
Parses a JSON token or sets the token type to "unknown" on error.

Constants

STATE_AND

public mixed STATE_AND = 13

STATE_EQ

public mixed STATE_EQ = 11

STATE_GT

public mixed STATE_GT = 10

STATE_IDENTIFIER

public mixed STATE_IDENTIFIER = 0

STATE_JSON_LITERAL

public mixed STATE_JSON_LITERAL = 6

STATE_LBRACKET

public mixed STATE_LBRACKET = 7

STATE_LT

public mixed STATE_LT = 9

STATE_NOT

public mixed STATE_NOT = 12

STATE_NUMBER

public mixed STATE_NUMBER = 1

STATE_PIPE

public mixed STATE_PIPE = 8

STATE_QUOTED_STRING

public mixed STATE_QUOTED_STRING = 5

STATE_SINGLE_CHAR

public mixed STATE_SINGLE_CHAR = 2

STATE_STRING_LITERAL

public mixed STATE_STRING_LITERAL = 4

STATE_WHITESPACE

public mixed STATE_WHITESPACE = 3

T_AND

public mixed T_AND = 'and'

T_COLON

public mixed T_COLON = 'colon'

T_COMMA

public mixed T_COMMA = 'comma'

T_COMPARATOR

public mixed T_COMPARATOR = 'comparator'

T_CURRENT

public mixed T_CURRENT = 'current'

T_DOT

public mixed T_DOT = 'dot'

T_EOF

public mixed T_EOF = 'eof'

T_EXPREF

public mixed T_EXPREF = 'expref'

T_FILTER

public mixed T_FILTER = 'filter'

T_FLATTEN

public mixed T_FLATTEN = 'flatten'

T_IDENTIFIER

public mixed T_IDENTIFIER = 'identifier'

T_LBRACE

public mixed T_LBRACE = 'lbrace'

T_LBRACKET

public mixed T_LBRACKET = 'lbracket'

T_LITERAL

public mixed T_LITERAL = 'literal'

T_LPAREN

public mixed T_LPAREN = 'lparen'

T_NOT

public mixed T_NOT = 'not'

T_NUMBER

public mixed T_NUMBER = 'number'

T_OR

public mixed T_OR = 'or'

T_PIPE

public mixed T_PIPE = 'pipe'

T_QUOTED_IDENTIFIER

public mixed T_QUOTED_IDENTIFIER = 'quoted_identifier'

T_RBRACE

public mixed T_RBRACE = 'rbrace'

T_RBRACKET

public mixed T_RBRACKET = 'rbracket'

T_RPAREN

public mixed T_RPAREN = 'rparen'

T_STAR

public mixed T_STAR = 'star'

T_UNKNOWN

public mixed T_UNKNOWN = 'unknown'

Properties

$numbers

private array<string|int, mixed> $numbers = ['0' => true, '1' => true, '2' => true, '3' => true, '4' => true, '5' => true, '6' => true, '7' => true, '8' => true, '9' => true]

Valid number characters after the first character

$simpleTokens

private array<string|int, mixed> $simpleTokens = ['.' => self::T_DOT, '*' => self::T_STAR, ']' => self::T_RBRACKET, ',' => self::T_COMMA, ':' => self::T_COLON, '@' => self::T_CURRENT, '(' => self::T_LPAREN, ')' => self::T_RPAREN, '{' => self::T_LBRACE, '}' => self::T_RBRACE]

Map of simple single character tokens

$transitionTable

private static array<string|int, mixed> $transitionTable = ['<' => self::STATE_LT, '>' => self::STATE_GT, '=' => self::STATE_EQ, '!' => self::STATE_NOT, '[' => self::STATE_LBRACKET, '|' => self::STATE_PIPE, '&' => self::STATE_AND, '`' => self::STATE_JSON_LITERAL, '"' => self::STATE_QUOTED_STRING, "'" => self::STATE_STRING_LITERAL, '-' => self::STATE_NUMBER, '0' => self::STATE_NUMBER, '1' => self::STATE_NUMBER, '2' => self::STATE_NUMBER, '3' => self::STATE_NUMBER, '4' => self::STATE_NUMBER, '5' => self::STATE_NUMBER, '6' => self::STATE_NUMBER, '7' => self::STATE_NUMBER, '8' => self::STATE_NUMBER, '9' => self::STATE_NUMBER, ' ' => self::STATE_WHITESPACE, " " => self::STATE_WHITESPACE, " " => self::STATE_WHITESPACE, " " => self::STATE_WHITESPACE, '.' => self::STATE_SINGLE_CHAR, '*' => self::STATE_SINGLE_CHAR, ']' => self::STATE_SINGLE_CHAR, ',' => self::STATE_SINGLE_CHAR, ':' => self::STATE_SINGLE_CHAR, '@' => self::STATE_SINGLE_CHAR, '(' => self::STATE_SINGLE_CHAR, ')' => self::STATE_SINGLE_CHAR, '{' => self::STATE_SINGLE_CHAR, '}' => self::STATE_SINGLE_CHAR, '_' => self::STATE_IDENTIFIER, 'A' => self::STATE_IDENTIFIER, 'B' => self::STATE_IDENTIFIER, 'C' => self::STATE_IDENTIFIER, 'D' => self::STATE_IDENTIFIER, 'E' => self::STATE_IDENTIFIER, 'F' => self::STATE_IDENTIFIER, 'G' => self::STATE_IDENTIFIER, 'H' => self::STATE_IDENTIFIER, 'I' => self::STATE_IDENTIFIER, 'J' => self::STATE_IDENTIFIER, 'K' => self::STATE_IDENTIFIER, 'L' => self::STATE_IDENTIFIER, 'M' => self::STATE_IDENTIFIER, 'N' => self::STATE_IDENTIFIER, 'O' => self::STATE_IDENTIFIER, 'P' => self::STATE_IDENTIFIER, 'Q' => self::STATE_IDENTIFIER, 'R' => self::STATE_IDENTIFIER, 'S' => self::STATE_IDENTIFIER, 'T' => self::STATE_IDENTIFIER, 'U' => self::STATE_IDENTIFIER, 'V' => self::STATE_IDENTIFIER, 'W' => self::STATE_IDENTIFIER, 'X' => self::STATE_IDENTIFIER, 'Y' => self::STATE_IDENTIFIER, 'Z' => self::STATE_IDENTIFIER, 'a' => self::STATE_IDENTIFIER, 'b' => self::STATE_IDENTIFIER, 'c' => self::STATE_IDENTIFIER, 'd' => self::STATE_IDENTIFIER, 'e' => self::STATE_IDENTIFIER, 'f' => self::STATE_IDENTIFIER, 'g' => self::STATE_IDENTIFIER, 'h' => self::STATE_IDENTIFIER, 'i' => self::STATE_IDENTIFIER, 'j' => self::STATE_IDENTIFIER, 'k' => self::STATE_IDENTIFIER, 'l' => self::STATE_IDENTIFIER, 'm' => self::STATE_IDENTIFIER, 'n' => self::STATE_IDENTIFIER, 'o' => self::STATE_IDENTIFIER, 'p' => self::STATE_IDENTIFIER, 'q' => self::STATE_IDENTIFIER, 'r' => self::STATE_IDENTIFIER, 's' => self::STATE_IDENTIFIER, 't' => self::STATE_IDENTIFIER, 'u' => self::STATE_IDENTIFIER, 'v' => self::STATE_IDENTIFIER, 'w' => self::STATE_IDENTIFIER, 'x' => self::STATE_IDENTIFIER, 'y' => self::STATE_IDENTIFIER, 'z' => self::STATE_IDENTIFIER]

We know what token we are consuming based on each char

$validIdentifier

private array<string|int, mixed> $validIdentifier = ['A' => true, 'B' => true, 'C' => true, 'D' => true, 'E' => true, 'F' => true, 'G' => true, 'H' => true, 'I' => true, 'J' => true, 'K' => true, 'L' => true, 'M' => true, 'N' => true, 'O' => true, 'P' => true, 'Q' => true, 'R' => true, 'S' => true, 'T' => true, 'U' => true, 'V' => true, 'W' => true, 'X' => true, 'Y' => true, 'Z' => true, 'a' => true, 'b' => true, 'c' => true, 'd' => true, 'e' => true, 'f' => true, 'g' => true, 'h' => true, 'i' => true, 'j' => true, 'k' => true, 'l' => true, 'm' => true, 'n' => true, 'o' => true, 'p' => true, 'q' => true, 'r' => true, 's' => true, 't' => true, 'u' => true, 'v' => true, 'w' => true, 'x' => true, 'y' => true, 'z' => true, '_' => true, '0' => true, '1' => true, '2' => true, '3' => true, '4' => true, '5' => true, '6' => true, '7' => true, '8' => true, '9' => true]

Valid identifier characters after first character

Methods

tokenize()

Tokenize the JMESPath expression into an array of tokens hashes that contain a 'type', 'value', and 'key'.

public tokenize(string $input) : array<string|int, mixed>
Parameters
$input : string

JMESPath input

Tags
throws
SyntaxErrorException
Return values
array<string|int, mixed>

inside()

Returns a token the is the result of consuming inside of delimiter characters. Escaped delimiters will be adjusted before returning a value. If the token is not closed, "unknown" is returned.

private inside(array<string|int, mixed> &$chars, string $delim, string $type) : array<string|int, mixed>
Parameters
$chars : array<string|int, mixed>

Array of characters by reference.

$delim : string

The delimiter character.

$type : string

Token type.

Return values
array<string|int, mixed>

Returns the consumed token.

matchOr()

Returns a token based on whether or not the next token matches the expected value. If it does, a token of "$type" is returned. Otherwise, a token of "$orElse" type is returned.

private matchOr(array<string|int, mixed> &$chars, string $current, string $expected, string $type, string $orElse) : array<string|int, mixed>
Parameters
$chars : array<string|int, mixed>

Array of characters by reference.

$current : string

The current character.

$expected : string

Expected character.

$type : string

Expected result type.

$orElse : string

Otherwise return a token of this type.

Return values
array<string|int, mixed>

Returns a conditional token.

parseJson()

Parses a JSON token or sets the token type to "unknown" on error.

private parseJson(array<string|int, mixed> $token) : array<string|int, mixed>
Parameters
$token : array<string|int, mixed>

Token that needs parsing.

Return values
array<string|int, mixed>

Returns a token with a parsed value.

Search results