5 ms·
Do you have a good link to learn about grammars in perl?
by alexchantavy 6y ago
Do you have a good link to learn about grammars in perl?
- lizmat 6y agoPerl does not have grammars (at least, not built-in). Raku (formerly known as Perl 6) does: https://docs.raku.org/language/grammar_tutorial https://docs.raku.org/language/grammar_tutorial
- blindluke 6y ago> Perl does not have grammars (at least, not built-in). That's not true since v5.10 (2007). Here's a sample that matches a subset of LaTeX markup: $matcher = qr{ (?&File) (?(DEFINE) (?<File> (?&Element)* ) (?<Element> \s* (?&Command) | \s* (?&Literal) ) (?<Command> \\ \s* (?&Literal) \s* (?&Options)? \s* (?&Args)? ) (?<Options> \[ \s* (?:(?&Option) (?:\s*,\s* (?&Option) )*)? \s* \]) (?<Args> \{ \s* (?&Element)* \s* \} ) (?<Option> \s* [^][\$&%#_{}~^\s,]+ ) (?<Literal> \s* [^][\$&%#_{}~^\s]+ ) ) }xms It's nowhere near as advanced as Raku grammars (not much is), but it's there, and it's built-in.
- SuspiciousSwan 6y agoStart https://perldoc.perl.org/perlre.html#Extended-Patterns https://perldoc.perl.org/perlre.html#Extended-Patterns . I was trying to find an article from many years ago, but either my google skills fail me, or it is dead. Perl's regular expressions haven't been regular expressions for a long time. Beyond that, the ergonomics of perl make them much more useful for things like flow control than in other languages. It's similar to how you can do type matching in Java, but it's ugly, versus a language like Haskell where using type matching simplifies the code. Perl 6 (as lizmat pointed out), has more powerful rules. I don't know a ton about them.