Parser class implements a text parser which follows simple rules to build tokens. .Sequence of letters, digits, and '_' is a token .Opening or a closing bracket is a token .Sequence of punctuation symbols like * - ; = , etc is a token .Sequence of characters beginning and ending with a quote is a token (escape chars are consistent with JSON) .Whitespace is ignored except in quotes
#include <str.h>
Inheritance diagram for jvar::Parser:Public Member Functions | |
| Parser (const char *txt) | |
| bool | eof () |
| bool | failed () |
| const std::string & | errMsg () |
| const char * | c_str () |
| const std::string & | token () |
| bool | tokenEquals (const char *val) |
| void | advance () |
| void | advance (const char *match) |
| void | setError (const char *msg) |
| void | stripQuotes (bool allowsingle) |
| void | captureDelim (const char *delim) |
Protected Member Functions | |
| bool | charWord (char c) |
| bool | charPunc (char c) |
| bool | charBrac (char c) |
| jvar::Parser::Parser | ( | const char * | txt | ) |
| void jvar::Parser::advance | ( | ) | [inline] |
Advances to the next token by parsing it
Referenced by advance(), jvar::JsonParser::JsonParser(), and jvar::Variant::path().
| void jvar::Parser::advance | ( | const char * | match | ) |
Advances if a matching token is found
| match | String to match |
References advance(), c_str(), setError(), token(), and tokenEquals().
| const char* jvar::Parser::c_str | ( | ) | [inline] |
Returns the current token
References token().
Referenced by advance(), and jvar::JsonParser::JsonParser().
| bool jvar::Parser::eof | ( | ) | [inline] |
Is the entire text parsed
Referenced by jvar::JsonParser::JsonParser(), and jvar::Variant::path().
| const std::string& jvar::Parser::errMsg | ( | ) | [inline] |
Returns the error message
Referenced by jvar::JsonParser::JsonParser().
| bool jvar::Parser::failed | ( | ) | [inline] |
Was there a failure
Referenced by jvar::JsonParser::JsonParser(), and jvar::Variant::parseJson().
| void jvar::Parser::setError | ( | const char * | msg | ) |
Sets an error message and signal failure
| msg | Error text |
Referenced by advance(), jvar::JsonParser::JsonParser(), and Parser().
| void jvar::Parser::stripQuotes | ( | bool | allowsingle | ) |
Strip quotes from the current token string if found
| allowsingle | If true, also allows stripping single quotes |
| const std::string& jvar::Parser::token | ( | ) | [inline] |
Returns the current token
Referenced by advance(), c_str(), jvar::JsonParser::JsonParser(), jvar::Variant::path(), and tokenEquals().
| bool jvar::Parser::tokenEquals | ( | const char * | val | ) | [inline] |
Compares the current token with a string
| val | String to compare |
References token().
Referenced by advance(), jvar::JsonParser::JsonParser(), and jvar::Variant::path().