Skip to content

Commit

Permalink
doc: explain that matching is greedy without backtracking (#744)
Browse files Browse the repository at this point in the history
Example borrowed and adapted from #742
  • Loading branch information
birkenfeld committed Nov 29, 2022
1 parent 15c96e7 commit ca11433
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions derive/src/lib.rs
Expand Up @@ -184,6 +184,19 @@
//!
//! where `e`, `e1`, and `e2` are expressions.
//!
//! Matching is greedy, without backtracking. Note the difference in behavior for
//! these two rules in matching identifiers that don't end in an underscore:
//!
//! ```ignore
//! // input: ab_bb_b
//!
//! identifier = @{ "a" ~ ("b"|"_")* ~ "b" }
//! // matches: a b_bb_b nothing -> error!
//!
//! identifier = @{ "a" ~ ("_"* ~ "b")* }
//! // matches: a b, _bb, _b in three repetitions
//! ```
//!
//! Expressions can modify the stack only if they match the input. For example,
//! if `e1` in the compound expression `e1 | e2` does not match the input, then
//! it does not modify the stack, so `e2` sees the stack in the same state as
Expand Down
13 changes: 13 additions & 0 deletions pest/src/lib.rs
Expand Up @@ -197,6 +197,19 @@
//!
//! where `e`, `e1`, and `e2` are expressions.
//!
//! Matching is greedy, without backtracking. Note the difference in behavior for
//! these two rules in matching identifiers that don't end in an underscore:
//!
//! ```ignore
//! // input: ab_bb_b
//!
//! identifier = @{ "a" ~ ("b"|"_")* ~ "b" }
//! // matches: a b_bb_b nothing -> error!
//!
//! identifier = @{ "a" ~ ("_"* ~ "b")* }
//! // matches: a b, _bb, _b in three repetitions
//! ```
//!
//! Expressions can modify the stack only if they match the input. For example,
//! if `e1` in the compound expression `e1 | e2` does not match the input, then
//! it does not modify the stack, so `e2` sees the stack in the same state as
Expand Down

0 comments on commit ca11433

Please sign in to comment.