|
TuringSim
C++ framework to simulate abstract computing models
|
3 #include <utils/messageException.h>
4 #include <symbol/turingMachineSymbolPattern.h>
56 typedef std::tuple<TokenKind, size_t, size_t>
Token;
100 std::pair<bool, std::string>
isVariableNode(
const std::string& node)
const;
109 std::pair<SymbolPattern, size_t>
parse_negative_pattern(
const std::string& pattern,
const std::vector <Token>& tokens,
size_t position)
const;
118 std::pair<SymbolPattern, size_t>
parse_positive_pattern(
const std::string& pattern,
const std::vector <Token>& tokens,
size_t position)
const;
131 std::vector<Token>
tokenize(
const std::string& pattern)
const;
138 Token tokenize(
const std::string& pattern,
size_t start)
const;
153 void translateKeywords(
const std::string& pattern, std::vector <Token>& tokens)
const;
162 template<
typename CharT,
typename Traits = std::
char_traits <CharT>>
163 friend std::basic_ostream <CharT, Traits>&
operator<<(std::basic_ostream <CharT, Traits>& os,
const TokenKind& tokenKind) {
203 template<
typename CharT,
typename Traits>
204 friend std::basic_ostream <CharT, Traits>&
operator<<(std::basic_ostream <CharT, Traits>& os,
const Token& token) {
205 using Utils::Debug::operator<<;
212 char separator =
',';
213 std::string blank =
"";
214 std::set<char> ignore{
'\n',
' ',
'\t'};
215 std::string variablePrefix =
"_";
216 std::string escapePrefix =
"\\";
260 using Utils::Debug::operator<<;
261 std::ostringstream ss;
262 ss << this->
msg << std::endl;
263 ss <<
" left: " <<
left << std::endl;
264 ss <<
" right: " <<
right << std::endl;
265 ss <<
" separator: " <<
separator << std::endl;
266 ss <<
" blank: " <<
blank << std::endl;
317 const std::vector<TuringStyleMixedSymbolPatternParser::Token>&
tokens,
328 using Utils::Debug::operator<<;
329 std::ostringstream ss;
330 ss << this->
msg << std::endl;
334 ss <<
" toParse: " <<
toParse << std::endl;
336 ss <<
" position: " <<
position << std::endl;
338 ss <<
" position at the end" << std::endl;
340 ss <<
" position after the end" << std::endl;
355 std::vector <TuringStyleMixedSymbolPatternParser::Token>
tokens;
MessageException()=delete
a message exception must have an explicative message.
Exception launched when we try to parse a string with a syntax error as a MConfiguration<std::string>...
@ EOS
The token at the end of the string.
friend std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &os, const Token &token)
Debug printer of Token.
char left
Opening delimiter.
std::set< char > ignore
Characters to ignore.
std::string msg
The error message.
TuringStyleMixedSymbolPatternParserBadInitializationException()=delete
Deleted default constructor: a SymbolPatternParserInitializationError must contain interesting inform...
The Base class for all custom exceptions.
std::string escapePrefix
Prefix to escape keywords.
TuringStyleMixedSymbolPatternParserBadInitializationException(std::string message, char left, char right, char separator, std::string blank, std::set< char > ignore, const std::string &variablePrefix, const std::string &escapePrefix)
Builds a SymbolPatternParserInitializationError.
A parser of mixed symbol pattern where symbols are std::string
The namespace for symbol patterns.
std::string sub(const std::string &pattern, const TuringStyleMixedSymbolPatternParser::Token &token) const
Get the text of a token.
virtual std::string makeFullMessage() const override
Build the full error message. It should be overridden by derived class that adds data to the exceptio...
Exception thrown when the special characters of a SymbolPatternParser are not consistent.
friend std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &os, const TokenKind &tokenKind)
Debug printer of TokenKind.
std::string blank
Blank string..
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 vari...
TuringStyleMixedSymbolPatternSyntaxErrorException()=delete
Deleted default constructor: a TuringStyleMixedSymbolPatternSyntaxErrorException must contain interes...
std::tuple< TokenKind, size_t, size_t > Token
Type of tokens: the first component is the category, the second is the starting character,...
TuringStyleMixedSymbolPatternSyntaxErrorException(std::string message, std::string toParse, const std::vector< TuringStyleMixedSymbolPatternParser::Token > &tokens, size_t position, std::string additionalMessage="")
Builds a TuringStyleMixedSymbolPatternSyntaxErrorException.
std::string toParse
the string we try to parse.
@ RIGHT
Right parenthesis.
char right
Closing delimiter.
std::vector< TuringStyleMixedSymbolPatternParser::Token > tokens
The list of tokens.
SymbolPattern parse(const std::string &pattern) const
Parse a string into a symbol pattern. The usual entry point.
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.
TuringStyleMixedSymbolPatternParser()
Builds TuringStyleMixedSymbolPatternParser with default parameters.
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.
TokenKind
Category of tokens.
char separator
The separator in lists.
void checkInitialization() const
Check if parameters of the parser are consistent. This function is called by constructors.
std::optional< Token > translateKeyword(const std::string &pattern, const TuringStyleMixedSymbolPatternParser::Token &token) const
Translate a single token by recognizing keyword.
std::vector< Token > tokenize(const std::string &pattern) const
Fully lex a string, without recognizing keyword.
virtual std::string makeFullMessage() const override
Build the full error message. It should be overridden by derived class that adds data to the exceptio...
std::string additionalMessage
Additional error message.
std::function< std::basic_ostream< CharT, Traits > &(std::basic_ostream< CharT, Traits > &)> debug(const T &s)
Generic debug printing function.
@ SEPARATOR
Separator of symbols, usually, the comma.
std::string variablePrefix
Prefix to mark variable names.
void translateKeywords(const std::string &pattern, std::vector< Token > &tokens) const
Translate a full sequence of tokens.