Struct cexpr::expr::IdentifierParser [] [src]

pub struct IdentifierParser<'ident> {
    // some fields omitted
}

Expression parser/evaluator that supports identifiers.

Methods

impl<'ident> IdentifierParser<'ident>
[src]

fn new(identifiers: &HashMap<Vec<u8>, EvalResult>) -> IdentifierParser

Create a new IdentifierParser with a set of known identifiers. When a known identifier is encountered during parsing, it is substituted for the value specified.

fn expr<'a>(&self, input: &'a [Token]) -> CResult<'a, EvalResult>

Parse and evalute an expression of a list of tokens.

Returns an error if the input is not a valid expression or if the token stream contains comments, keywords or unknown identifiers.

fn macro_definition<'a>(&self, input: &'a [Token]) -> CResult<'a, (&'a [u8], EvalResult)>

Parse and evaluate a macro definition from of a list of tokens.

Returns the identifier for the macro and its replacement evaluated as an expression. The input should not include #define.

Returns an error if the replacement is not a valid expression, if called on most function-like macros, or if the token stream contains comments, keywords or unknown identifiers.

N.B. This is intended to fail on function-like macros, but if it the macro takes a single argument, the argument name is defined as an identifier, and the macro otherwise parses as an expression, it will return a result even on function-like macros.

// will evaluate into IDENTIFIER
#define DELETE(IDENTIFIER)
// will evaluate into IDENTIFIER-3
#define NEGATIVE_THREE(IDENTIFIER)  -3

Trait Implementations

impl<'ident> Debug for IdentifierParser<'ident>
[src]

fn fmt(&self, __arg_0: &mut Formatter) -> Result

Formats the value using the given formatter.