Parser
An LL(*) recursive-descent parser for MySQL CREATE TABLE statements.
Parses a CREATE TABLE statement, reports any errors in it, and generates an AST.
Table of Contents
Properties
- $lexer : Lexer
- The lexer.
- $statement : string
- The statement to parse.
Methods
- __construct() : mixed
- Creates a new statement parser object.
- createStatement() : AbstractCreateStatement
- CreateStatement ::= CREATE [TEMPORARY] TABLE Abstraction to allow for support of other schema objects like views in the future.
- free() : mixed
- Frees this parser, enabling it to be reused.
- getAST() : AbstractCreateStatement
- Parses and builds AST for the given Query.
- getLexer() : Lexer
- Gets the lexer used by the parser.
- indexName() : Identifier
- Return the name of an index. No name has been supplied if the next token is USING which defines the index type.
- indexOptions() : array<string|int, mixed>
- IndexOptions ::= KEY_BLOCK_SIZE [=] value | index_type | WITH PARSER parser_name | COMMENT 'string'
- indexType() : string
- IndexType ::= USING { BTREE | HASH }
- match() : mixed
- Attempts to match the given token with the current lookahead token.
- parse() : array<string|int, Table>
- Parses a statement string.
- queryLanguage() : AbstractCreateStatement
- queryLanguage ::= CreateTableStatement
- semanticalError() : mixed
- Generates a new semantical error.
- syntaxError() : mixed
- Generates a new syntax error.
- characterDataTypeOptions() : array<string|int, mixed>
- Parse common options for numeric datatypes
- columnDataType() : AbstractDataType
- DataType ::= BIT[(length)] | TINYINT[(length)] [UNSIGNED] [ZEROFILL] | SMALLINT[(length)] [UNSIGNED] [ZEROFILL] | MEDIUMINT[(length)] [UNSIGNED] [ZEROFILL] | INT[(length)] [UNSIGNED] [ZEROFILL] | INTEGER[(length)] [UNSIGNED] [ZEROFILL] | BIGINT[(length)] [UNSIGNED] [ZEROFILL] | REAL[(length,decimals)] [UNSIGNED] [ZEROFILL] | DOUBLE[(length,decimals)] [UNSIGNED] [ZEROFILL] | FLOAT[(length,decimals)] [UNSIGNED] [ZEROFILL] | DECIMAL[(length[,decimals])] [UNSIGNED] [ZEROFILL] | NUMERIC[(length[,decimals])] [UNSIGNED] [ZEROFILL] | DATE | TIME[(fsp)] | TIMESTAMP[(fsp)] | DATETIME[(fsp)] | YEAR | CHAR[(length)] [BINARY] [CHARACTER SET charset_name] [COLLATE collation_name] | VARCHAR(length) [BINARY] [CHARACTER SET charset_name] [COLLATE collation_name] | BINARY[(length)] | VARBINARY(length) | TINYBLOB | BLOB | MEDIUMBLOB | LONGBLOB | TINYTEXT [BINARY] [CHARACTER SET charset_name] [COLLATE collation_name] | TEXT [BINARY] [CHARACTER SET charset_name] [COLLATE collation_name] | MEDIUMTEXT [BINARY] [CHARACTER SET charset_name] [COLLATE collation_name] | LONGTEXT [BINARY] [CHARACTER SET charset_name] [COLLATE collation_name] | ENUM(value1,value2,value3,...) [CHARACTER SET charset_name] [COLLATE collation_name] | SET(value1,value2,value3,...) [CHARACTER SET charset_name] [COLLATE collation_name] | JSON
- columnDefaultValue() : mixed
- DefaultValue::= DEFAULT default_value
- createColumnDefinitionItem() : CreateColumnDefinitionItem
- CreateColumnDefinitionItem ::= col_name column_definition
- createDefinition() : CreateDefinition
- Parses the table field/index definition
- createDefinitionItem() : AbstractCreateDefinitionItem
- Parse the definition of a single column or index
- createForeignKeyDefinitionItem() : CreateForeignKeyDefinitionItem
- Parses a foreign key definition item contained in the create definition
- createIndexDefinitionItem() : CreateIndexDefinitionItem
- Parses an index definition item contained in the create definition
- createTableClause() : CreateTableClause
- CreateTableClause ::= CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
- createTableStatement() : CreateTableStatement
- CreateTableStatement ::= CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name (create_definition,...) [tbl_options]
- dataTypeLength() : int
- Determine length parameter of a column field definition, i.E. INT(11) or VARCHAR(255)
- enumerationDataTypeOptions() : array<string|int, mixed>
- Parse shared options for enumeration datatypes (ENUM and SET)
- fractionalSecondsPart() : int
- Determine the fractional seconds part support for TIME, DATETIME and TIMESTAMP columns
- indexColumnName() : IndexColumnName
- IndexColumnName ::= col_name [(length)] [ASC | DESC]
- numericDataTypeOptions() : array<string|int, mixed>
- Parse common options for numeric datatypes
- peekBeyondClosingParenthesis() : array<string|int, mixed>
- Peeks beyond the matched closing parenthesis and returns the first token after that one.
- referenceDefinition() : ReferenceDefinition
- ReferenceDefinition ::= REFERENCES tbl_name (index_col_name,...) [MATCH FULL | MATCH PARTIAL | MATCH SIMPLE] [ON DELETE reference_option] [ON UPDATE reference_option]
- referenceOption() : string
- ReferenceOption ::= RESTRICT | CASCADE | SET NULL | NO ACTION
- schemaObjectName() : Identifier
- Certain objects within MySQL, including database, table, index, column, alias, view, stored procedure, partition, tablespace, and other object names are known as identifiers.
- tableOptions() : array<string|int, mixed>
- Parse MySQL table options
- tableOptionValue() : mixed
- Return the value of an option, skipping the optional equal sign.
- valueList() : array<string|int, mixed>
- Return all defined values for an enumeration datatype (ENUM, SET)
- valueListItem() : string
- Return a value list item for an enumeration set
Properties
$lexer
The lexer.
        protected
            Lexer
    $lexer
    
    
    
    
    
    
