summaryrefslogtreecommitdiff
path: root/dhall
diff options
context:
space:
mode:
authorNadrieril2019-09-10 14:21:09 +0200
committerNadrieril2019-09-10 14:21:27 +0200
commit9f3ada020ee7af61b80be24c0fb2f9a0b0a5a0bd (patch)
tree692d8b64af083bf54a3269f60faab8e6884b6258 /dhall
parent7e9c8d5fbb1c6536012207073931b3db09345fad (diff)
Use match_inputs for parser entrypoint
Diffstat (limited to '')
-rw-r--r--dhall_syntax/src/parser.rs20
1 files changed, 13 insertions, 7 deletions
diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs
index 761795a..15515f0 100644
--- a/dhall_syntax/src/parser.rs
+++ b/dhall_syntax/src/parser.rs
@@ -21,6 +21,8 @@ type ParsedText<E> = InterpolatedText<Expr<E>>;
type ParsedTextContents<E> = InterpolatedTextContents<Expr<E>>;
type ParseInput<'input, 'data> =
pest_consume::ParseInput<'input, 'data, Rule, Rc<str>>;
+type ParseInputs<'input, 'data> =
+ pest_consume::ParseInputs<'input, 'data, Rule, Rc<str>>;
pub type ParseError = pest::error::Error<Rule>;
pub type ParseResult<T> = Result<T, ParseError>;
@@ -152,6 +154,15 @@ struct Parsers;
#[make_parser(Rule)]
impl Parsers {
+ fn entrypoint<E: Clone>(input_str: &str) -> ParseResult<Expr<E>> {
+ let pairs = DhallParser::parse(Rule::final_expression, input_str)?;
+ let rc_input_str = input_str.to_string().into();
+ let inputs = ParseInputs::new(input_str, pairs, &rc_input_str);
+ Ok(match_inputs!(inputs;
+ [expression(e)] => e,
+ ))
+ }
+
fn EOI(_input: ParseInput) -> ParseResult<()> {
Ok(())
}
@@ -939,6 +950,7 @@ impl Parsers {
))
}
+ #[alias(expression)]
fn final_expression<E: Clone>(input: ParseInput) -> ParseResult<Expr<E>> {
Ok(match_inputs!(input.children();
[expression(e), EOI(_)] => e
@@ -947,11 +959,5 @@ impl Parsers {
}
pub fn parse_expr<E: Clone>(input_str: &str) -> ParseResult<Expr<E>> {
- let mut pairs = DhallParser::parse(Rule::final_expression, input_str)?;
- // TODO: proper errors
- let pair = pairs.next().unwrap();
- assert_eq!(pairs.next(), None);
- let rc_input_str = input_str.to_string().into();
- let input = ParseInput::new(pair, &rc_input_str);
- Parsers::final_expression(input)
+ Parsers::entrypoint(input_str)
}