|
|
|
|
|
by blindluke
2182 days 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. |
|