#include <source/toolbox/inputdb/Parser.h>
Public Member Functions | |
Parser () | |
~Parser () | |
int | parse (const std::string &filename, FILE *fstream, Pointer< Database > database) |
int | getNumberErrors () const |
int | getNumberWarnings () const |
Pointer< Database > & | getScope () |
void | enterScope (const std::string &name) |
void | leaveScope () |
Pointer< Database > | getDatabaseWithKey (const std::string &name) |
bool | pushIncludeFile (const std::string &filename) |
void | popIncludeFile () |
void | error (const std::string &message) |
void | warning (const std::string &message) |
void | setLine (const std::string &line) |
void | advanceLine (const int nline=1) |
void | advanceCursor (const std::string &token) |
int | yyinput (char *buffer, const int max_size) |
Static Public Member Functions | |
static Parser * | getParser () |
The parser class also defines a ``default'' parser that may be accessed via a static member function. The default parser may only be accessed by the yacc/lex routines called during the input file parsing. This singleton-like approach provides a clean way to communicate parser information to the yacc/lex files without global variables.
This parser (and the associated yacc and lex files) assume the GNU flex and bison utilities. These utilities are only required if the grammar or scanner is changed, since the SAMRAI distribution already contains the output files from flex and bison.
SAMRAI::tbox::Parser::Parser | ( | ) |
The parser constructor simply creates an uninitialized parser object. Member function parse() must be called before any other member function to initialize the object and parse the input data. Function parse() may be called multiple times to parse multiple input files, but all state values (such as the number of errors or warnings) are reset at the beginning of each new parse pass.
SAMRAI::tbox::Parser::~Parser | ( | ) |
Destroy the parser object and deallocate parser data.
int SAMRAI::tbox::Parser::parse | ( | const std::string & | filename, | |
FILE * | fstream, | |||
Pointer< Database > | database | |||
) |
Parse the input file from the specified file stream. The number of syntax errors is returned. A successful parse will return zero errors. The parse() function takes the initial filename (for informational purposes) and the filestream from which to read the parse data. All (key,value) pairs are placed in the specified database. If running in parallel, the fstream must be valid on node zero, but is ignored on other nodes and may be set to NULL. Multiple input files may be parsed by calling parse() for each file, but all variables are reset at the beginning of each parse.
int SAMRAI::tbox::Parser::getNumberErrors | ( | ) | const [inline] |
Return the total number of errors resulting from the parse.
int SAMRAI::tbox::Parser::getNumberWarnings | ( | ) | const [inline] |
Return the total number of warnings resulting from the parse.
Parser * SAMRAI::tbox::Parser::getParser | ( | ) | [inline, static] |
Return the parser object. This mechanism is useful for communicating with the yacc/lex routines during the input file parse. The default parser will be NULL outside of the parse call.
Return the current database scope. The current scope is modified through the enterScope() and leaveScope() member functions.
void SAMRAI::tbox::Parser::enterScope | ( | const std::string & | name | ) | [inline] |
Create a new database scope with the specified name. This new scope will be the default scope until leaveScope() is called.
void SAMRAI::tbox::Parser::leaveScope | ( | ) | [inline] |
Leave the current database scope and return to the previous scope. It is an error to leave the outermost scope.
Lookup the scope that contains the specified key. If the scope does not exist, then return a NULL pointer to the database.
bool SAMRAI::tbox::Parser::pushIncludeFile | ( | const std::string & | filename | ) |
Save the current context and switch to the specified input file. This routine returns true if the file exists and the switch was successful and false otherwise.
void SAMRAI::tbox::Parser::popIncludeFile | ( | ) |
Pop the include file context off of the stack and return to the previous include file.
void SAMRAI::tbox::Parser::error | ( | const std::string & | message | ) |
Report a parsing error with the specified error message. This routine will only be called from the parser or the scanner. Errors are printed to pout, since it is assumed that all nodes are parsing the same input file.
void SAMRAI::tbox::Parser::warning | ( | const std::string & | message | ) |
Report a parsing warning with the specified warning message. This routine will only be called from the parser or the scanner. Errors are printed to pout, since it is assumed that all nodes are parsing the same input file.
void SAMRAI::tbox::Parser::setLine | ( | const std::string & | line | ) |
Set the input line which is currently being parsed.
void SAMRAI::tbox::Parser::advanceLine | ( | const int | nline = 1 |
) |
Advance the line number by the specified number of lines. If no argument is given, then the line number is advanced by one line.
void SAMRAI::tbox::Parser::advanceCursor | ( | const std::string & | token | ) |
Advance the position of the cursor on the line using the values in the specified character string. Tab characters in the string are assumed to advance the cursor to eight character tab stops. The cursor position is automatically reset to one whenever the line number is changed.
int SAMRAI::tbox::Parser::yyinput | ( | char * | buffer, | |
const int | max_size | |||
) |
Define the input reading routine used by flex. Under MPI, node zero reads the input and broadcasts the character data to all processors.