4 ms·
perl6 grammars have to be seen in context of perl5 regexp. Basically, regular expressions have grown to impossible to understand, write and modify. Mostly due
by riffraff 9y ago
perl6 grammars have to be seen in context of perl5 regexp.
Basically, regular expressions have grown to impossible to understand, write and modify. Mostly due to perl.
Yet, they are used daily by millions of developers, because they are a ton better than manual character checks.
Perl6 grammars are basically an attempt to bring developers another step forward.
- vram22 9y agoAre you saying that Perl6 grammars are a replacement (maybe eventually) for Perl5 regexps?
- riffraff 9y agopartly, you still build Grammars out of "token", "regex" and "rule" definitions, but some things are more natural with one or the other. So, if you are doing "test if string has whitespace" you'd use a regex, while for "parse an apache log line" you'd probably use a grammar instead of a very nasty regex. IANA perl6 dev though, just a casual observer.
- kbenson 9y ago> while for "parse an apache log line" you'd probably use a grammar instead of a very nasty regex. That's actually a fairly easy endeavor with perl regex capabilities, especially named captures. Parsing HTML, or a programming language, or other much more complex structures is much easier with a grammar. For example, JSON parsing[1]. That said, there are ways to approximate some features of grammars with Perl5 regexes[2]. 1: https://github.com/moritz/json/blob/master/lib/JSON/Tiny/Grammar.pm https://github.com/moritz/json/blob/master/lib/JSON/Tiny/Gra... 2: http://blogs.perl.org/users/brian_d_foy/2013/10/parsing-json-with-a-single-regex.html http://blogs.perl.org/users/brian_d_foy/2013/10/parsing-json...
- vram22 9y agoThanks, riffraff and kbenson.