diff options
Diffstat (limited to '')
-rw-r--r-- | dhall_syntax/src/parser.rs | 76 | ||||
-rw-r--r-- | pest_consume/examples/csv/main.rs | 10 | ||||
-rw-r--r-- | pest_consume/src/lib.rs | 2 | ||||
-rw-r--r-- | pest_consume_macros/src/lib.rs | 6 | ||||
-rw-r--r-- | pest_consume_macros/src/match_nodes.rs (renamed from pest_consume_macros/src/match_inputs.rs) | 2 |
5 files changed, 48 insertions, 48 deletions
diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs index d945435..c0b9712 100644 --- a/dhall_syntax/src/parser.rs +++ b/dhall_syntax/src/parser.rs @@ -6,7 +6,7 @@ use std::rc::Rc; use dgp::Rule; use dhall_generated_parser as dgp; -use pest_consume::{match_inputs, Parser}; +use pest_consume::{match_nodes, Parser}; use crate::map::{DupTreeMap, DupTreeSet}; use crate::ExprF::*; @@ -167,7 +167,7 @@ impl DhallParser { fn double_quote_literal<E: Clone>( input: ParseInput, ) -> ParseResult<ParsedText<E>> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [double_quote_chunk(chunks)..] => { chunks.collect() } @@ -177,7 +177,7 @@ impl DhallParser { fn double_quote_chunk<E: Clone>( input: ParseInput, ) -> ParseResult<ParsedTextContents<E>> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [expression(e)] => { InterpolatedTextContents::Expr(e) }, @@ -264,7 +264,7 @@ impl DhallParser { fn single_quote_literal<E: Clone>( input: ParseInput, ) -> ParseResult<ParsedText<E>> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [single_quote_continue(lines)] => { let newline: ParsedText<E> = "\n".to_string().into(); @@ -303,7 +303,7 @@ impl DhallParser { fn single_quote_continue<E: Clone>( input: ParseInput, ) -> ParseResult<Vec<Vec<ParsedTextContents<E>>>> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [expression(e), single_quote_continue(lines)] => { let c = InterpolatedTextContents::Expr(e); let mut lines = lines; @@ -388,7 +388,7 @@ impl DhallParser { #[alias(expression, shortcut = true)] fn identifier<E: Clone>(input: ParseInput) -> ParseResult<Expr<E>> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [variable(v)] => { spanned(input, Var(v)) }, @@ -397,7 +397,7 @@ impl DhallParser { } fn variable(input: ParseInput) -> ParseResult<V<Label>> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [label(l), natural_literal(idx)] => { V(l, idx) }, @@ -439,7 +439,7 @@ impl DhallParser { .collect()) } fn path(input: ParseInput) -> ParseResult<Vec<String>> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [path_component(components)..] => { components.collect() } @@ -450,7 +450,7 @@ impl DhallParser { fn local<E: Clone>( input: ParseInput, ) -> ParseResult<ImportLocation<Expr<E>>> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [local_path((prefix, p))] => ImportLocation::Local(prefix, p), )) } @@ -459,19 +459,19 @@ impl DhallParser { fn parent_path( input: ParseInput, ) -> ParseResult<(FilePrefix, Vec<String>)> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [path(p)] => (FilePrefix::Parent, p) )) } #[alias(local_path)] fn here_path(input: ParseInput) -> ParseResult<(FilePrefix, Vec<String>)> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [path(p)] => (FilePrefix::Here, p) )) } #[alias(local_path)] fn home_path(input: ParseInput) -> ParseResult<(FilePrefix, Vec<String>)> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [path(p)] => (FilePrefix::Home, p) )) } @@ -479,7 +479,7 @@ impl DhallParser { fn absolute_path( input: ParseInput, ) -> ParseResult<(FilePrefix, Vec<String>)> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [path(p)] => (FilePrefix::Absolute, p) )) } @@ -493,7 +493,7 @@ impl DhallParser { } fn http_raw<E: Clone>(input: ParseInput) -> ParseResult<URL<Expr<E>>> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [scheme(sch), authority(auth), path(p)] => URL { scheme: sch, authority: auth, @@ -523,7 +523,7 @@ impl DhallParser { fn http<E: Clone>( input: ParseInput, ) -> ParseResult<ImportLocation<Expr<E>>> { - Ok(ImportLocation::Remote(match_inputs!(input.children(); + Ok(ImportLocation::Remote(match_nodes!(input.children(); [http_raw(url)] => url, [http_raw(url), expression(e)] => URL { headers: Some(e), ..url }, ))) @@ -533,7 +533,7 @@ impl DhallParser { fn env<E: Clone>( input: ParseInput, ) -> ParseResult<ImportLocation<Expr<E>>> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [environment_variable(v)] => ImportLocation::Env(v), )) } @@ -543,7 +543,7 @@ impl DhallParser { } #[alias(environment_variable)] fn posix_environment_variable(input: ParseInput) -> ParseResult<String> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [posix_environment_variable_character(chars)..] => { chars.collect() }, @@ -588,7 +588,7 @@ impl DhallParser { ) -> ParseResult<crate::Import<Expr<E>>> { use crate::Import; let mode = ImportMode::Code; - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [import_type(location)] => Import { mode, location, hash: None }, [import_type(location), hash(h)] => Import { mode, location, hash: Some(h) }, )) @@ -606,7 +606,7 @@ impl DhallParser { #[alias(expression)] fn import<E: Clone>(input: ParseInput) -> ParseResult<Expr<E>> { use crate::Import; - let import = match_inputs!(input.children(); + let import = match_nodes!(input.children(); [import_hashed(imp)] => { Import { mode: ImportMode::Code, ..imp } }, @@ -641,13 +641,13 @@ impl DhallParser { #[alias(expression)] fn empty_list_literal<E: Clone>(input: ParseInput) -> ParseResult<Expr<E>> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [expression(e)] => spanned(input, EmptyListLit(e)), )) } fn expression<E: Clone>(input: ParseInput) -> ParseResult<Expr<E>> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [lambda(()), label(l), expression(typ), arrow(()), expression(body)] => { spanned(input, Lam(l, typ, body)) @@ -694,7 +694,7 @@ impl DhallParser { fn let_binding<E: Clone>( input: ParseInput, ) -> ParseResult<(Label, Option<Expr<E>>, Expr<E>, Span)> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [label(name), expression(annot), expression(expr)] => (name, Some(annot), expr, input_to_span(input)), [label(name), expression(expr)] => @@ -744,7 +744,7 @@ impl DhallParser { fn application_expression<E: Clone>( input: ParseInput, ) -> ParseResult<Expr<E>> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [expression(e)] => e, [expression(first), expression(rest)..] => { rest.fold( @@ -765,7 +765,7 @@ impl DhallParser { fn first_application_expression<E: Clone>( input: ParseInput, ) -> ParseResult<Expr<E>> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [Some_(()), expression(e)] => { spanned(input, SomeLit(e)) }, @@ -783,7 +783,7 @@ impl DhallParser { fn selector_expression<E: Clone>( input: ParseInput, ) -> ParseResult<Expr<E>> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [expression(e)] => e, [expression(first), selector(rest)..] => { rest.fold( @@ -806,7 +806,7 @@ impl DhallParser { fn selector( input: ParseInput, ) -> ParseResult<(Either<Label, DupTreeSet<Label>>, Span)> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [label(l)] => (Either::Left(l), input_to_span(input)), [labels(ls)] => (Either::Right(ls), input_to_span(input)), // [expression(_e)] => unimplemented!("selection by expression"), // TODO @@ -814,7 +814,7 @@ impl DhallParser { } fn labels(input: ParseInput) -> ParseResult<DupTreeSet<Label>> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [label(ls)..] => ls.collect(), )) } @@ -823,7 +823,7 @@ impl DhallParser { fn primitive_expression<E: Clone>( input: ParseInput, ) -> ParseResult<Expr<E>> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [double_literal(n)] => spanned(input, DoubleLit(n)), [natural_literal(n)] => spanned(input, NaturalLit(n)), [integer_literal(n)] => spanned(input, IntegerLit(n)), @@ -849,7 +849,7 @@ impl DhallParser { fn non_empty_record_type_or_literal<E: Clone>( input: ParseInput, ) -> ParseResult<Expr<E>> { - let e = match_inputs!(input.children(); + let e = match_nodes!(input.children(); [label(first_label), non_empty_record_type(rest)] => { let (first_expr, mut map) = rest; map.insert(first_label, first_expr); @@ -867,7 +867,7 @@ impl DhallParser { fn non_empty_record_type<E: Clone>( input: ParseInput, ) -> ParseResult<(Expr<E>, DupTreeMap<Label, Expr<E>>)> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [expression(expr), record_type_entry(entries)..] => { (expr, entries.collect()) } @@ -877,7 +877,7 @@ impl DhallParser { fn record_type_entry<E: Clone>( input: ParseInput, ) -> ParseResult<(Label, Expr<E>)> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [label(name), expression(expr)] => (name, expr) )) } @@ -885,7 +885,7 @@ impl DhallParser { fn non_empty_record_literal<E: Clone>( input: ParseInput, ) -> ParseResult<(Expr<E>, DupTreeMap<Label, Expr<E>>)> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [expression(expr), record_literal_entry(entries)..] => { (expr, entries.collect()) } @@ -895,14 +895,14 @@ impl DhallParser { fn record_literal_entry<E: Clone>( input: ParseInput, ) -> ParseResult<(Label, Expr<E>)> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [label(name), expression(expr)] => (name, expr) )) } #[alias(expression)] fn union_type<E: Clone>(input: ParseInput) -> ParseResult<Expr<E>> { - let map = match_inputs!(input.children(); + let map = match_nodes!(input.children(); [empty_union_type(_)] => Default::default(), [union_type_entry(entries)..] => entries.collect(), ); @@ -916,7 +916,7 @@ impl DhallParser { fn union_type_entry<E: Clone>( input: ParseInput, ) -> ParseResult<(Label, Option<Expr<E>>)> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [label(name), expression(expr)] => (name, Some(expr)), [label(name)] => (name, None), )) @@ -926,7 +926,7 @@ impl DhallParser { fn non_empty_list_literal<E: Clone>( input: ParseInput, ) -> ParseResult<Expr<E>> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [expression(items)..] => spanned( input, NEListLit(items.collect()) @@ -936,7 +936,7 @@ impl DhallParser { #[alias(expression)] fn final_expression<E: Clone>(input: ParseInput) -> ParseResult<Expr<E>> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [expression(e), EOI(_)] => e )) } @@ -949,7 +949,7 @@ pub fn parse_expr<E: Clone>(input_str: &str) -> ParseResult<Expr<E>> { input_str, rc_input_str, )?; - Ok(match_inputs!(<DhallParser>; inputs; + Ok(match_nodes!(<DhallParser>; inputs; [expression(e)] => e, )) } diff --git a/pest_consume/examples/csv/main.rs b/pest_consume/examples/csv/main.rs index 037948b..bb9f8fc 100644 --- a/pest_consume/examples/csv/main.rs +++ b/pest_consume/examples/csv/main.rs @@ -1,5 +1,5 @@ #![feature(slice_patterns)] -use pest_consume::{match_inputs, Parser}; +use pest_consume::{match_nodes, Parser}; #[derive(pest_derive::Parser)] #[grammar = "../examples/csv/csv.pest"] @@ -32,20 +32,20 @@ impl CSVParser { } fn field(input: Node) -> ParseResult<CSVField> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [number(n)] => CSVField::Number(n), [string(s)] => CSVField::String(s), )) } fn record(input: Node) -> ParseResult<CSVRecord> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [field(fields)..] => fields.collect(), )) } fn file(input: Node) -> ParseResult<CSVFile> { - Ok(match_inputs!(input.children(); + Ok(match_nodes!(input.children(); [record(records).., EOI(_)] => records.collect(), )) } @@ -53,7 +53,7 @@ impl CSVParser { fn parse_csv(input_str: &str) -> ParseResult<CSVFile> { let inputs = CSVParser::parse(Rule::file, input_str)?; - Ok(match_inputs!(<CSVParser>; inputs; + Ok(match_nodes!(<CSVParser>; inputs; [file(e)] => e, )) } diff --git a/pest_consume/src/lib.rs b/pest_consume/src/lib.rs index f14f6f5..319810a 100644 --- a/pest_consume/src/lib.rs +++ b/pest_consume/src/lib.rs @@ -7,7 +7,7 @@ use pest::Parser as PestParser; use pest::RuleType; #[proc_macro_hack::proc_macro_hack] -pub use pest_consume_macros::match_inputs; +pub use pest_consume_macros::match_nodes; pub use pest_consume_macros::parser; mod node { diff --git a/pest_consume_macros/src/lib.rs b/pest_consume_macros/src/lib.rs index 7f9f464..d726b5d 100644 --- a/pest_consume_macros/src/lib.rs +++ b/pest_consume_macros/src/lib.rs @@ -6,7 +6,7 @@ extern crate proc_macro; mod make_parser; -mod match_inputs; +mod match_nodes; use proc_macro::TokenStream; @@ -19,8 +19,8 @@ pub fn parser(attrs: TokenStream, input: TokenStream) -> TokenStream { } #[proc_macro_hack::proc_macro_hack] -pub fn match_inputs(input: TokenStream) -> TokenStream { - TokenStream::from(match match_inputs::match_inputs(input) { +pub fn match_nodes(input: TokenStream) -> TokenStream { + TokenStream::from(match match_nodes::match_nodes(input) { Ok(tokens) => tokens, Err(err) => err.to_compile_error(), }) diff --git a/pest_consume_macros/src/match_inputs.rs b/pest_consume_macros/src/match_nodes.rs index 773f806..251b7ef 100644 --- a/pest_consume_macros/src/match_inputs.rs +++ b/pest_consume_macros/src/match_nodes.rs @@ -186,7 +186,7 @@ fn make_parser_branch( )) } -pub fn match_inputs( +pub fn match_nodes( input: proc_macro::TokenStream, ) -> Result<proc_macro2::TokenStream> { let input: ParseChildrenInput = syn::parse(input)?; |