feat: add error and builtin to term function

and add between parse
This commit is contained in:
Kasey White 2022-05-09 02:50:51 -04:00
parent 6b2601c40b
commit bbc1b25ab7
1 changed files with 20 additions and 10 deletions

View File

@ -64,6 +64,8 @@ where
attempt(apply()), attempt(apply()),
attempt(constant()), attempt(constant()),
attempt(force()), attempt(force()),
attempt(error()),
attempt(builtin()),
)) ))
} }
@ -143,12 +145,16 @@ where
Input: Stream<Token = char>, Input: Stream<Token = char>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>, Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{ {
between(
token('('),
token(')'),
string("builtin") string("builtin")
.with(skip_many1(space())) .with(skip_many1(space()))
.with(many1(alpha_num())) .with(many1(alpha_num()))
.map(|builtin_name: String| { .map(|builtin_name: String| {
Term::Builtin(DefaultFunction::from_str(&builtin_name).unwrap()) Term::Builtin(DefaultFunction::from_str(&builtin_name).unwrap())
}) }),
)
} }
pub fn error<Input>() -> impl Parser<Input, Output = Term> pub fn error<Input>() -> impl Parser<Input, Output = Term>
@ -156,10 +162,14 @@ where
Input: Stream<Token = char>, Input: Stream<Token = char>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>, Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{ {
between(
token('('),
token(')'),
string("error") string("error")
.with(skip_many1(space())) .with(skip_many1(space()))
.with(term_()) .with(term_())
.map(|term| Term::Error(Box::new(term))) .map(|term| Term::Error(Box::new(term))),
)
} }
pub fn constant<Input>() -> impl Parser<Input, Output = Term> pub fn constant<Input>() -> impl Parser<Input, Output = Term>