From 409a2ea78f8a9afa0e2d1569d3996908253b77a0 Mon Sep 17 00:00:00 2001 From: Nick Alexander Date: Fri, 5 May 2017 13:14:37 -0700 Subject: [PATCH] Post: Use choice instead of or. --- tx-parser/src/lib.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tx-parser/src/lib.rs b/tx-parser/src/lib.rs index 2fc8371c..e92ccf35 100644 --- a/tx-parser/src/lib.rs +++ b/tx-parser/src/lib.rs @@ -21,11 +21,13 @@ extern crate mentat_tx; extern crate mentat_parser_utils; use combine::{ + choice, eof, many, parser, satisfy, satisfy_map, + try, Parser, ParseResult, }; @@ -90,10 +92,12 @@ def_parser!(Tx, nested_vector, Vec, { }); def_parser!(Tx, atom_or_lookup_ref_or_vector, AtomOrLookupRefOrVectorOrMapNotation, { - Tx::lookup_ref().map(AtomOrLookupRefOrVectorOrMapNotation::LookupRef) - .or(Tx::nested_vector().map(AtomOrLookupRefOrVectorOrMapNotation::Vector)) - .or(Tx::map_notation().map(AtomOrLookupRefOrVectorOrMapNotation::MapNotation)) - .or(Tx::atom().map(|x| x.clone()).map(AtomOrLookupRefOrVectorOrMapNotation::Atom)) + choice::<[&mut Parser; 4], _> + ([&mut try(Tx::lookup_ref().map(AtomOrLookupRefOrVectorOrMapNotation::LookupRef)), + &mut Tx::nested_vector().map(AtomOrLookupRefOrVectorOrMapNotation::Vector), + &mut Tx::map_notation().map(AtomOrLookupRefOrVectorOrMapNotation::MapNotation), + &mut Tx::atom().map(|x| x.clone()).map(AtomOrLookupRefOrVectorOrMapNotation::Atom) + ]) }); def_matches_namespaced_keyword!(Tx, literal_db_add, "db", "add");