gkappler / CombinedParsers.jl

Compiled parser combinators and regular expressions in pure julia
MIT License
78 stars 10 forks source link

Confusing syntax #27

Closed kskyten closed 3 years ago

kskyten commented 3 years ago

I'm confused by the exclamation mark syntax. I could find the documentation for the single exclamation mark (https://gkappler.github.io/CombinedParsers.jl/dev/lib/public/#Base.:!), which is a parser transformation to get the matched substring. At first, I thought it was a negation of the parser as that is the meaning of ! elsewhere in Julia. Maybe it would be better to use a longer name such as getmatch and possibly use a different shorthand as well. I also noticed the use of a double exclamation mark !!, but couldn't find documentation for it.

gkappler commented 3 years ago

The exclamation syntax was adopted from scala fastparse. Alternatively you can use JoinSubstring, but I am open to suggestions as I want to rename the constructor/type to include Vector views when parsing non-Strings. I think of Match(parser) = map(Match(), parser), or map(MatchView, parser). What do you think?

I personally like the ! syntax, as it allows to dispatch on the View on first operator call, and on interning on the second. I improved the documentation of the exclamation syntax https://gkappler.github.io/CombinedParsers.jl/dev/lib/transformation/#Base.:!. (updated release 1.8 soon, pending new dependency package LazyStrings registration delay)

gkappler commented 3 years ago

closing the issue with v0.2 documentation for ! and MatchedSubSequence