Function lambda_calculus::parser::parse
[−]
[src]
pub fn parse(input: &str, notation: Notation) -> Result<Term, ParseError>
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 areString
s of ASCII alphabetic 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(&"λf.(λx.f(x x))(λx.f(x x))", 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.