Function lambda_calculus::parser::parse

source ·
pub fn parse(input: &str, notation: Notation) -> Result<Term, ParseError>
Expand description

Attempts to parse the input &str as a lambda Term encoded in the given Notation.

  • lambdas can be represented either with the greek letter (λ) or a backslash (\ - less aesthetic, but only one byte in size)
  • the identifiers in Classic notation are Strings of alphabetic Unicode characters
  • Classic notation ignores whitespaces where unambiguous
  • the indices in the DeBruijn notation start with 1 and are hexadecimal digits
  • DeBruijn notation ignores all whitespaces (since indices > 15 are very unlikely)

Examples

use lambda_calculus::*;
use lambda_calculus::combinators::{S, Y};

assert_eq!(parse(&"λf.(λx.f (x x)) (λx.f (x x))", Classic), Ok(Y()));
assert_eq!(parse(&"λƒ.(λℵ.ƒ(ℵ ℵ))(λℵ.ƒ(ℵ ℵ))", Classic),  Ok(Y()));

assert_eq!(parse(  &"λλλ31(21)",     DeBruijn), Ok(S()));
assert_eq!(parse(&r#"\\\3 1 (2 1)"#, DeBruijn), Ok(S()));

Errors

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