2017-04-07 36 views

回答

5

你可以找到https://docs.rs/pest/0.4.1/pest/macro.grammar.html#syntax害蟲語法,尤其是有「負前瞻」

!a - 如果a匹配不匹配不進取

所以,你可以寫

!["/"] ~ any 

例如:

// cargo-deps: pest 

#[macro_use] extern crate pest; 
use pest::*; 

fn main() { 
    impl_rdp! { 
     grammar! { 
      path = @{ soi ~ (["/"] ~ component)+ ~ eoi } 
      component = @{ (!["/"] ~ any)+ } 
     } 
    } 

    println!("should be true: {}", Rdp::new(StringInput::new("/bcc/cc/v")).path()); 
    println!("should be false: {}", Rdp::new(StringInput::new("/bcc/cc//v")).path()); 
} 
相關問題