Parse commands. More...

#include <senf/Utils/Console/Parse.hh>

Inheritance diagram for senf::console::CommandParser:

Classes

struct  ParserErrorException
 Exception thrown when the parser detects an error. More...
 
struct  SetIncremental
 

Public Types

typedef boost::function< void(ParseCommandInfo const &)> Callback
 

Public Member Functions

void parse (std::string const &command, Callback cb)
 Parse string. More...
 
void parseFile (std::string const &filename, Callback cb)
 Parse file. More...
 
void parseArguments (std::string const &arguments, ParseCommandInfo &info)
 Parse arguments. More...
 
void parsePath (std::string const &path, ParseCommandInfo &info)
 Parse path. More...
 
std::string::size_type parseIncremental (std::string const &commands, Callback cb)
 Incremental parse. More...
 

Static Public Member Functions

static bool isSpecialChar (char ch)
 Check, if ch is a special character. More...
 
static bool isPunctuationChar (char ch)
 Check, if ch is a punctuation character. More...
 
static bool isSpaceChar (char ch)
 Check, if ch is a space character. More...
 
static bool isInvalidChar (char ch)
 Check, if ch is an invalid character. More...
 
static bool isWordChar (char ch)
 Check, if ch is a word character. More...
 

Structors and default members

 CommandParser ()
 
 ~CommandParser ()
 

Detailed Description

Parse commands.

This class implements a parser for the console/config language. It supports parsing strings as well as files. For every parsed command, a callback function is called.

Implementation note:
The implementation is based on Boost.Spirit. See the file Parse.ih for the formal language grammar.
Implementation note:
Parsing an arbitrary iostream is not supported since arbitrary streams are not seekable. If this is needed, it can however be provided using stream iterators and some special iterator adaptors from Boost.Spirit. However, the amount of backtracking needs to be analyzed before this is viable.

Definition at line 602 of file Parse.hh.

Member Typedef Documentation

◆ Callback

typedef boost::function<void (ParseCommandInfo const &)> senf::console::CommandParser::Callback

Definition at line 609 of file Parse.hh.

Constructor & Destructor Documentation

◆ CommandParser()

senf::console::CommandParser::CommandParser ( )

Definition at line 309 of file Parse.cc.

◆ ~CommandParser()

senf::console::CommandParser::~CommandParser ( )

Definition at line 313 of file Parse.cc.

Member Function Documentation

◆ isInvalidChar()

bool senf::console::CommandParser::isInvalidChar ( char  ch)
static

Check, if ch is an invalid character.

Definition at line 477 of file Parse.cc.

◆ isPunctuationChar()

bool senf::console::CommandParser::isPunctuationChar ( char  ch)
static

Check, if ch is a punctuation character.

Definition at line 467 of file Parse.cc.

◆ isSpaceChar()

bool senf::console::CommandParser::isSpaceChar ( char  ch)
static

Check, if ch is a space character.

Definition at line 472 of file Parse.cc.

◆ isSpecialChar()

bool senf::console::CommandParser::isSpecialChar ( char  ch)
static

Check, if ch is a special character.

Definition at line 462 of file Parse.cc.

◆ isWordChar()

bool senf::console::CommandParser::isWordChar ( char  ch)
static

Check, if ch is a word character.

Definition at line 482 of file Parse.cc.

◆ parse()

void senf::console::CommandParser::parse ( std::string const &  command,
Callback  cb 
)

Parse string.

Definition at line 364 of file Parse.cc.

◆ parseArguments()

void senf::console::CommandParser::parseArguments ( std::string const &  arguments,
ParseCommandInfo info 
)

Parse arguments.

parseArguments() parses the string arguments which contains arbitrary command arguments (without the name of the command). The argument tokens are written into info.

Definition at line 390 of file Parse.cc.

◆ parseFile()

void senf::console::CommandParser::parseFile ( std::string const &  filename,
Callback  cb 
)

Parse file.

Exceptions
SystemExceptionif the file cannot be read.

Definition at line 369 of file Parse.cc.

◆ parseIncremental()

std::string::size_type senf::console::CommandParser::parseIncremental ( std::string const &  commands,
Callback  cb 
)

Incremental parse.

An incremental parse will parse all complete statements in commands. parseIncremental() will return the number of characters successfully parsed from commands.

Note
The incremental parser requires all statements to be terminated explicitly. This means, that the last ';' is not optional in this case.

Definition at line 452 of file Parse.cc.

◆ parsePath()

void senf::console::CommandParser::parsePath ( std::string const &  path,
ParseCommandInfo info 
)

Parse path.

parsePath() parses the string path as an arbitrary command path. The result is written into info.

Definition at line 414 of file Parse.cc.


The documentation for this class was generated from the following files: