Meta::MParser Class Reference

Parser base class. Provides methods that are useful to parser subclasses irrespective of how they implemented. More...

#include <MParser.h>

Inheritance diagram for Meta::MParser:
Meta::MEmitter Meta::MLParser Meta::MMLParser Meta::MMParser Meta::MXMLParser

List of all members.

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 mstrfileName () 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)

Detailed Description

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.


Constructor & Destructor Documentation

Meta::MParser::MParser ( size_t  historySize = 50  ) 

Constructor.

Parameters:
historySize For interactive mode, the number of lines of history to maintain.
virtual Meta::MParser::~MParser (  )  [virtual]

Destructor.


Member Function Documentation

mnode Meta::MParser::error ( mnode  n,
const mstr msg,
bool  warn = false 
)

Display an error or warning with filename and line number.

Parameters:
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.
Returns:
The mnode that to be emitted at the error location.
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.

static bool Meta::MParser::isEvalFunction ( mnode  f  )  [static]
Returns:
true if f is an eval-related function, e.g: Eval(), CEval(). Usually code within one of these functions should be left literally as is by the parser.
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.

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.

bool Meta::MParser::readLine ( const mstr prompt,
mstr line 
)

For interactive parsing, this method reads a line from stdin.

Parameters:
prompt The line prompt, e.g: ">>>"
line On output, the line as read.
Returns:
true on success, false on EOF.
bool Meta::MParser::reportErrors (  )  const
Returns:
true if error reporting is enabled.
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.

mnode Meta::MParser::sym ( const mstr name  )  const

Construct a symbol, setting the parse info to contain the current filename and line number.


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

Generated on Wed Mar 24 16:22:43 2010 for AndroMeta by  doxygen 1.6.1