|
AndroMeta
2.0.0
|
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 () |
| bool | readLine (const mstr &prompt, mstr &line) |
| mnode | error (mnode n, const mstr &msg, bool warn=false, const mstr &type="") |
| 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 () |
| size_t & | character () |
| int & | tokenId () |
| bool | reportErrors () const |
| void | setReportErrors (bool flag) |
| void | submitError (const mvar &error) |
| const mvec & | errors () const |
| void | clearErrors () |
| void | setErrorStream (std::ostream &estr) |
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.
| size_t& Meta::MParser::character | ( | ) |
Get/modify the current character index of the parser.
| void Meta::MParser::clearErrors | ( | ) |
Clear errors.
| mnode Meta::MParser::error | ( | mnode | n, |
| const mstr & | msg, | ||
| bool | warn = false, |
||
| const mstr & | type = "" |
||
| ) |
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. |
type A type string, e.g: "parse", "semantic", can be anything, and if non-empty an error message is inserted into the errors vec.
| const mvec& Meta::MParser::errors | ( | ) | const |
Return errors.
| const mstr& Meta::MParser::fileName | ( | ) | const |
Get the current filename of the parser.
| mnode Meta::MParser::func | ( | const mstr & | name | ) | const |
Construct a function, setting the parse info to contain the current filename and line number.
| size_t& Meta::MParser::lineNumber | ( | ) |
Get/modify the current line number of the parser.
| mnode Meta::MParser::node | ( | const mvar & | v | ) | const |
Construct a non-symbolic node, setting the parse info to contain the current filename and line number.
| bool Meta::MParser::readLine | ( | const mstr & | prompt, |
| mstr & | line | ||
| ) |
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.
| void Meta::MParser::submitError | ( | const mvar & | error | ) |
Submit an error.
| mnode Meta::MParser::sym | ( | const mstr & | name | ) | const |
Construct a symbol, setting the parse info to contain the current filename and line number.
| int& Meta::MParser::tokenId | ( | ) |
Get/modify the current token id of the parser.
1.7.6.1