class Lexer extends Core (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.

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 string[] $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

void
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)

No description

void
setDelimiter(string $delimiter)

Sets the delimiter.

void
lex()

Parses the string and extracts lexemes.

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

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

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

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

No description

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

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

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