perldebguts.html

来自「perl教程」· HTML 代码 · 共 928 行 · 第 1/4 页

HTML
928 行
字号
        0[0] 12[1] 0[0] 6[1] 0[0] 7[1] 0[0] 9[1] 8[1] 0[0] 10[1] 0[0]
        11[1] 0[0] 12[0] 12[0] 13[1] 0[0] 14[4] 0[0] 0[0] 0[0] 0[0]
        0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 18[1] 0[0] 19[1] 20[0]  
  Omitting $`</span> <span class="variable">$&amp;</span> <span class="variable">$'</span> <span class="variable">support</span><span class="operator">.</span>
</pre>
<p>The first line shows the pre-compiled form of the regex.  The second
shows the size of the compiled form (in arbitrary units, usually
4-byte words) and the total number of bytes allocated for the
offset/length table, usually 4+<a href="../../lib/Pod/perlfunc.html#item_size"><code>size</code></a>*8.  The next line shows the
label <em>id</em> of the first node that does a match.</p>
<p>The</p>
<pre>
  anchored `de' at 1 floating `gh' at 3..2147483647 (checking floating) 
        stclass `ANYOF[bc]' minlen 7</pre>
<p>line (split into two lines above) contains optimizer
information.  In the example shown, the optimizer found that the match 
should contain a substring <code>de</code> at offset 1, plus substring <code>gh</code>
at some offset between 3 and infinity.  Moreover, when checking for
these substrings (to abandon impossible matches quickly), Perl will check
for the substring <code>gh</code> before checking for the substring <code>de</code>.  The
optimizer may also use the knowledge that the match starts (at the
<code>first</code> <em>id</em>) with a character class, and no string 
shorter than 7 characters can possibly match.</p>
<p>The fields of interest which may appear in this line are</p>
<dl>
<dt><strong><a name="item_anchored_string_at_pos"><a href="#item_anchored"><code>anchored</code></a> <em>STRING</em> <code>at</code> <em>POS</em></a></strong>

<dt><strong><a name="item_floating_string_at_pos1_2e_2epos2"><code>floating</code> <em>STRING</em> <code>at</code> <em>POS1..POS2</em></a></strong>

<dd>
<p>See above.</p>
</dd>
</li>
<dt><strong><a name="item_matching_floating_2fanchored"><code>matching floating/anchored</code></a></strong>

<dd>
<p>Which substring to check first.</p>
</dd>
</li>
<dt><strong><a name="item_minlen"><code>minlen</code></a></strong>

<dd>
<p>The minimal length of the match.</p>
</dd>
</li>
<dt><strong><a name="item_stclass"><code>stclass</code> <em>TYPE</em></a></strong>

<dd>
<p>Type of first matching node.</p>
</dd>
</li>
<dt><strong><a name="item_noscan"><code>noscan</code></a></strong>

<dd>
<p>Don't scan for the found substrings.</p>
</dd>
</li>
<dt><strong><a name="item_isall"><code>isall</code></a></strong>

<dd>
<p>Means that the optimizer information is all that the regular
expression contains, and thus one does not need to enter the regex engine at
all.</p>
</dd>
</li>
<dt><strong><a name="item_gpos"><code>GPOS</code></a></strong>

<dd>
<p>Set if the pattern contains <code>\G</code>.</p>
</dd>
</li>
<dt><strong><a name="item_plus"><code>plus</code></a></strong>

<dd>
<p>Set if the pattern starts with a repeated char (as in <code>x+y</code>).</p>
</dd>
</li>
<dt><strong><a name="item_implicit"><code>implicit</code></a></strong>

<dd>
<p>Set if the pattern starts with <code>.*</code>.</p>
</dd>
</li>
<dt><strong><a name="item_with_eval"><code>with eval</code></a></strong>

<dd>
<p>Set if the pattern contain eval-groups, such as <code>(?{ code })</code> and
<code>(??{ code })</code>.</p>
</dd>
</li>
<dt><strong><a name="item_anchored"><code>anchored(TYPE)</code></a></strong>

<dd>
<p>If the pattern may match only at a handful of places, (with <code>TYPE</code>
being <code>BOL</code>, <code>MBOL</code>, or <a href="#item_gpos"><code>GPOS</code></a>.  See the table below.</p>
</dd>
</li>
</dl>
<p>If a substring is known to match at end-of-line only, it may be
followed by <code>$</code>, as in <code>floating `k'$</code>.</p>
<p>The optimizer-specific information is used to avoid entering (a slow) regex
engine on strings that will not definitely match.  If the <a href="#item_isall"><code>isall</code></a> flag
is set, a call to the regex engine may be avoided even when the optimizer
found an appropriate place for the match.</p>
<p>Above the optimizer section is the list of <em>nodes</em> of the compiled
form of the regex.  Each line has format</p>
<p><code>   </code><em>id</em>: <em>TYPE</em> <em>OPTIONAL-INFO</em> (<em>next-id</em>)</p>
<p>
</p>
<h2><a name="types_of_nodes">Types of nodes</a></h2>
<p>Here are the possible types, with short descriptions:</p>
<pre>
    <span class="comment"># TYPE arg-description [num-args] [longjump-len] DESCRIPTION</span>
