class Lexer extends Core

Performs lexical analysis over a SQL statement and splits it in multiple tokens.

The output of the lexer is affected by the context of the SQL statement.

Properties

bool $strict Whether errors should throw exceptions or just be stored. from Core
Exception[] $errors List of errors that occurred during lexing. from Core
static array $PARSER_METHODS A list of methods that are used in lexing the SQL query.
string|UtfString $str The string to be parsed.
int $len The length of $str.
int $last The index of the last parsed character.
TokensList $list Tokens extracted from given strings.
static string $DEFAULT_DELIMITER The default delimiter. This is used, by default, in all new instances.
string $delimiter Statements delimiter.
int $delimiterLen The length of the delimiter.

Methods

error(string $msg, string $str = '', int $pos = 0, int $code = 0)

Creates a new error log.

static TokensList
getTokens(string|UtfString $str, bool $strict = false, string $delimiter = null)

Gets the tokens list parsed by a new instance of a lexer.

__construct(string|UtfString $str, bool $strict = false, string $delimiter = null)

Constructor.

setDelimiter(string $delimiter)

Sets the delimiter.

lex()

Parses the string and extracts lexemes.

null|Token
parseKeyword()

Parses a keyword.

null|Token
parseLabel()

Parses a label.

null|Token
parseOperator()

Parses an operator.

null|Token
parseWhitespace()

Parses a whitespace.

null|Token
parseComment()

Parses a comment.

null|Token
parseBool()

Parses a boolean.

null|Token
parseNumber()

Parses a number.

null|Token
parseString(string $quote = '')

Parses a string.

null|Token
parseSymbol()

Parses a symbol.

null|Token
parseUnknown()

Parses unknown parts of the query.

null|Token
parseDelimiter()

Parses the delimiter of the query.

Details

at line 350
error(string $msg, string $str = '', int $pos = 0, int $code = 0)

Creates a new error log.

Parameters

string $msg the error message
string $str the character that produced the error
int $pos the position of the character
int $code the code of the error

Exceptions

LexerException throws the exception, if strict mode is enabled

at line 145
static TokensList getTokens(string|UtfString $str, bool $strict = false, string $delimiter = null)

Gets the tokens list parsed by a new instance of a lexer.

Parameters

string|UtfString $str the query to be lexed
bool $strict whether strict mode should be enabled or not
string $delimiter the delimiter to be used

Return Value

TokensList

at line 160
__construct(string|UtfString $str, bool $strict = false, string $delimiter = null)

Constructor.

Parameters

string|UtfString $str the query to be lexed
bool $strict whether strict mode should be enabled or not
string $delimiter the delimiter to be used

at line 190
setDelimiter(string $delimiter)

Sets the delimiter.

Parameters

string $delimiter the new delimiter

at line 199
lex()

Parses the string and extracts lexemes.

at line 364
null|Token parseKeyword()

Parses a keyword.

Return Value

null|Token

at line 425
null|Token parseLabel()

Parses a label.

Return Value

null|Token

at line 470
null|Token parseOperator()

Parses an operator.

Return Value

null|Token

at line 506
null|Token parseWhitespace()

Parses a whitespace.

Return Value

null|Token

at line 528
null|Token parseComment()

Parses a comment.

Return Value

null|Token

at line 638
null|Token parseBool()

Parses a boolean.

Return Value

null|Token

at line 669
null|Token parseNumber()

Parses a number.

Return Value

null|Token

at line 816
null|Token parseString(string $quote = '')

Parses a string.

Parameters

string $quote additional starting symbol

Return Value

null|Token

at line 861
null|Token parseSymbol()

Parses a symbol.

Return Value

null|Token

at line 908
null|Token parseUnknown()

Parses unknown parts of the query.

Return Value

null|Token

at line 928
null|Token parseDelimiter()

Parses the delimiter of the query.

Return Value

null|Token