From bf417fadb206d6d2351a13cd7c6988977a46dd33 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 18 Sep 2019 22:37:30 +0200 Subject: Extract pest_consume into its own crate --- dhall_syntax/Cargo.toml | 3 +-- dhall_syntax/src/parser.rs | 62 ++++++++++++++++++++-------------------------- 2 files changed, 28 insertions(+), 37 deletions(-) (limited to 'dhall_syntax') diff --git a/dhall_syntax/Cargo.toml b/dhall_syntax/Cargo.toml index 8d9cca6..b98c4a4 100644 --- a/dhall_syntax/Cargo.toml +++ b/dhall_syntax/Cargo.toml @@ -12,11 +12,10 @@ doctest = false itertools = "0.8.0" percent-encoding = "2.1.0" pest = "2.1" -pest_derive = "2.1" either = "1.5.2" take_mut = "0.2.2" hex = "0.3.2" lazy_static = "1.4.0" dhall_generated_parser = { path = "../dhall_generated_parser" } dhall_proc_macros = { path = "../dhall_proc_macros" } -pest_consume = { path = "../pest_consume" } +pest_consume = "1.0" diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs index 2af2d92..71fab0f 100644 --- a/dhall_syntax/src/parser.rs +++ b/dhall_syntax/src/parser.rs @@ -1,5 +1,4 @@ use itertools::Itertools; -use pest::iterators::Pair; use pest::prec_climber as pcl; use pest::prec_climber::PrecClimber; use std::rc::Rc; @@ -167,7 +166,7 @@ impl DhallParser { fn double_quote_literal( input: ParseInput, ) -> ParseResult> { - Ok(match_nodes!(input.children(); + Ok(match_nodes!(input.into_children(); [double_quote_chunk(chunks)..] => { chunks.collect() } @@ -177,7 +176,7 @@ impl DhallParser { fn double_quote_chunk( input: ParseInput, ) -> ParseResult> { - Ok(match_nodes!(input.children(); + Ok(match_nodes!(input.into_children(); [expression(e)] => { InterpolatedTextContents::Expr(e) }, @@ -264,7 +263,7 @@ impl DhallParser { fn single_quote_literal( input: ParseInput, ) -> ParseResult> { - Ok(match_nodes!(input.children(); + Ok(match_nodes!(input.into_children(); [single_quote_continue(lines)] => { let newline: ParsedText = "\n".to_string().into(); @@ -301,7 +300,7 @@ impl DhallParser { fn single_quote_continue( input: ParseInput, ) -> ParseResult>>> { - Ok(match_nodes!(input.children(); + Ok(match_nodes!(input.into_children(); [expression(e), single_quote_continue(lines)] => { let c = InterpolatedTextContents::Expr(e); let mut lines = lines; @@ -387,21 +386,15 @@ impl DhallParser { #[alias(expression, shortcut = true)] fn identifier(input: ParseInput) -> ParseResult> { Ok(match_nodes!(input.children(); - [variable(v)] => { - spanned(input, Var(v)) - }, + [variable(v)] => spanned(input, Var(v)), [expression(e)] => e, )) } fn variable(input: ParseInput) -> ParseResult> { - Ok(match_nodes!(input.children(); - [label(l), natural_literal(idx)] => { - V(l, idx) - }, - [label(l)] => { - V(l, 0) - }, + Ok(match_nodes!(input.into_children(); + [label(l), natural_literal(idx)] => V(l, idx), + [label(l)] => V(l, 0), )) } @@ -437,7 +430,7 @@ impl DhallParser { .collect()) } fn path(input: ParseInput) -> ParseResult> { - Ok(match_nodes!(input.children(); + Ok(match_nodes!(input.into_children(); [path_component(components)..] => { components.collect() } @@ -448,7 +441,7 @@ impl DhallParser { fn local( input: ParseInput, ) -> ParseResult>> { - Ok(match_nodes!(input.children(); + Ok(match_nodes!(input.into_children(); [local_path((prefix, p))] => ImportLocation::Local(prefix, p), )) } @@ -457,19 +450,19 @@ impl DhallParser { fn parent_path( input: ParseInput, ) -> ParseResult<(FilePrefix, Vec)> { - Ok(match_nodes!(input.children(); + Ok(match_nodes!(input.into_children(); [path(p)] => (FilePrefix::Parent, p) )) } #[alias(local_path)] fn here_path(input: ParseInput) -> ParseResult<(FilePrefix, Vec)> { - Ok(match_nodes!(input.children(); + Ok(match_nodes!(input.into_children(); [path(p)] => (FilePrefix::Here, p) )) } #[alias(local_path)] fn home_path(input: ParseInput) -> ParseResult<(FilePrefix, Vec)> { - Ok(match_nodes!(input.children(); + Ok(match_nodes!(input.into_children(); [path(p)] => (FilePrefix::Home, p) )) } @@ -477,7 +470,7 @@ impl DhallParser { fn absolute_path( input: ParseInput, ) -> ParseResult<(FilePrefix, Vec)> { - Ok(match_nodes!(input.children(); + Ok(match_nodes!(input.into_children(); [path(p)] => (FilePrefix::Absolute, p) )) } @@ -491,7 +484,7 @@ impl DhallParser { } fn http_raw(input: ParseInput) -> ParseResult>> { - Ok(match_nodes!(input.children(); + Ok(match_nodes!(input.into_children(); [scheme(sch), authority(auth), path(p)] => URL { scheme: sch, authority: auth, @@ -521,7 +514,7 @@ impl DhallParser { fn http( input: ParseInput, ) -> ParseResult>> { - Ok(ImportLocation::Remote(match_nodes!(input.children(); + Ok(ImportLocation::Remote(match_nodes!(input.into_children(); [http_raw(url)] => url, [http_raw(url), expression(e)] => URL { headers: Some(e), ..url }, ))) @@ -531,7 +524,7 @@ impl DhallParser { fn env( input: ParseInput, ) -> ParseResult>> { - Ok(match_nodes!(input.children(); + Ok(match_nodes!(input.into_children(); [environment_variable(v)] => ImportLocation::Env(v), )) } @@ -541,7 +534,7 @@ impl DhallParser { } #[alias(environment_variable)] fn posix_environment_variable(input: ParseInput) -> ParseResult { - Ok(match_nodes!(input.children(); + Ok(match_nodes!(input.into_children(); [posix_environment_variable_character(chars)..] => { chars.collect() }, @@ -586,7 +579,7 @@ impl DhallParser { ) -> ParseResult>> { use crate::Import; let mode = ImportMode::Code; - Ok(match_nodes!(input.children(); + Ok(match_nodes!(input.into_children(); [import_type(location)] => Import { mode, location, hash: None }, [import_type(location), hash(h)] => Import { mode, location, hash: Some(h) }, )) @@ -703,9 +696,8 @@ impl DhallParser { #[alias(expression, shortcut = true)] #[prec_climb(expression, PRECCLIMBER)] fn operator_expression( - input: ParseInput, l: Expr, - op: Pair, + op: ParseInput, r: Expr, ) -> ParseResult> { use crate::BinOp::*; @@ -724,7 +716,7 @@ impl DhallParser { bool_eq => BoolEQ, bool_ne => BoolNE, equivalent => Equivalence, - r => Err(input.error(format!("Rule {:?} isn't an operator", r)))?, + r => Err(op.error(format!("Rule {:?} isn't an operator", r)))?, }; Ok(spanned_union( @@ -812,7 +804,7 @@ impl DhallParser { } fn labels(input: ParseInput) -> ParseResult> { - Ok(match_nodes!(input.children(); + Ok(match_nodes!(input.into_children(); [label(ls)..] => ls.collect(), )) } @@ -865,7 +857,7 @@ impl DhallParser { fn non_empty_record_type( input: ParseInput, ) -> ParseResult<(Expr, DupTreeMap>)> { - Ok(match_nodes!(input.children(); + Ok(match_nodes!(input.into_children(); [expression(expr), record_type_entry(entries)..] => { (expr, entries.collect()) } @@ -875,7 +867,7 @@ impl DhallParser { fn record_type_entry( input: ParseInput, ) -> ParseResult<(Label, Expr)> { - Ok(match_nodes!(input.children(); + Ok(match_nodes!(input.into_children(); [label(name), expression(expr)] => (name, expr) )) } @@ -883,7 +875,7 @@ impl DhallParser { fn non_empty_record_literal( input: ParseInput, ) -> ParseResult<(Expr, DupTreeMap>)> { - Ok(match_nodes!(input.children(); + Ok(match_nodes!(input.into_children(); [expression(expr), record_literal_entry(entries)..] => { (expr, entries.collect()) } @@ -893,7 +885,7 @@ impl DhallParser { fn record_literal_entry( input: ParseInput, ) -> ParseResult<(Label, Expr)> { - Ok(match_nodes!(input.children(); + Ok(match_nodes!(input.into_children(); [label(name), expression(expr)] => (name, expr) )) } @@ -934,7 +926,7 @@ impl DhallParser { #[alias(expression)] fn final_expression(input: ParseInput) -> ParseResult> { - Ok(match_nodes!(input.children(); + Ok(match_nodes!(input.into_children(); [expression(e), EOI(_)] => e )) } -- cgit v1.2.3