kevinmehall / rust-peg

Parsing Expression Grammar (PEG) parser generator for Rust
https://crates.io/crates/peg
MIT License
1.44k stars 105 forks source link

How do I escape the dot character in [^ pat]? #351

Closed mcandre closed 1 year ago

mcandre commented 1 year ago

I want to conduct a (negated) match pattern that specifically excludes periods. But I do not see the syntax for how to accomplish this.

I tried [^ '.'], but that appears to expand the period to mean any symbol. Instead of a literal dot.

I also tried !("."), but in my context, peg complains that this would result in an infinite loop.

What is the right syntax for escaping a dot character in peg patterns?

kevinmehall commented 1 year ago

[^ '.'] is correct. This is a Rust pattern as would go in a match arm, not a regex.

!(".") will accept the empty string whenever the next character is not a dot, so (!("."))* would infinite-loop since the inside of the loop doesn't consume anything and matches in the same place repeatedly.