PostgresLexer
class PostgresLexer extends Lexer
| internal |
Lex plain-text pg_dump output with psql's statement boundaries.
psql ends a statement at a semicolon outside parentheses and outside the
BEGIN ... END body of a SQL-standard routine, treats backslash commands as
its own, and reads COPY FROM STDIN data through the \. line.
Constants
| protected HIGH_BYTES |
Bytes of multibyte characters, which unquoted identifiers may contain. |
| protected LETTERS |
|
| protected DIGITS |
|
| protected WHITESPACE |
|
| protected COMMENT_STARTS |
|
| private WINDOW_LENGTH |
The most source that runs are matched against at once. |
| private WINDOW_CUTS |
The bytes a window can be cut before, as no unquoted token contains them. |
| private IDENTIFIER_BYTES |
|
| private DOLLAR_TAG_BYTES |
|
| private SKIP_STOPS |
The bytes where skipping must stop, as they can begin a quoted token, a comment or a boundary. |
| private SPACE |
Whitespace and line comments before a token. Repetitions in the native patterns are bounded so one match stays within PCRE's limits; longer input stops the run and is read by the scanner. |
| private WORD |
A word that is not a string prefix and does not run into a string. |
| private NUMBER |
|
| private QUOTED_IDENTIFIER |
A quoted identifier whose closing quote does not begin a doubled one. |
| private OPERATOR |
An operator, which cannot contain the start of a comment. |
| private PUNCTUATION |
Single-byte punctuation other than parentheses. |
| private STRING_END |
The closing quote of a string literal, not the first of a doubled one, followed by more on its line so it cannot continue on a later one. |
| private STANDARD_STRING |
A plain string literal where backslashes are ordinary characters. |
| private ESCAPED_STRING |
A plain string literal where backslashes are escapes. |
| private STANDARD_RUN |
A run of tokens and standard strings, read in one native call through a semicolon or up to a token that needs boundary handling. |
| private ESCAPED_RUN |
A run of tokens and escaped strings. |
| private SPACE_END |
Whitespace and line comments, matched to report where they end. |
| private TOKEN_END |
A number, operator or punctuation, matched to report where it ends. |
| private LEADING_WORDS |
The letters psql records for the leading words that identify routines and COPY FROM STDIN. |
| private ROUTINE_STARTS |
The leading words of CREATE [OR REPLACE] FUNCTION and PROCEDURE, whose bodies can contain semicolons. |
| private ROUTINE_PREFIXES |
The leading words that can still become a routine start. |
Properties
| protected int | $length | from Lexer | |
| protected int | $position | from Lexer | |
| protected int | $statementStart | from Lexer | |
| protected int | $tokenStart | The start of the token or terminator most recently scanned. |
from Lexer |
| protected bool | $ended | from Lexer | |
| protected int | $windowStart | from Lexer | |
| bool | $standardConformingStrings | Whether ordinary string literals treat backslashes literally. |
Methods
Create a lexer, skipping a UTF-8 byte order mark as psql does.
Begin the next non-empty statement, or return null at the end of the input.
Append a run of regular tokens, or one token that needs boundary handling.
Get the type of a token read in a run, which follows from its upper-case text.
Match a run of tokens at the position, or return null where the scanner must read the next token.
Skip the rest of the current statement and return the offsets of its terminator.
Skip to the parenthesis that closes the given number of open groups and return its start.
Scan the token starting at the current position, or a terminator as End.
Skip to the terminator.
Get the length of a statement terminator at the current position, or zero.
Reset the boundary state tracked within one statement.
Skip the data of a COPY FROM STDIN statement through its \. line.
Skip whitespace and comments.
Skip comments, including nested block comments and psql backslash commands.
Scan a quoted run whose opening quote is at the position, escaped by doubling and optionally backslashes.
Fold an unquoted identifier or keyword to lower case.
Decode a quoted identifier, including Unicode escapes.
Decode any PostgreSQL string literal form.
Details
at line 107
__construct(string $sql)
Create a lexer, skipping a UTF-8 byte order mark as psql does.
in
Lexer at line 77
TokenStream|null
nextStatement()
Begin the next non-empty statement, or return null at the end of the input.
at line 117
void
read(array $types, array $starts, array $ends, array $texts)
Append a run of regular tokens, or one token that needs boundary handling.
at line 164
TokenType
type(string $text)
Get the type of a token read in a run, which follows from its upper-case text.
in
Lexer at line 149
protected array|null
matchRun(string $pattern)
Match a run of tokens at the position, or return null where the scanner must read the next token.
Dialects read runs of ordinary tokens with one native match each, so only tokens that need boundary handling go through the scanner. A statement's first token is matched alone, as parsers skip most statements after it.
in
Lexer at line 194
array
skipStatement()
Skip the rest of the current statement and return the offsets of its terminator.
at line 184
int|null
skipGroup(int $depth)
Skip to the parenthesis that closes the given number of open groups and return its start.
Returns null when the statement ends first.
in
Lexer at line 226
string
value(TokenType $type, int $start, int $end)
Decode a token's value.
in
Lexer at line 239
int
line(int $offset)
Get the one-based line containing a source offset.
in
Lexer at line 247
ParseException
error(string $message, int $offset)
Create a parse error located at a source offset.
in
Lexer at line 255
protected TokenType
scan()
Scan one token or the statement terminator.
in
Lexer at line 272
protected void
finishStatement()
Mark the current statement as ended at its terminator.
at line 192
protected TokenType
scanToken()
Scan the token starting at the current position, or a terminator as End.
at line 237
protected void
skip()
Skip to the terminator.
in
Lexer at line 294
protected int
terminator()
Get the length of a statement terminator at the current position, or zero.
in
Lexer at line 302
protected bool
skipCommand()
Consume a client command between statements.
at line 308
protected void
startStatement()
Reset the boundary state tracked within one statement.
at line 320
protected void
endStatement()
Skip the data of a COPY FROM STDIN statement through its \. line.
at line 359
protected void
skipWhitespace()
Skip whitespace and comments.
at line 377
protected bool
skipComment()
Skip comments, including nested block comments and psql backslash commands.
in
Lexer at line 363
protected void
skipLine()
Skip to the start of the next line.
in
Lexer at line 373
protected void
scanQuoted(string $quote, bool $backslashes, string $description)
Scan a quoted run whose opening quote is at the position, escaped by doubling and optionally backslashes.
at line 431
protected string
word(int $start, int $end)
Fold an unquoted identifier or keyword to lower case.
at line 439
protected string
identifier(int $start, int $end)
Decode a quoted identifier, including Unicode escapes.
at line 453
protected string
string(TokenType $type, int $start, int $end)
Decode any PostgreSQL string literal form.