parsing - Parser expression grammar - how to match any string excluding a single character? -


i'd write peg matches filesystem paths. path element character except / in posix linux.

there expression in peg match any character, cannot figure out how match character except one.

the peg parser i'm using pest rust.

you find pest syntax in https://docs.rs/pest/0.4.1/pest/macro.grammar.html#syntax, in particular there "negative lookahead"

!a — matches if a doesn't match without making progress

so write

!["/"] ~ 

example:

// cargo-deps: pest  #[macro_use] extern crate pest; use pest::*;  fn main() {     impl_rdp! {         grammar! {             path = @{ soi ~ (["/"] ~ component)+ ~ eoi }             component = @{ (!["/"] ~ any)+ }         }     }      println!("should true: {}", rdp::new(stringinput::new("/bcc/cc/v")).path());     println!("should false: {}", rdp::new(stringinput::new("/bcc/cc//v")).path()); } 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -