regex - How do I best do balanced quoting with Perl's Regexp::Grammars? -
Using the Damien Conway, I use different balanced quotes (
'foo'
, "foo"
, but 'foo'
) - Such as feet, quotes, double quotes, and not as double dollars. This is the code that I am currently using. / P> & lt; Token: pair and gt; \ '& Lt; Textual & gt; \ '| \ "& Lt; literal & gt; \" | \ $ \ $ & Lt; Textual & gt; \ $ \ $ & Lt; Token: Textual & gt; ; [\ S] +
It usually works fine and allows me to say something like this:
& lt; Rule: quotes & gt; Coat & lt; To exclude needle notation for .as & gt
pair
token, my question is how do I improve the output?{"'=> 'Coat AS', '', 'Quote' => {'' = & Gt; 'Coat AS', '', 'Pair' => {'Literal' = & gt; ',', '' = & gt; \ ', \' '}}},
Here, obviously between
pair
, quote, andliteral
There is no wish to have a better way of matching'foo'
,"foo"
and$$ foo $$
, and maybe Sometimes(Foo)
each time without creating an unnecessarypair
token? Can I already process or multiply in tokens? Or, write a better creation altogether, which eliminates its need?
per daemian, the answer was in fact in the part of the docs
The correct answer is your & lt; Pair and gt; Each & lt; Textual & gt; To pass the result of the token MATCH = alias (see: Using "manual result distillation" in the module document), as your own result, such as: & lt; Token: Pair & gt; \ 'And lieutenant; MATCH = Textual & gt; \ '| \ "& Lt; MATCH = script & gt; \" | \ $ \ $ & Lt; MATCH = literal & gt; What Do Docs Say: Regexp :: Grammar also provides full manual control over the distillation process if you want to call the above mentioned call Reserved words use the MATCH as the nickname [...] Note that, in this second case, the result-hash has been captured, they will not be returned, because the match aka normal Overrides "result-hash" returns semantics and only its Related subtitles forms (ie).