parse_with_context

Function parse_with_context 

Source
pub fn parse_with_context(
    ctx: &Context,
    input: &str,
    notation: Notation,
) -> Result<Term, ParseError>
Expand description

Attempts to parse the input &str using a provided context of free variables.

This function is identical to parse(), but it allows defining a set of named free variables that are considered valid during parsing in Classic notation.

§Examples

use lambda_calculus::{*, term::Context};

let ctx = Context::new(&["x", "y"]);

// `z` is not in the context, so it will be an error.
assert!(parse_with_context(&ctx, "z", Classic).is_err());

// `y` is in the context, so it's parsed as the outermost free variable (Var(2)).
assert_eq!(parse_with_context(&ctx, "y", Classic), Ok(Var(2)));

// In `λa.y`, `y` is still the outermost free variable, but its index is now 3.
assert_eq!(parse_with_context(&ctx, "λa.y", Classic), Ok(abs(Var(3))));

§Errors

Returns a ParseError when a lexing or syntax error is encountered.