P.S. Question for merlyn if he checks back: What is the nibbling approach? I performed a search here and looked through my library, but couldn't find anything ....
Nibbling is a method of tokenization by constantly attempting substitutions at the beginning of the string, replacing it with nothing if found.
$_ = "Hello there, people!"; @output = (); while (length) { (push @output, "word: $1"), next if s/^(\w+)//; (push @output, "spaces"), next if s/^\s+//; (push @output, "punc: $1"), next if s/^(.)//; die "how did I get here?"; } print map "$_\n", @output;
This is fine for small strings, but the constant leftward shuffling of the string gets very expensive for huge strings. P::RD uses nibbling. P::FastDescent will use pos() scanning instead:
$_ = "Hello there, people!"; @output = (); while (pos $_ <= length $_) { (push @output, "word: $1"), next if /\G(\w+)/gc; (push @output, "spaces"), next if /\G\s+/gc; (push @output, "punc: $1"), next if /\G(.)/gc; die "how did I get here?"; } print map "$_\n", @output;
Much easier, but wasn't available when theDamian first wrote P::RD.

-- Randal L. Schwartz, Perl hacker


In reply to Nibbling Approach (was Re: Re: Parse::RecDescent size limit?) by merlyn
in thread Parse::RecDescent size limit? by Anonymous Monk

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.