3 ms·
Grammars are invented in Perl6 just for that. Perl5 has module[0] for that implemented using recursive regex's. Example of LaTeX parser: use Regexp::Gramm
by lisivka 11y ago
Grammars are invented in Perl6 just for that. Perl5 has module[0] for that implemented using recursive regex's.
Example of LaTeX parser:
use Regexp::Grammars;
$parser = qr{
<File>
<rule: File> <[Element]>*
<rule: Element> <Command> | <Literal>
<rule: Command> \\ <Literal> <Options>? <Args>?
<rule: Options> \[ <[Option]>+ % (,) \]
<rule: Args> \{ <[Element]>* \}
<rule: Option> [^][\$&%#_{}~^\s,]+
<rule: Literal> [^][\$&%#_{}~^\s]+
}xms
[0] http://search.cpan.org/~dconway/Regexp-Grammars-1.041/lib/Regexp/Grammars.pm http://search.cpan.org/~dconway/Regexp-Grammars-1.041/lib/Re...