rust-peg icon indicating copy to clipboard operation
rust-peg copied to clipboard

More concise character set syntax (like version 0.5)

Open jocutajar opened this issue 4 years ago • 0 comments

Hi Kevin, In the move to 0.6 we've lost a substantial amount of eyecandy and readability. I appreciate that the redesign must have simplified many things in your code, or even improved performance. I'm struggling with the new syntax though.


        rule char_regular() -> u8
            = b:$(quiet!{[b'-' | b'!' | b'#' | b'$' | b'%' | b'&' |
                b'\'' | b'*' | b'+' | b'-' | b'`' | b'/' |
                    b'0'..=b'9' | b'a'..=b'z' | b'A'..=b'Z' |
                    b'=' | b'?' | b'~' | b'^' | b'_' | b'{' | b'}' | b'|' | 0x80..=0xFF
            ]} / expected!("regular character"))
            {debug_assert!(b.len()==1); b[0]}

I don't remember exactly, but this used to be something like

        rule char_regular() -> u8
            = b:$(quiet!{[-!#$%&\'*+`/0-9a-zA-Z=?~^_{}|\u80\uFF]} / expected!("regular character"))
            {debug_assert!(b.len()==1); b[0]}

Eyes hurt when I try to analyze the new set description. Could you include some macros perhaps that would take the old syntax or similar and produce the appropriate matching pattern? I can imagine this would be possible to adapt:

       rule char_regular() -> u8
            = b:$(quiet!{[any!("-!#$%&\'*+`/0-9a-zA-Z=?~^_{}|\u80\uFF")]} / expected!("regular character"))
            {debug_assert!(b.len()==1); b[0]}

Thank you. Ref https://gitlab.com/BrightOpen/BackYard/Samotop/-/blob/develop/samotop-parser/src/smtp.rs

jocutajar avatar Aug 23 '20 18:08 jocutajar