A recursive-descent parser: one method per statement type, reading the tokens left to right.
More...
|
| | Parser (std::vector< Token > tokens) |
| | Prepares to parse a statement.
|
| |
| Statement | parse () |
| | Parses the whole statement, choosing the method from its first word.
|
| |
|
| const Token & | peek () const |
| | Looks at the next token without consuming it.
|
| |
| Token | next () |
| | Consumes the next token (the End token is never consumed).
|
| |
| void | fail (std::string_view expected) const |
| | Reports a syntax error at the current token.
|
| |
| bool | acceptKeyword (std::string_view keyword) |
| | Consumes the next token if it is a given keyword.
|
| |
| void | expectKeyword (std::string_view keyword) |
| | Consumes a keyword that must come next.
|
| |
| bool | acceptSymbol (std::string_view symbol) |
| | Consumes the next token if it is a given symbol.
|
| |
| void | expectSymbol (std::string_view symbol) |
| | Consumes a symbol that must come next.
|
| |
| std::string | expectWord (std::string_view what) |
| | Consumes a word (a name) that must come next.
|
| |
| std::string | expectValue () |
| | Consumes a value that must come next: a word or a quoted string.
|
| |
| void | expectEnd () |
| | Checks that the statement ends here, after any trailing ; or @.
|
| |
| Condition | parseCondition () |
| | Parses <column> <op> <value>, after the WHERE keyword; <op> is a comparison or LIKE.
|
| |
| SelectStmt | parseSelect () |
| | Parses SELECT <items> FROM <table> [WHERE ...].
|
| |
| InsertStmt | parseInsert () |
| | Parses INSERT INTO <table> VALUES (...). A value is a quoted string, or one or more bare words joined by spaces.
|
| |
| UpdateStmt | parseUpdate () |
| | Parses UPDATE <table> SET <col> = <value>, ... WHERE ....
|
| |
| DeleteStmt | parseDelete () |
| | Parses DELETE FROM <table> WHERE ....
|
| |
| CreateTableStmt | parseCreateTable () |
| | Parses CREATE TABLE <table> (<col> <type>(<width>), ...), where <type> is CHAR or NUMBER.
|
| |
| ColumnFormatStmt | parseColumn () |
| | Parses COLUMN <col> FORMAT A<width>.
|
| |
| DescribeStmt | parseDescribe () |
| | Parses DESCRIBE [<table>].
|
| |
A recursive-descent parser: one method per statement type, reading the tokens left to right.
Definition at line 165 of file Parser.cpp.
◆ Parser()
| tinysql::anonymous_namespace{Parser.cpp}::Parser::Parser |
( |
std::vector< Token > |
tokens | ) |
|
|
inlineexplicit |
Prepares to parse a statement.
- Parameters
-
Definition at line 169 of file Parser.cpp.
◆ acceptKeyword()
| bool tinysql::anonymous_namespace{Parser.cpp}::Parser::acceptKeyword |
( |
std::string_view |
keyword | ) |
|
|
inlineprivate |
Consumes the next token if it is a given keyword.
- Parameters
-
| keyword | The keyword (case-insensitive). |
- Returns
- True if it was there and was consumed.
Definition at line 214 of file Parser.cpp.
◆ acceptSymbol()
| bool tinysql::anonymous_namespace{Parser.cpp}::Parser::acceptSymbol |
( |
std::string_view |
symbol | ) |
|
|
inlineprivate |
Consumes the next token if it is a given symbol.
- Parameters
-
| symbol | The symbol, e.g. ",". |
- Returns
- True if it was there and was consumed.
Definition at line 236 of file Parser.cpp.
◆ expectEnd()
| void tinysql::anonymous_namespace{Parser.cpp}::Parser::expectEnd |
( |
| ) |
|
|
inlineprivate |
Checks that the statement ends here, after any trailing ; or @.
- Exceptions
-
Definition at line 280 of file Parser.cpp.
◆ expectKeyword()
| void tinysql::anonymous_namespace{Parser.cpp}::Parser::expectKeyword |
( |
std::string_view |
keyword | ) |
|
|
inlineprivate |
Consumes a keyword that must come next.
- Parameters
-
| keyword | The keyword (case-insensitive). |
- Exceptions
-
| SqlError | If the next token is something else. |
Definition at line 226 of file Parser.cpp.
◆ expectSymbol()
| void tinysql::anonymous_namespace{Parser.cpp}::Parser::expectSymbol |
( |
std::string_view |
symbol | ) |
|
|
inlineprivate |
Consumes a symbol that must come next.
- Parameters
-
| symbol | The symbol, e.g. "(". |
- Exceptions
-
| SqlError | If the next token is something else. |
Definition at line 248 of file Parser.cpp.
◆ expectValue()
| std::string tinysql::anonymous_namespace{Parser.cpp}::Parser::expectValue |
( |
| ) |
|
|
inlineprivate |
Consumes a value that must come next: a word or a quoted string.
- Returns
- The value's text.
- Exceptions
-
Definition at line 270 of file Parser.cpp.
◆ expectWord()
| std::string tinysql::anonymous_namespace{Parser.cpp}::Parser::expectWord |
( |
std::string_view |
what | ) |
|
|
inlineprivate |
Consumes a word (a name) that must come next.
- Parameters
-
| what | What the word is, for the error message, e.g. "a column name". |
- Returns
- The word.
- Exceptions
-
| SqlError | If the next token is not a word. |
Definition at line 259 of file Parser.cpp.
◆ fail()
| void tinysql::anonymous_namespace{Parser.cpp}::Parser::fail |
( |
std::string_view |
expected | ) |
const |
|
inlineprivate |
Reports a syntax error at the current token.
- Parameters
-
| expected | What should have come, e.g. "a table name". |
- Exceptions
-
| SqlError | Always: "expected ... but found ...". |
Definition at line 206 of file Parser.cpp.
◆ next()
| Token tinysql::anonymous_namespace{Parser.cpp}::Parser::next |
( |
| ) |
|
|
inlineprivate |
Consumes the next token (the End token is never consumed).
- Returns
- The token.
Definition at line 201 of file Parser.cpp.
◆ parse()
| Statement tinysql::anonymous_namespace{Parser.cpp}::Parser::parse |
( |
| ) |
|
|
inline |
Parses the whole statement, choosing the method from its first word.
- Returns
- The parsed statement.
- Exceptions
-
| SqlError | On an unknown command or a syntax error. |
Definition at line 174 of file Parser.cpp.
◆ parseColumn()
| ColumnFormatStmt tinysql::anonymous_namespace{Parser.cpp}::Parser::parseColumn |
( |
| ) |
|
|
inlineprivate |
◆ parseCondition()
| Condition tinysql::anonymous_namespace{Parser.cpp}::Parser::parseCondition |
( |
| ) |
|
|
inlineprivate |
Parses <column> <op> <value>, after the WHERE keyword; <op> is a comparison or LIKE.
- Returns
- The condition.
- Exceptions
-
Definition at line 292 of file Parser.cpp.
◆ parseCreateTable()
| CreateTableStmt tinysql::anonymous_namespace{Parser.cpp}::Parser::parseCreateTable |
( |
| ) |
|
|
inlineprivate |
Parses CREATE TABLE <table> (<col> <type>(<width>), ...), where <type> is CHAR or NUMBER.
- Returns
- The CreateTableStmt.
- Exceptions
-
| SqlError | On a syntax error, an unknown type, or a width that is not a positive integer. |
Definition at line 425 of file Parser.cpp.
◆ parseDelete()
| DeleteStmt tinysql::anonymous_namespace{Parser.cpp}::Parser::parseDelete |
( |
| ) |
|
|
inlineprivate |
◆ parseDescribe()
| DescribeStmt tinysql::anonymous_namespace{Parser.cpp}::Parser::parseDescribe |
( |
| ) |
|
|
inlineprivate |
◆ parseInsert()
| InsertStmt tinysql::anonymous_namespace{Parser.cpp}::Parser::parseInsert |
( |
| ) |
|
|
inlineprivate |
Parses INSERT INTO <table> VALUES (...). A value is a quoted string, or one or more bare words joined by spaces.
- Returns
- The InsertStmt.
- Exceptions
-
Definition at line 349 of file Parser.cpp.
◆ parseSelect()
| SelectStmt tinysql::anonymous_namespace{Parser.cpp}::Parser::parseSelect |
( |
| ) |
|
|
inlineprivate |
Parses SELECT <items> FROM <table> [WHERE ...].
- Returns
- The SelectStmt.
- Exceptions
-
Definition at line 321 of file Parser.cpp.
◆ parseUpdate()
| UpdateStmt tinysql::anonymous_namespace{Parser.cpp}::Parser::parseUpdate |
( |
| ) |
|
|
inlineprivate |
Parses UPDATE <table> SET <col> = <value>, ... WHERE ....
- Returns
- The UpdateStmt.
- Exceptions
-
Definition at line 380 of file Parser.cpp.
◆ peek()
| const Token & tinysql::anonymous_namespace{Parser.cpp}::Parser::peek |
( |
| ) |
const |
|
inlineprivate |
Looks at the next token without consuming it.
- Returns
- The next token.
Definition at line 198 of file Parser.cpp.
◆ pos_
| std::size_t tinysql::anonymous_namespace{Parser.cpp}::Parser::pos_ = 0 |
|
private |
The position of the next token to read.
Definition at line 194 of file Parser.cpp.
◆ tokens_
| std::vector<Token> tinysql::anonymous_namespace{Parser.cpp}::Parser::tokens_ |
|
private |
The documentation for this class was generated from the following file: