|
TuringSim
C++ framework to simulate abstract computing models
|
A parser of mixed symbol pattern where symbols are std::string
More...
#include <symbol/turingStyleMixedSymbolPatternParser.h>
Public Types | |
| enum | TokenKind { TokenKind::SEPARATOR, TokenKind::LEFT, TokenKind::RIGHT, TokenKind::IDENT, TokenKind::NONE, TokenKind::NON, TokenKind::ANY, TokenKind::TRUE, TokenKind::EOS } |
| Category of tokens. More... | |
| typedef std::tuple< TokenKind, size_t, size_t > | Token |
| Type of tokens: the first component is the category, the second is the starting character, and the third is the last character (included). | |
Public Member Functions | |
| TuringStyleMixedSymbolPatternParser () | |
| Builds TuringStyleMixedSymbolPatternParser with default parameters. More... | |
| TuringStyleMixedSymbolPatternParser (char left, char right, char separator, std::string blank, std::set< char > ignore, std::string variablePrefix, std::string escapePrefix) | |
| Builds TuringStyleMixedSymbolPatternParser with custom parameters. More... | |
| void | checkInitialization () const |
| Check if parameters of the parser are consistent. This function is called by constructors. More... | |
| SymbolPattern | parse (const std::string &pattern) const |
| Parse a string into a symbol pattern. The usual entry point. More... | |
| std::pair< bool, std::string > | isVariableNode (const std::string &node) const |
| Test is a raw node name is a variable name. A node name is a variable name if it starts with the variable name prefix. More... | |
| std::pair< SymbolPattern, size_t > | parse_negative_pattern (const std::string &pattern, const std::vector< Token > &tokens, size_t position) const |
| Parse a negative list of symbols. More... | |
| std::pair< SymbolPattern, size_t > | parse_positive_pattern (const std::string &pattern, const std::vector< Token > &tokens, size_t position) const |
| Parse a positive list of symbols. More... | |
| std::string | sub (const std::string &pattern, const TuringStyleMixedSymbolPatternParser::Token &token) const |
| Get the text of a token. More... | |
| std::vector< Token > | tokenize (const std::string &pattern) const |
| Fully lex a string, without recognizing keyword. More... | |
| Token | tokenize (const std::string &pattern, size_t start) const |
| Lex a single token. More... | |
| std::optional< Token > | translateKeyword (const std::string &pattern, const TuringStyleMixedSymbolPatternParser::Token &token) const |
| Translate a single token by recognizing keyword. More... | |
| void | translateKeywords (const std::string &pattern, std::vector< Token > &tokens) const |
| Translate a full sequence of tokens. More... | |
Friends | |
| template<typename CharT , typename Traits = std::char_traits <CharT>> | |
| std::basic_ostream< CharT, Traits > & | operator<< (std::basic_ostream< CharT, Traits > &os, const TokenKind &tokenKind) |
| Debug printer of TokenKind. More... | |
| template<typename CharT , typename Traits > | |
| std::basic_ostream< CharT, Traits > & | operator<< (std::basic_ostream< CharT, Traits > &os, const Token &token) |
| Debug printer of Token. More... | |
A parser of mixed symbol pattern where symbols are std::string
We use a Turing-style syntax:
pattern ::=
| "empty"
| letter{"," letter}*
| "non("letter{"," letter}*")"
| "any" | "true"
For instance (spaces and tab are not significant):
To specify a symbol named as a keyword, it should be escaped:
All symbols can be specified when instantiating the parser, as long as there is no conflict.
Definition at line 35 of file turingStyleMixedSymbolPatternParser.h.
Category of tokens.
Definition at line 41 of file turingStyleMixedSymbolPatternParser.h.
| TuringSim::Symbol::TuringStyleMixedSymbolPatternParser::TuringStyleMixedSymbolPatternParser | ( | ) |
Builds TuringStyleMixedSymbolPatternParser with default parameters.
We have:
Definition at line 61 of file turingStyleMixedSymbolPatternParser.cpp.

| TuringSim::Symbol::TuringStyleMixedSymbolPatternParser::TuringStyleMixedSymbolPatternParser | ( | char | left, |
| char | right, | ||
| char | separator, | ||
| std::string | blank, | ||
| std::set< char > | ignore, | ||
| std::string | variablePrefix, | ||
| std::string | escapePrefix | ||
| ) |
Builds TuringStyleMixedSymbolPatternParser with custom parameters.
| [in] | left | the left parenthesis. |
| [in] | right | the right parenthesis. |
| [in] | separator | the separators of symbols. |
| [in] | blank | the blank symbol, represented by "blank" keyword. |
| [in] | ignore | set of characters to ignore. |
| [in] | variablePrefix | The prefix of names that denotes keys. The prefix is removed from the name. |
| [in] | escapePrefix | The prefix to add before an identifier to force it to be recognize as an identifier, even if it is also a keyword. |
Definition at line 65 of file turingStyleMixedSymbolPatternParser.cpp.

| void TuringSim::Symbol::TuringStyleMixedSymbolPatternParser::checkInitialization | ( | ) | const |
Check if parameters of the parser are consistent. This function is called by constructors.
| TuringStyleMixedSymbolPatternParserBadInitializationException | if parameters are conflicting. |
Definition at line 5 of file turingStyleMixedSymbolPatternParser.cpp.

