Parser base class. Provides methods that are useful to parser subclasses irrespective of how they implemented. More...
#include <MParser.h>
Public Member Functions | |
| MParser (size_t historySize=50) | |
| virtual | ~MParser () |
| virtual int | parse (const mstr &code)=0 |
| virtual int | parse ()=0 |
| virtual int | parseFile (const mstr &path)=0 |
| bool | readLine (const mstr &prompt, mstr &line) |
| mnode | error (mnode n, const mstr &msg, bool warn=false) |
| mnode | func (const mstr &name) const |
| mnode | sym (const mstr &name) const |
| mnode | node (const mvar &v) const |
| int & | status () |
| const mstr & | fileName () const |
| void | setFileName (const mstr &fileName) |
| size_t & | lineNumber () |
| bool | reportErrors () const |
| void | setReportErrors (bool flag) |
| void | setErrorStream (std::ostream &estr) |
Static Public Member Functions | |
| static bool | isEvalFunction (mnode f) |
Parser base class. Provides methods that are useful to parser subclasses irrespective of how they implemented.
Parser implementations are specific to each language, however this class defines a general interface that parser subclasses may find useful and should utilize when possible. Many of the parsing details are left to the implementation, however the general design flow is that an MParser instance parses code from a target language and constructs and emits M code in the form of MNode's.
| Meta::MParser::MParser | ( | size_t | historySize = 50 |
) |
Constructor.
| historySize | For interactive mode, the number of lines of history to maintain. |
| virtual Meta::MParser::~MParser | ( | ) | [virtual] |
Destructor.
Display an error or warning with filename and line number.
| n | The node from which to extract filename and line number. | |
| msg | Error/warning message. | |
| warn | true if this is a warning message and not an error. An error sets status to non-zero while a warning does not. |
| const mstr& Meta::MParser::fileName | ( | ) | const |
Get the current filename of the parser.
Construct a function, setting the parse info to contain the current filename and line number.
| static bool Meta::MParser::isEvalFunction | ( | mnode | f | ) | [static] |
| size_t& Meta::MParser::lineNumber | ( | ) |
Get/modify the current line number of the parser.
Construct a non-symbolic node, setting the parse info to contain the current filename and line number.
| virtual int Meta::MParser::parse | ( | ) | [pure virtual] |
Called to parse interactively.
Implemented in Meta::MLParser, Meta::MMLParser, Meta::MMParser, and Meta::MXMLParser.
| virtual int Meta::MParser::parse | ( | const mstr & | code | ) | [pure virtual] |
Called to parse from a string.
Implemented in Meta::MLParser, Meta::MMLParser, Meta::MMParser, and Meta::MXMLParser.
| virtual int Meta::MParser::parseFile | ( | const mstr & | path | ) | [pure virtual] |
Called to parse a file.
Implemented in Meta::MLParser, Meta::MMLParser, Meta::MMParser, and Meta::MXMLParser.
For interactive parsing, this method reads a line from stdin.
| prompt | The line prompt, e.g: ">>>" | |
| line | On output, the line as read. |
| bool Meta::MParser::reportErrors | ( | ) | const |
| void Meta::MParser::setErrorStream | ( | std::ostream & | estr | ) |
Set the output stream to be used when reporting errors. Default is std::cerr.
| void Meta::MParser::setFileName | ( | const mstr & | fileName | ) |
Set the current filename of the parser.
| void Meta::MParser::setReportErrors | ( | bool | flag | ) |
Set whether to report errors. The default is true.
| int& Meta::MParser::status | ( | ) |
Get/modify the current status of the parser.
Construct a symbol, setting the parse info to contain the current filename and line number.
1.6.1