PHP Class SqlParser\Lexer

The output of the lexer is affected by the context of the SQL statement.
See also: Context
显示文件 Open project: phpmyadmin/sql-parser Class Usage Examples

Public Properties

Property Type Description
$DEFAULT_DELIMITER string The default delimiter. This is used, by default, in all new instances.
$PARSER_METHODS array A list of methods that are used in lexing the SQL query.
$delimiter string This may change during lexing.
$delimiterLen integer Because parseDelimiter can be called a lot, it would perform a lot of calls to strlen, which might affect performance when the delimiter is big.
$errors SqlParser\Exceptions\LexerException[] Usually, the lexing does not stop once an error occurred because that error might be false positive or a partial result (even a bad one) might be needed.
$last integer The index of the last parsed character.
$len integer By storing its length, a lot of time is saved, because parsing methods would call strlen everytime.
$list TokensList Tokens extracted from given strings.
$str string | UtfString The string to be parsed.
$strict boolean Whether errors should throw exceptions or just be stored.

Public Methods

Method Description
__construct ( string | UtfString $str, boolean $strict = false, string $delimiter = null ) Constructor.
error ( string $msg = '', string $str = '', integer $pos, integer $code ) : void Creates a new error log.
getTokens ( string | UtfString $str, boolean $strict = false, string $delimiter = null ) : TokensList Gets the tokens list parsed by a new instance of a lexer.
lex ( ) : void Parses the string and extracts lexemes.
parseBool ( ) : Token Parses a boolean.
parseComment ( ) : Token Parses a comment.
parseDelimiter ( ) : Token Parses the delimiter of the query.
parseKeyword ( ) : Token Parses a keyword.
parseLabel ( ) : Token Parses a label.
parseNumber ( ) : Token Parses a number.
parseOperator ( ) : Token Parses an operator.
parseString ( string $quote = '' ) : Token Parses a string.
parseSymbol ( ) : Token Parses a symbol.
parseUnknown ( ) : Token Parses unknown parts of the query.
parseWhitespace ( ) : Token Parses a whitespace.
setDelimiter ( string $delimiter ) Sets the delimiter.

Method Details

__construct() public method

Constructor.
public __construct ( string | UtfString $str, boolean $strict = false, string $delimiter = null )
$str string | UtfString The query to be lexed.
$strict boolean Whether strict mode should be enabled or not.
$delimiter string The delimiter to be used.

error() public method

Creates a new error log.
public error ( string $msg = '', string $str = '', integer $pos, integer $code ) : void
$msg string The error message.
$str string The character that produced the error.
$pos integer The position of the character.
$code integer The code of the error.
return void

getTokens() public static method

Gets the tokens list parsed by a new instance of a lexer.
public static getTokens ( string | UtfString $str, boolean $strict = false, string $delimiter = null ) : TokensList
$str string | UtfString The query to be lexed.
$strict boolean Whether strict mode should be enabled or not.
$delimiter string The delimiter to be used.
return TokensList

lex() public method

Parses the string and extracts lexemes.
public lex ( ) : void
return void

parseBool() public method

Parses a boolean.
public parseBool ( ) : Token
return Token

parseComment() public method

Parses a comment.
public parseComment ( ) : Token
return Token

parseDelimiter() public method

Parses the delimiter of the query.
public parseDelimiter ( ) : Token
return Token

parseKeyword() public method

Parses a keyword.
public parseKeyword ( ) : Token
return Token

parseLabel() public method

Parses a label.
public parseLabel ( ) : Token
return Token

parseNumber() public method

Parses a number.
public parseNumber ( ) : Token
return Token

parseOperator() public method

Parses an operator.
public parseOperator ( ) : Token
return Token

parseString() public method

Parses a string.
public parseString ( string $quote = '' ) : Token
$quote string Additional starting symbol.
return Token

parseSymbol() public method

Parses a symbol.
public parseSymbol ( ) : Token
return Token

parseUnknown() public method

Parses unknown parts of the query.
public parseUnknown ( ) : Token
return Token

parseWhitespace() public method

Parses a whitespace.
public parseWhitespace ( ) : Token
return Token

setDelimiter() public method

Sets the delimiter.
public setDelimiter ( string $delimiter )
$delimiter string The new delimiter.

Property Details

$DEFAULT_DELIMITER public_oe static_oe property

The default delimiter. This is used, by default, in all new instances.
public static string $DEFAULT_DELIMITER
return string

$PARSER_METHODS public_oe static_oe property

A list of methods that are used in lexing the SQL query.
public static array $PARSER_METHODS
return array

$delimiter public_oe property

This may change during lexing.
public string $delimiter
return string

$delimiterLen public_oe property

Because parseDelimiter can be called a lot, it would perform a lot of calls to strlen, which might affect performance when the delimiter is big.
public int $delimiterLen
return integer

$errors public_oe property

Usually, the lexing does not stop once an error occurred because that error might be false positive or a partial result (even a bad one) might be needed.
See also: Lexer::error()
public LexerException[],SqlParser\Exceptions $errors
return SqlParser\Exceptions\LexerException[]

$last public_oe property

The index of the last parsed character.
public int $last
return integer

$len public_oe property

By storing its length, a lot of time is saved, because parsing methods would call strlen everytime.
public int $len
return integer

$list public_oe property

Tokens extracted from given strings.
public TokensList,sqlparser $list
return TokensList

$str public_oe property

The string to be parsed.
public string|UtfString,sqlparser $str
return string | UtfString

$strict public_oe property

Whether errors should throw exceptions or just be stored.
See also: static::$errors
public bool $strict
return boolean