$statement
The statement to parse.
        protected
            string
    $statement
    
    
    
    
    
    
Methods
__construct()
Creates a new statement parser object.
    public
                    __construct(string $statement) : mixed
    Parameters
- $statement : string
- 
                    The statement to parse. 
createStatement()
CreateStatement ::= CREATE [TEMPORARY] TABLE Abstraction to allow for support of other schema objects like views in the future.
    public
                    createStatement() : AbstractCreateStatement
    Tags
Return values
AbstractCreateStatementfree()
Frees this parser, enabling it to be reused.
    public
                    free([bool $deep = false ][, int $position = 0 ]) : mixed
    Parameters
- $deep : bool = false
- 
                    Whether to clean peek and reset errors. 
- $position : int = 0
- 
                    Position to reset. 
getAST()
Parses and builds AST for the given Query.
    public
                    getAST() : AbstractCreateStatement
    Tags
Return values
AbstractCreateStatementgetLexer()
Gets the lexer used by the parser.
    public
                    getLexer() : Lexer
    Return values
LexerindexName()
Return the name of an index. No name has been supplied if the next token is USING which defines the index type.
    public
                    indexName() : Identifier
    Tags
Return values
IdentifierindexOptions()
IndexOptions ::= KEY_BLOCK_SIZE [=] value | index_type | WITH PARSER parser_name | COMMENT 'string'
    public
                    indexOptions() : array<string|int, mixed>
    Tags
Return values
array<string|int, mixed>indexType()
IndexType ::= USING { BTREE | HASH }
    public
                    indexType() : string
    Tags
Return values
stringmatch()
Attempts to match the given token with the current lookahead token.
    public
                    match(int $token) : mixed
    If they match, updates the lookahead token; otherwise raises a syntax error.
Parameters
- $token : int
- 
                    The token type. 
Tags
parse()
Parses a statement string.
    public
                    parse() : array<string|int, Table>
    Tags
Return values
array<string|int, Table>queryLanguage()
queryLanguage ::= CreateTableStatement
    public
                    queryLanguage() : AbstractCreateStatement
    Tags
Return values
AbstractCreateStatementsemanticalError()
Generates a new semantical error.
    public
                    semanticalError([string $message = '' ][, array<string|int, mixed>|null $token = null ]) : mixed
    Parameters
- $message : string = ''
- 
                    Optional message. 
- $token : array<string|int, mixed>|null = null
- 
                    Optional token. 
Tags
syntaxError()
Generates a new syntax error.
    public
                    syntaxError([string $expected = '' ][, array<string|int, mixed>|null $token = null ]) : mixed
    Parameters
- $expected : string = ''
- 
                    Expected string. 
- $token : array<string|int, mixed>|null = null
- 
                    Got token. 
