myTinySQL v0.2.0-2-g5000098
A tiny SQL interpreter over fixed-width text files
Loading...
Searching...
No Matches
Classes | Enumerations | Functions | Variables
tinysql::anonymous_namespace{Parser.cpp} Namespace Reference

Classes

class  Parser
 A recursive-descent parser: one method per statement type, reading the tokens left to right. More...
 
struct  Token
 One token of a statement. More...
 

Enumerations

enum class  TokenKind { Word , String , Symbol , End }
 The kinds of token the tokenizer produces. More...
 

Functions

bool isWordChar (char c)
 Tells whether a character can stand next to an apostrophe inside a word.
 
bool isApostrophe (std::string_view text, std::size_t i)
 Tells whether the ' at a position is an apostrophe inside a word, as in d'Asti, L'Aquila or dell'800.
 
std::vector< Token > tokenize (std::string_view sql)
 Splits a statement into tokens.
 
std::string describe (const Token &token)
 Describes a token for an error message.
 
bool isComparison (std::string_view op)
 Tells whether a symbol is a comparison operator.
 
bool isComment (std::string_view sql)
 Tells whether a line is a comment or empty.
 

Variables

constexpr std::string_view kDelimiters = " \t\r\n(),*;@=<>!'"
 The characters that end a word (a ' only when it is not an apostrophe, see isApostrophe()).
 

Enumeration Type Documentation

◆ TokenKind

enum class tinysql::anonymous_namespace{Parser.cpp}::TokenKind
strong

The kinds of token the tokenizer produces.

Enumerator
Word 

A keyword, name or bare value, e.g. SELECT, EMPLOY, Torino, 42.

String 

A 'quoted string', without its quotes.

Symbol 

Punctuation or an operator: ( ) , * ; @ = != <> < <= > >=.

End 

The end of the statement.

Definition at line 33 of file Parser.cpp.

Function Documentation

◆ describe()

std::string tinysql::anonymous_namespace{Parser.cpp}::describe ( const Token &  token)

Describes a token for an error message.

Parameters
tokenThe token.
Returns
E.g. "FROM", 'text', or "end of statement".

Definition at line 144 of file Parser.cpp.

◆ isApostrophe()

bool tinysql::anonymous_namespace{Parser.cpp}::isApostrophe ( std::string_view  text,
std::size_t  i 
)

Tells whether the ' at a position is an apostrophe inside a word, as in d'Asti, L'Aquila or dell'800.

Italian (and other languages) put apostrophes inside names, so a ' with a letter or digit on both sides is part of the word, in quotes or not. Only a ' next to a space, a comma, a bracket or the end of the text starts or ends a quoted string.

Parameters
textThe text.
iA position in it.
Returns
True if the character there is a ' with word characters on both sides (see isWordChar()).

Definition at line 67 of file Parser.cpp.

◆ isComment()

bool tinysql::anonymous_namespace{Parser.cpp}::isComment ( std::string_view  sql)

Tells whether a line is a comment or empty.

Parameters
sqlThe line.
Returns
True for an empty line, -- ..., or REM ....

Definition at line 497 of file Parser.cpp.

◆ isComparison()

bool tinysql::anonymous_namespace{Parser.cpp}::isComparison ( std::string_view  op)

Tells whether a symbol is a comparison operator.

Parameters
opThe symbol.
Returns
True for = != <> < <= > >=.

Definition at line 159 of file Parser.cpp.

◆ isWordChar()

bool tinysql::anonymous_namespace{Parser.cpp}::isWordChar ( char  c)

Tells whether a character can stand next to an apostrophe inside a word.

Parameters
cThe character.
Returns
True for an ASCII letter or digit, or any byte of a UTF-8 character such as รจ.

Definition at line 52 of file Parser.cpp.

◆ tokenize()

std::vector< Token > tinysql::anonymous_namespace{Parser.cpp}::tokenize ( std::string_view  sql)

Splits a statement into tokens.

Parameters
sqlThe statement.
Returns
The tokens, always ending with one TokenKind::End.
Exceptions
SqlErrorOn an unterminated quoted string or a lone !.

Definition at line 77 of file Parser.cpp.

Variable Documentation

◆ kDelimiters

constexpr std::string_view tinysql::anonymous_namespace{Parser.cpp}::kDelimiters = " \t\r\n(),*;@=<>!'"
constexpr

The characters that end a word (a ' only when it is not an apostrophe, see isApostrophe()).

Definition at line 47 of file Parser.cpp.