| std::pair< bool, std::string > TuringSim::Symbol::TuringStyleMixedSymbolPatternParser::isVariableNode | ( | const std::string & | node | ) | const |
Test is a raw node name is a variable name. A node name is a variable name if it starts with the variable name prefix.
| [in] | node | the name of the node. |
node is not a variable name, the returned pair is (false, node), otherwise, it is (true, variableName) where variable name is obtained from node by removing the variable name prefix. Definition at line 112 of file turingStyleMixedSymbolPatternParser.cpp.

| TuringStyleMixedSymbolPatternParser::SymbolPattern TuringSim::Symbol::TuringStyleMixedSymbolPatternParser::parse | ( | const std::string & | pattern | ) | const |
Parse a string into a symbol pattern. The usual entry point.
| [in] | pattern | the string to parse. |
| TuringStyleMixedSymbolPatternSyntaxErrorException | if there is a syntax error. |
Definition at line 70 of file turingStyleMixedSymbolPatternParser.cpp.

| std::pair< TuringStyleMixedSymbolPatternParser::SymbolPattern, size_t > TuringSim::Symbol::TuringStyleMixedSymbolPatternParser::parse_negative_pattern | ( | const std::string & | pattern, |
| const std::vector< Token > & | tokens, | ||
| size_t | position | ||
| ) | const |
Parse a negative list of symbols.
| [in] | pattern | the full string to parse. |
| [in] | tokens | the sequence of tokens. |
| [in] | position | the position in tokens to start parsing. |
| TuringStyleMixedSymbolPatternSyntaxErrorException | if there is a syntax error. |
Definition at line 124 of file turingStyleMixedSymbolPatternParser.cpp.


| std::pair< TuringStyleMixedSymbolPatternParser::SymbolPattern, size_t > TuringSim::Symbol::TuringStyleMixedSymbolPatternParser::parse_positive_pattern | ( | const std::string & | pattern, |
| const std::vector< Token > & | tokens, | ||
| size_t | position | ||
| ) | const |
Parse a positive list of symbols.
| [in] | pattern | the full string to parse. |
| [in] | tokens | the sequence of tokens. |
| [in] | position | the position in tokens to start parsing. |
| TuringStyleMixedSymbolPatternSyntaxErrorException | if there is a syntax error. |
Definition at line 197 of file turingStyleMixedSymbolPatternParser.cpp.


| std::string TuringSim::Symbol::TuringStyleMixedSymbolPatternParser::sub | ( | const std::string & | pattern, |
| const TuringStyleMixedSymbolPatternParser::Token & | token | ||
| ) | const |
Get the text of a token.
| [in] | pattern | the full string. |
| [in] | token | the token we want the string. |
Definition at line 262 of file turingStyleMixedSymbolPatternParser.cpp.

| std::vector< TuringStyleMixedSymbolPatternParser::Token > TuringSim::Symbol::TuringStyleMixedSymbolPatternParser::tokenize | ( | const std::string & | pattern | ) | const |
Fully lex a string, without recognizing keyword.
| [in] | pattern | the string to parse. |
Definition at line 269 of file turingStyleMixedSymbolPatternParser.cpp.

| TuringStyleMixedSymbolPatternParser::Token TuringSim::Symbol::TuringStyleMixedSymbolPatternParser::tokenize | ( | const std::string & | pattern, |
| size_t | start | ||
| ) | const |
Lex a single token.
| [in] | pattern | the full string to parse. |
| [in] | start | the starting position. |
start. Definition at line 282 of file turingStyleMixedSymbolPatternParser.cpp.
| std::optional< TuringStyleMixedSymbolPatternParser::Token > TuringSim::Symbol::TuringStyleMixedSymbolPatternParser::translateKeyword | ( | const std::string & | pattern, |
| const TuringStyleMixedSymbolPatternParser::Token & | token | ||
| ) | const |
Translate a single token by recognizing keyword.
| [in] | pattern | the full string to parse. |
| [in] | token | the token to translate. |
This function translate IDENT token into dedicated keyword tokens.
Definition at line 298 of file turingStyleMixedSymbolPatternParser.cpp.


| void TuringSim::Symbol::TuringStyleMixedSymbolPatternParser::translateKeywords | ( | const std::string & | pattern, |
| std::vector< Token > & | tokens | ||
| ) | const |
Translate a full sequence of tokens.
| [in] | pattern | the full string to parse. |
| [in,out] | tokens | the list of tokens, modified in-place. |
Definition at line 318 of file turingStyleMixedSymbolPatternParser.cpp.


|
friend |
Debug printer of Token.
| CharT | the char type. |
| Traits | std::basic_ostream trait. |
| [in,out] | os | the output stream |
| [in] | token | the token to print. |
Definition at line 204 of file turingStyleMixedSymbolPatternParser.h.
|
friend |
Debug printer of TokenKind.
| CharT | the char type. |
| Traits | std::basic_ostream trait. |
| [in,out] | os | the output stream |
| [in] | tokenKind | the token kind to print. |
Definition at line 163 of file turingStyleMixedSymbolPatternParser.h.