</pre>
<pre>
    # Exit points
    END         no      End of program.
    SUCCEED     no      Return from a subroutine, basically.</pre>
<pre>
    # Anchors:
    BOL         no      Match &quot;&quot; at beginning of line.
    MBOL        no      Same, assuming multiline.
    SBOL        no      Same, assuming singleline.
    EOS         no      Match &quot;&quot; at end of string.
    EOL         no      Match &quot;&quot; at end of line.
    MEOL        no      Same, assuming multiline.
    SEOL        no      Same, assuming singleline.
    BOUND       no      Match &quot;&quot; at any word boundary
    BOUNDL      no      Match &quot;&quot; at any word boundary
    NBOUND      no      Match &quot;&quot; at any word non-boundary
    NBOUNDL     no      Match &quot;&quot; at any word non-boundary
    GPOS        no      Matches where last m//g left off.</pre>
<pre>
    # [Special] alternatives
    ANY         no      Match any one character (except newline).
    SANY        no      Match any one character.
    ANYOF       sv      Match character in (or not in) this class.
    ALNUM       no      Match any alphanumeric character
    ALNUML      no      Match any alphanumeric char in locale
    NALNUM      no      Match any non-alphanumeric character
    NALNUML     no      Match any non-alphanumeric char in locale
    SPACE       no      Match any whitespace character
    SPACEL      no      Match any whitespace char in locale
    NSPACE      no      Match any non-whitespace character
    NSPACEL     no      Match any non-whitespace char in locale
    DIGIT       no      Match any numeric character
    NDIGIT      no      Match any non-numeric character</pre>
<pre>
    <span class="comment"># BRANCH    The set of branches constituting a single choice are hooked</span>
    <span class="comment">#           together with their "next" pointers, since precedence prevents</span>
    <span class="comment">#           anything being concatenated to any individual branch.  The</span>
    <span class="comment">#           "next" pointer of the last BRANCH in a choice points to the</span>
    <span class="comment">#           thing following the whole choice.  This is also where the</span>
    <span class="comment">#           final "next" pointer of each individual branch points; each</span>
    <span class="comment">#           branch starts with the operand node of a BRANCH node.</span>
    <span class="comment">#</span>
    <span class="variable">BRANCH</span>      <span class="variable">node</span>    <span class="variable">Match</span> <span class="variable">this</span> <span class="variable">alternative</span><span class="operator">,</span> <span class="keyword">or</span> <span class="variable">the</span> <span class="keyword">next</span><span class="operator">...</span>
</pre>
<pre>
    <span class="comment"># BACK      Normal "next" pointers all implicitly point forward; BACK</span>
    <span class="comment">#           exists to make loop structures possible.</span>
    <span class="comment"># not used</span>
    <span class="variable">BACK</span>        <span class="keyword">no</span>      <span class="variable">Match</span> <span class="string">""</span><span class="operator">,</span> <span class="string">"next"</span> <span class="variable">ptr</span> <span class="variable">points</span> <span class="variable">backward</span><span class="operator">.</span>
