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

'hasOwnProperty' in javascript -

python - ValueError: No axis named 1 for object type <class 'pandas.core.series.Series'> -

java - How to provide dependency injections in Eclipse RCP 3.x? -