Tags
characterDataTypeOptions()
Parse common options for numeric datatypes
    protected
                    characterDataTypeOptions() : array<string|int, mixed>
    Tags
Return values
array<string|int, mixed>columnDataType()
DataType ::= BIT[(length)] | TINYINT[(length)] [UNSIGNED] [ZEROFILL] | SMALLINT[(length)] [UNSIGNED] [ZEROFILL] | MEDIUMINT[(length)] [UNSIGNED] [ZEROFILL] | INT[(length)] [UNSIGNED] [ZEROFILL] | INTEGER[(length)] [UNSIGNED] [ZEROFILL] | BIGINT[(length)] [UNSIGNED] [ZEROFILL] | REAL[(length,decimals)] [UNSIGNED] [ZEROFILL] | DOUBLE[(length,decimals)] [UNSIGNED] [ZEROFILL] | FLOAT[(length,decimals)] [UNSIGNED] [ZEROFILL] | DECIMAL[(length[,decimals])] [UNSIGNED] [ZEROFILL] | NUMERIC[(length[,decimals])] [UNSIGNED] [ZEROFILL] | DATE | TIME[(fsp)] | TIMESTAMP[(fsp)] | DATETIME[(fsp)] | YEAR | CHAR[(length)] [BINARY] [CHARACTER SET charset_name] [COLLATE collation_name] | VARCHAR(length) [BINARY] [CHARACTER SET charset_name] [COLLATE collation_name] | BINARY[(length)] | VARBINARY(length) | TINYBLOB | BLOB | MEDIUMBLOB | LONGBLOB | TINYTEXT [BINARY] [CHARACTER SET charset_name] [COLLATE collation_name] | TEXT [BINARY] [CHARACTER SET charset_name] [COLLATE collation_name] | MEDIUMTEXT [BINARY] [CHARACTER SET charset_name] [COLLATE collation_name] | LONGTEXT [BINARY] [CHARACTER SET charset_name] [COLLATE collation_name] | ENUM(value1,value2,value3,...) [CHARACTER SET charset_name] [COLLATE collation_name] | SET(value1,value2,value3,...) [CHARACTER SET charset_name] [COLLATE collation_name] | JSON
    protected
                    columnDataType() : AbstractDataType
    Tags
Return values
AbstractDataTypecolumnDefaultValue()
DefaultValue::= DEFAULT default_value
    protected
                    columnDefaultValue() : mixed
    Tags
createColumnDefinitionItem()
CreateColumnDefinitionItem ::= col_name column_definition
    protected
                    createColumnDefinitionItem() : CreateColumnDefinitionItem
    column_definition: data_type [NOT NULL | NULL] [DEFAULT default_value] [AUTO_INCREMENT] [UNIQUE [KEY] | [PRIMARY] KEY] [COMMENT 'string'] [COLUMN_FORMAT {FIXED|DYNAMIC|DEFAULT}] [STORAGE {DISK|MEMORY|DEFAULT}] [reference_definition]
Tags
Return values
CreateColumnDefinitionItemcreateDefinition()
Parses the table field/index definition
    protected
                    createDefinition() : CreateDefinition
    createDefinition ::= ( col_name column_definition | [CONSTRAINT [symbol]] PRIMARY KEY [index_type] (index_col_name,...) [index_option] ... | {INDEX|KEY} [index_name] [index_type] (index_col_name,...) [index_option] ... | [CONSTRAINT [symbol]] UNIQUE [INDEX|KEY] [index_name] [index_type] (index_col_name,...) [index_option] ... | {FULLTEXT|SPATIAL} [INDEX|KEY] [index_name] (index_col_name,...) [index_option] ... | [CONSTRAINT [symbol]] FOREIGN KEY [index_name] (index_col_name,...) reference_definition | CHECK (expr) )
Tags
Return values
CreateDefinitioncreateDefinitionItem()
Parse the definition of a single column or index
    protected
                    createDefinitionItem() : AbstractCreateDefinitionItem
    Tags
Return values
AbstractCreateDefinitionItemcreateForeignKeyDefinitionItem()
Parses a foreign key definition item contained in the create definition
    protected
                    createForeignKeyDefinitionItem() : CreateForeignKeyDefinitionItem
    Tags
Return values
CreateForeignKeyDefinitionItemcreateIndexDefinitionItem()
Parses an index definition item contained in the create definition
    protected
                    createIndexDefinitionItem() : CreateIndexDefinitionItem
    Tags
