How do I best do balanced quoting with Perl's Regexp::Grammars?

℡╲_俬逩灬. 提交于 2019-12-06 09:51:58

Per Damian, the answer was actually in the "Manual result distillation" part of the docs

The correct answer is to tell your <pair> token
to pass the result of each <literal> subrule through as its own
result, using the MATCH=
alias (see: "Manual result distillation" in the module documentation)  like so:

   <token: pair>        \'<MATCH=literal>\' | \"<MATCH=literal>\" |
\$\$<MATCH=literal>\$\$

Here is what the docs say:

Regexp::Grammars also offers full manual control over the distillation process. If you use the reserved word MATCH as the alias for a subrule call [...] Note that, in this second case, even though and are captured to the result-hash, they are not returned, because the MATCH alias overrides the normal "return the result-hash" semantics and returns only what its associated subrule (i.e. ) produces.

Use another great module by Damian, Text::Balanced.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!