AST

source: bluebase/core/ast.py

AST stands for Abstract Syntax Tree.


dataclassclass Ast[source]

Bases: ABC

An abstract base class for ASTs.

Common Grammar

table: WORD | WORD "AS" WORD
tables: table | tables COMMA table
attr: WORD | WORD DOT WORD
attrs: attr | attrs COMMA attr
value: FLOAT | INT | BOOL | STRING
values: value | values COMMA value
hand: attr | value
cond: attr COMP hand
conds: cond | conds "AND" cond
assign: attr COMP hand
assigns: assign | assigns COMMA assign
domain: BOOL | INT | FLOAT | STRING LP INT RP
define: attr domain
defines: define | defines COMMA define
where_clause: | "WHERE" conds

Dispatch Grammar

create_statement
    : "CREATE" "TABLE" create_table_body SC
    | "CREATE" "INDEX" create_index_body SC
drop_statement
    : "DROP" "TABLE" drop_table_body SC
    | "DROP" "INDEX" drop_index_body SC

Partial Grammar

create_table_body: table LP defines RP
create_index_body: attr "OF" table
drop_table_body: table
drop_index_body: attr "OF" table

Statement Grammar

select_statement: "SELECT" attrs "FROM" tables where_clause SC
insert_statement: "INSERT" "INTO" table "VALUES" LP values RP SC
delete_statement: "DELETE" "FROM" table where_clause SC
update_statement: "UPDATE" table "SET" assigns where_clause SC
show_tables_statement: "SHOW" "TABLES" SC
describe_table_statement: "DESCRIBE" "TABLE" table SC
dump_table_statement: "DUMP" "TABLE" table SC
exit_statement: "EXIT" SC
dataclassclass AstTable(name: str, alias: str | None)[source]

Bases: Ast

An AST representing a table.

Variables:
  • name (str) – the name of the table

  • alias (str | None) – the alias of the table if "AS" is specified

dataclassclass AstAttr(ref: str | None, name: str)[source]

Bases: Ast

An AST representing a attr.

Variables:
  • ref (str | None) – the reference of the attr if DOT is present

  • name (str) – the name of the attr

dataclassclass AstCond(left_attr: AstAttr, comp: Comp, right_hand: AstAttr | bool | int | float | str)[source]

Bases: Ast

An AST representing a cond.

Variables:
  • left_attr (AstAttr) – the left attr of the cond

  • comp (Comp) – the COMP of the cond

  • right_hand (AstAttr | bool | int | float | str) – the right hand of the cond

dataclassclass AstAssign(left_attr: AstAttr, right_hand: AstAttr | bool | int | float | str)[source]

Bases: Ast

An AST representing a assign.

Variables:
  • left_attr (AstAttr) – the left attr of the assign

  • right_hand (AstAttr | bool | int | float | str) – the right hand of the assign

dataclassclass AstDefine(attr: AstAttr, domain: Domain)[source]

Bases: Ast

An AST representing a define.

Variables:
  • attr (AstAttr) – the attr of the define

  • domain (Domain) – the domain of the define

dataclassclass AstSelect(attrs: list[AstAttr], tables: list[AstTable], conds: list[AstCond])[source]

Bases: Ast

An AST representing a select_statement.

Variables:
  • attrs (list[AstAttr]) – the attrs of the select_statement

  • tables (list[AstTable]) – the tables of the select_statement

  • conds (list[AstCond]) – the conds of the select_statement

dataclassclass AstInsert(table: AstTable, values: tuple[bool | int | float | str, ...])[source]

Bases: Ast

An AST representing a insert_statement.

Variables:
  • table (AstTable) – the table of the insert_statement

  • values (tuple[bool | int | float | str, ...]) – the values of the insert_statement

dataclassclass AstDelete(table: AstTable, conds: list[AstCond])[source]

Bases: Ast

An AST representing a delete_statement.

Variables:
  • table (AstTable) – the table of the delete_statement

  • conds (list[AstCond]) – the conds of the delete_statement

dataclassclass AstUpdate(table: AstTable, assigns: list[AstAssign], conds: list[AstCond])[source]

Bases: Ast

An AST representing a update_statement.

Variables:
  • table (AstTable) – the table of the update_statement

  • assigns (list[AstAssign]) – the assigns of the update_statement

  • conds (list[AstCond]) – the conds of the update_statement

dataclassclass AstCreateTable(table: AstTable, defines: list[AstDefine])[source]

Bases: Ast

An AST representing a create_table_body.

Variables:
  • table (AstTable) – the table of the create_table_body

  • defines (list[AstDefine]) – the defines of the create_table_body

dataclassclass AstDropTable(table: AstTable)[source]

Bases: Ast

An AST representing a drop_table_body.

Variables:

table (AstTable) – the table of the drop_table_body

dataclassclass AstCreateIndex(table: AstTable, attr: AstAttr)[source]

Bases: Ast

An AST representing a create_index_body.

Variables:
  • table (AstTable) – the table of the create_index_body

  • attr (AstAttr) – the attr of the create_index_body

dataclassclass AstDropIndex(table: AstTable, attr: AstAttr)[source]

Bases: Ast

An AST representing a drop_index_body.

Variables:
  • table (AstTable) – the table of the drop_index_body

  • attr (AstAttr) – the attr of the drop_index_body

dataclassclass AstShowTables[source]

Bases: Ast

An AST representing a show_tables_statement.

dataclassclass AstDescribeTable(table: AstTable)[source]

Bases: Ast

An AST representing a describe_table_statement.

Variables:

table (AstTable) – the table of the describe_table_statement

dataclassclass AstDumpTable(table: AstTable)[source]

Bases: Ast

An AST representing a dump_table_statement.

Variables:

table (AstTable) – the table of the dump_table_statement

dataclassclass AstExit[source]

Bases: Ast

An AST representing a exit_statement.