waxeye-org / waxeye

Waxeye is a parser generator based on parsing expression grammars (PEGs). It supports C, Java, JavaScript, Python, Racket, and Ruby.
https://waxeye-org.github.io/waxeye/index.html
Other
235 stars 38 forks source link

Implement "negative" symbol classes #101

Closed KOLANICH closed 4 years ago

KOLANICH commented 4 years ago

All symbols except these ones, for example is in regexps is [^a] and in ANTLR ~[a] mean "all symbols except a".

orlandohill commented 4 years ago

Have you tried ![a] .? That should be equivalent.

KOLANICH commented 4 years ago

No, I haven't, but I will try. Thanks. Looks like it should work. Shame on me, I haven't thought about this solution.

BTW what should give better performance, the real negative class (positive class having all chars except one in a negative class) or this solution?

orlandohill commented 4 years ago

Future versions of the compiler could detect and optimize for this pattern.

I don't think introducing special syntax would be required, if performance was an issue.