class Lexer (View source)

Defines the lexer of the library.

This is one of the most important components, along with the parser.

Depends on context to extract lexemes.

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.

Constants

private KEYWORD_NAME_INDICATORS

A list of keywords that indicate that the function keyword is not used as a function

private OPERATOR_NAME_INDICATORS

A list of operators that indicate that the function keyword is not used as a function

Properties

Exception[] $errors

List of errors that occurred during lexing.

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 $defaultDelimiter

The default delimiter. This is used, by default, in all new instances.

string $delimiter

Statements delimiter.

int $delimiterLen

The length of the delimiter.

Methods

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

No description

void
setDelimiter(string $delimiter)

Sets the delimiter.

void
lex()

Parses the string and extracts lexemes.

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

Creates a new error log.

Token|null
parseKeyword()

Parses a keyword.

Token|null
parseLabel()

Parses a label.

Token|null
parseOperator()

Parses an operator.

Token|null
parseWhitespace()

Parses a whitespace.

Token|null
parseComment()

Parses a comment.

Token|null
parseBool()

Parses a boolean.

Token|null
parseNumber()

Parses a number.

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

Parses a string.

Token|null
parseSymbol()

Parses a symbol.

Token|null
parseUnknown()

Parses unknown parts of the query.

Token|null
parseDelimiter()

Parses the delimiter of the query.

Details

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

No description

Parameters

UtfString $str

the query to be lexed

bool $strict

whether strict mode should be enabled or not

string|null $delimiter

the delimiter to be used

void setDelimiter(string $delimiter)

Sets the delimiter.

Parameters

string $delimiter

the new delimiter

Return Value

void

void lex()

Parses the string and extracts lexemes.

Return Value

void

void 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

Return Value

void

Exceptions

LexerException

Token|null parseKeyword()

Parses a keyword.

Return Value

Token|null

Token|null parseLabel()

Parses a label.

Return Value

Token|null

Token|null parseOperator()

Parses an operator.

Return Value

Token|null

Token|null parseWhitespace()

Parses a whitespace.

Return Value

Token|null

Token|null parseComment()

Parses a comment.

Return Value

Token|null

Token|null parseBool()

Parses a boolean.

Return Value

Token|null

Token|null parseNumber()

Parses a number.

Return Value

Token|null

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

Parses a string.

Parameters

string $quote

additional starting symbol

Return Value

Token|null

Exceptions

LexerException

Token|null parseSymbol()

Parses a symbol.

Return Value

Token|null

Exceptions

LexerException

Token|null parseUnknown()

Parses unknown parts of the query.

Return Value

Token|null

Token|null parseDelimiter()

Parses the delimiter of the query.

Return Value

Token|null