Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Argh, it's driving me nuts.

I am using Parse::RecDescent to parse a meta language, and it is pretty much working, but I am having trouble with quoted strings. I have searched all around and can't find any good documentation on it.

In the P::RD docs it shows a parser for parsing P::RD grammars, and in that it shows { extract_quotelike($text) } being used as a rule. This doesn't do exactly what I want, since I only want ' and ", but it was close enough. I put it in my grammar like so:

string: { $_ = extract_quotelike($text); chop; substr($_,0,1,''); $_; +} { [@item] }
and it works, I realize its probably not right, especially since I get lots of warnings for use of uninitialized values. When I tried to change my code to something more proper and kill the warnings, however, my grammar no longer works. I tried:
string: { extract_quotelike($text) }
and it changes the way the whole grammar works

In fact if I change it to:

string: { $_ = extract_quotelike($text); if($_) { chop; substr($_,0,1, +''); } $_; } { [@item] }
it breaks it as well... which really confuses me.

So, my real question is in two parts
1) how do you use the extract_quotelike in P::RD (I looked all through the docs for an explanation of what rule: { <code> } is supposed to do, but I can't find it. Is it undocumented or am I blind?)
2) Is there a better way to match a string with just single or double quotes?

                - Ant
                - Some of my best work - (1 2 3)


In reply to Quoted Text rule for Parse::RecDescent? by suaveant

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (6)
    As of 2014-07-31 23:15 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (255 votes), past polls