Return values
CreateIndexDefinitionItemcreateTableClause()
CreateTableClause ::= CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
    protected
                    createTableClause() : CreateTableClause
    Tags
Return values
CreateTableClausecreateTableStatement()
CreateTableStatement ::= CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name (create_definition,...) [tbl_options]
    protected
                    createTableStatement() : CreateTableStatement
    Tags
Return values
CreateTableStatementdataTypeLength()
Determine length parameter of a column field definition, i.E. INT(11) or VARCHAR(255)
    protected
                    dataTypeLength([bool $required = false ]) : int
    Parameters
- $required : bool = false
Tags
Return values
intenumerationDataTypeOptions()
Parse shared options for enumeration datatypes (ENUM and SET)
    protected
                    enumerationDataTypeOptions() : array<string|int, mixed>
    Tags
Return values
array<string|int, mixed>fractionalSecondsPart()
Determine the fractional seconds part support for TIME, DATETIME and TIMESTAMP columns
    protected
                    fractionalSecondsPart() : int
    Tags
Return values
intindexColumnName()
IndexColumnName ::= col_name [(length)] [ASC | DESC]
    protected
                    indexColumnName() : IndexColumnName
    Tags
Return values
IndexColumnNamenumericDataTypeOptions()
Parse common options for numeric datatypes
    protected
                    numericDataTypeOptions() : array<string|int, mixed>
    Tags
Return values
array<string|int, mixed>peekBeyondClosingParenthesis()
Peeks beyond the matched closing parenthesis and returns the first token after that one.
    protected
                    peekBeyondClosingParenthesis([bool $resetPeek = true ]) : array<string|int, mixed>
    Parameters
- $resetPeek : bool = true
- 
                    Reset peek after finding the closing parenthesis. 
Return values
array<string|int, mixed>referenceDefinition()
ReferenceDefinition ::= REFERENCES tbl_name (index_col_name,...) [MATCH FULL | MATCH PARTIAL | MATCH SIMPLE] [ON DELETE reference_option] [ON UPDATE reference_option]
    protected
                    referenceDefinition() : ReferenceDefinition
    Tags
Return values
ReferenceDefinitionreferenceOption()
ReferenceOption ::= RESTRICT | CASCADE | SET NULL | NO ACTION
    protected
                    referenceOption() : string
    Tags
Return values
stringschemaObjectName()
Certain objects within MySQL, including database, table, index, column, alias, view, stored procedure, partition, tablespace, and other object names are known as identifiers.
    protected
                    schemaObjectName() : Identifier
    Tags
Return values
IdentifiertableOptions()
Parse MySQL table options
    protected
                    tableOptions() : array<string|int, mixed>
    ENGINE [=] engine_name | AUTO_INCREMENT [=] value | AVG_ROW_LENGTH [=] value | [DEFAULT] CHARACTER SET [=] charset_name | CHECKSUM [=] {0 | 1} | [DEFAULT] COLLATE [=] collation_name | COMMENT [=] 'string' | COMPRESSION [=] {'ZLIB'|'LZ4'|'NONE'} | CONNECTION [=] 'connect_string' | DATA DIRECTORY [=] 'absolute path to directory' | DELAY_KEY_WRITE [=] {0 | 1} | ENCRYPTION [=] {'Y' | 'N'} | INDEX DIRECTORY [=] 'absolute path to directory' | INSERT_METHOD [=] { NO | FIRST | LAST } | KEY_BLOCK_SIZE [=] value | MAX_ROWS [=] value | MIN_ROWS [=] value | PACK_KEYS [=] {0 | 1 | DEFAULT} | PASSWORD [=] 'string' | ROW_FORMAT [=] {DEFAULT|DYNAMIC|FIXED|COMPRESSED|REDUNDANT|COMPACT} | STATS_AUTO_RECALC [=] {DEFAULT|0|1} | STATS_PERSISTENT [=] {DEFAULT|0|1} | STATS_SAMPLE_PAGES [=] value | TABLESPACE tablespace_name | UNION [=] (tbl_name[,tbl_name]...)
Tags
Return values
array<string|int, mixed>tableOptionValue()
Return the value of an option, skipping the optional equal sign.
    protected
                    tableOptionValue() : mixed
    Tags
valueList()
Return all defined values for an enumeration datatype (ENUM, SET)
    protected
                    valueList() : array<string|int, mixed>
    Tags
Return values
array<string|int, mixed>valueListItem()
Return a value list item for an enumeration set
    protected
                    valueListItem() : string