jvar
JS inspired Variant and Json
jvar::Parser Class Reference

Detailed Description

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)

Constructor & Destructor Documentation

jvar::Parser::Parser ( const char *  txt)

Constructor

Parameters:
txtText to parse

References setError().


Member Function Documentation

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

Parameters:
matchString to match

References advance(), c_str(), setError(), token(), and tokenEquals().

const char* jvar::Parser::c_str ( ) [inline]

Returns the current token

Returns:
Pointer to current token

References token().

Referenced by advance(), and jvar::JsonParser::JsonParser().

bool jvar::Parser::eof ( ) [inline]

Is the entire text parsed

Returns:
True if at the end of text has reached

Referenced by jvar::JsonParser::JsonParser(), and jvar::Variant::path().

const std::string& jvar::Parser::errMsg ( ) [inline]

Returns the error message

Returns:
Reference to the formatted error message string

Referenced by jvar::JsonParser::JsonParser().

bool jvar::Parser::failed ( ) [inline]

Was there a failure

Returns:
True if there was an error, false otherwise

Referenced by jvar::JsonParser::JsonParser(), and jvar::Variant::parseJson().

void jvar::Parser::setError ( const char *  msg)

Sets an error message and signal failure

Parameters:
msgError text

Referenced by advance(), jvar::JsonParser::JsonParser(), and Parser().

void jvar::Parser::stripQuotes ( bool  allowsingle)

Strip quotes from the current token string if found

Parameters:
allowsingleIf true, also allows stripping single quotes
const std::string& jvar::Parser::token ( ) [inline]

Returns the current token

Returns:
Reference to 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

Parameters:
valString to compare
Returns:
True if equal, false otherwise

References token().

Referenced by advance(), jvar::JsonParser::JsonParser(), and jvar::Variant::path().


The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerator