Skip to content

Commit

Permalink
Remove provision for inverted pattern expr
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinmehall committed Jan 2, 2021
1 parent 998cf96 commit afa6ee9
Showing 1 changed file with 3 additions and 23 deletions.
26 changes: 3 additions & 23 deletions peg-macros/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,6 @@ fn labeled_seq(context: &Context, exprs: &[TaggedExpr], inner: TokenStream) -> T
})
}

fn cond_swap<T>(swap: bool, tup: (T, T)) -> (T, T) {
let (a, b) = tup;
if swap {
(b, a)
} else {
(a, b)
}
}

fn compile_expr(context: &Context, e: &Expr, result_used: bool) -> TokenStream {
match e {
LiteralExpr(ref s) => {
Expand All @@ -352,24 +343,13 @@ fn compile_expr(context: &Context, e: &Expr, result_used: bool) -> TokenStream {
}

PatternExpr(ref pattern) => {
let invert = false;
let pat_str = pattern.to_string();

let (in_set, not_in_set) = cond_swap(
invert,
(
quote! { ::peg::RuleResult::Matched(__next, ()) },
quote! { __err_state.mark_failure(__pos, #pat_str) },
),
);

let in_set_arm = quote!( #pattern => #in_set, );

quote! {
quote!{
match ::peg::ParseElem::parse_elem(__input, __pos) {
::peg::RuleResult::Matched(__next, __ch) => match __ch {
#in_set_arm
_ => #not_in_set,
#pattern => ::peg::RuleResult::Matched(__next, ()),
_ => __err_state.mark_failure(__pos, #pat_str) ,
}
::peg::RuleResult::Failed => __err_state.mark_failure(__pos, #pat_str)
}
Expand Down

0 comments on commit afa6ee9

Please sign in to comment.