Expand description
§sql_create_parser
§Purpose
sql_create_parser is used for parsing SQL CREATE TABLE queries into a structured Abstract Syntax Tree (AST) using Rust and pest.
This parser analyzes CREATE TABLE syntax. It identifies the table name and a list of column definitions. Each definition consists of a column name and its data type (e.g., INT, TEXT, VARCHAR(255)). The resulting AST (CreateTableQuery) can be used for schema validation or code generation.
§Grammar
- WHITESPACE: Matches spaces, tabs, and newlines (ignored).
- Keywords:
CREATE,TABLE. - New Keywords:
NOT,NULL. - identifier: Matches table and column names.
- number: Matches digits (for VARCHAR length).
- simple_type: Matches types like
INT,TEXT,BOOLEAN,DATE. - varchar_type: Matches
VARCHAR(n). - data_type: A rule that combines
simple_typeandvarchar_type. - not_null_constraint: New rule that matches
NOT NULL. - column_definition: Matches a column name, its
data_type, and an optionalnot_null_constraint. - column_list: Matches one or more
column_definitions separated by commas. - create_query: The main rule, defines the full
CREATE TABLEstatement structure.
Structs§
- Column
Def - Represents a single column definition.
- Create
Table Query - Main structure for a CREATE TABLE query.
- SQLParser
Enums§
- Data
Type - Represents a SQL Data Type.
- Parse
Error - Rule
Functions§
- parse_
query - Function to parse a SQL CREATE TABLE query.