</pre>
<pre>
    # Literals
    EXACT       sv      Match this string (preceded by length).
    EXACTF      sv      Match this string, folded (prec. by length).
    EXACTFL     sv      Match this string, folded in locale (w/len).</pre>
<pre>
    # Do nothing
    NOTHING     no      Match empty string.
    # A variant of above which delimits a group, thus stops optimizations
    TAIL        no      Match empty string. Can jump here from outside.</pre>
<pre>
    # STAR,PLUS '?', and complex '*' and '+', are implemented as circular
    #           BRANCH structures using BACK.  Simple cases (one character
    #           per match) are implemented with STAR and PLUS for speed
    #           and to minimize recursive plunges.
    #
    STAR        node    Match this (simple) thing 0 or more times.
    PLUS        node    Match this (simple) thing 1 or more times.</pre>
<pre>
    <span class="variable">CURLY</span>       <span class="variable">sv</span> <span class="number">2</span>    <span class="variable">Match</span> <span class="variable">this</span> <span class="variable">simple</span> <span class="variable">thing</span> <span class="operator">{</span><span class="variable">n</span><span class="operator">,</span><span class="regex">m} times.
    CURLYN      no 2    Match next-after-this simple thing 
    #                   {n,m}</span> <span class="keyword">times</span><span class="operator">,</span> <span class="variable">set</span> <span class="variable">parens</span><span class="operator">.</span>
    <span class="variable">CURLYM</span>      <span class="keyword">no</span> <span class="number">2</span>    <span class="variable">Match</span> <span class="variable">this</span> <span class="variable">medium</span><span class="operator">-</span><span class="variable">complex</span> <span class="variable">thing</span> <span class="operator">{</span><span class="variable">n</span><span class="operator">,</span><span class="regex">m} times.
    CURLYX      sv 2    Match this complex thing {n,m}</span> <span class="keyword">times</span><span class="operator">.</span>
</pre>
<pre>
    # This terminator creates a loop structure for CURLYX
    WHILEM      no      Do curly processing and see if rest matches.</pre>
<pre>
    # OPEN,CLOSE,GROUPP ...are numbered at compile time.
    OPEN        num 1   Mark this point in input as start of #n.
    CLOSE       num 1   Analogous to OPEN.</pre>
<pre>
    REF         num 1   Match some already matched string
    REFF        num 1   Match already matched string, folded
    REFFL       num 1   Match already matched string, folded in loc.</pre>
<pre>
    # grouping assertions
    IFMATCH     off 1 2 Succeeds if the following matches.
    UNLESSM     off 1 2 Fails if the following matches.
    SUSPEND     off 1 1 &quot;Independent&quot; sub-regex.
    IFTHEN      off 1 1 Switch, should be preceded by switcher .
    GROUPP      num 1   Whether the group matched.</pre>
<pre>
    # Support for long regex
    LONGJMP     off 1 1 Jump far away.
    BRANCHJ     off 1 1 BRANCH with long offset.</pre>
<pre>
    # The heavy worker
    EVAL        evl 1   Execute some Perl code.</pre>
<pre>
    # Modifiers
    MINMOD      no      Next operator is not greedy.
    LOGICAL     no      Next opcode should set the flag only.</pre>
<pre>
    # This is not used yet
    RENUM       off 1 1 Group with independently numbered parens.</pre>
<pre>
    # This is not really a node, but an optimized away piece of a &quot;long&quot; node.
    # To simplify debugging output, we mark it as if it were a node
    OPTIMIZED   off     Placeholder for dump.</pre>
<p>Following the optimizer information is a dump of the offset/length
table, here split across several lines:</p>
<pre>
  Offsets: [45]
        1[4] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 5[1]
        0[0] 12[1] 0[0] 6[1] 0[0] 7[1] 0[0] 9[1] 8[1] 0[0] 10[1] 0[0]
        11[1] 0[0] 12[0] 12[0] 13[1] 0[0] 14[4] 0[0] 0[0] 0[0] 0[0]

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?