1PPIx::Regexp::Element(3U)ser Contributed Perl DocumentatiPoPnIx::Regexp::Element(3)
2
3
4

NAME

6       PPIx::Regexp::Element - Base of the PPIx::Regexp hierarchy.
7

SYNOPSIS

9       No user-serviceable parts inside.
10

INHERITANCE

12       "PPIx::Regexp::Element" is not descended from any other class.
13
14       "PPIx::Regexp::Element" is the parent of PPIx::Regexp::Node and
15       PPIx::Regexp::Token.
16

DESCRIPTION

18       This class is the base of the PPIx::Regexp object hierarchy. It
19       provides the same kind of navigational functionality that is provided
20       by PPI::Element.
21

METHODS

23       This class provides the following public methods. Methods not
24       documented here are private, and unsupported in the sense that the
25       author reserves the right to change or remove them without notice.
26
27   accepts_perl
28        $token->accepts_perl( '5.020' )
29            and say 'This works under Perl 5.20';
30
31       This method returns a true value if the token is acceptable under the
32       specified version of Perl, and a false value otherwise. Unless the
33       token (or its contents) have been equivocated on, the result is simply
34       what you would expect based on testing the results of
35       perl_version_introduced() and perl_version_removed() versus the given
36       Perl version number.
37
38       This method was added in version 0.051_01.
39
40   ancestor_of
41       This method returns true if the object is an ancestor of the argument,
42       and false otherwise. By the definition of this method, $self is its own
43       ancestor.
44
45   can_be_quantified
46        $token->can_be_quantified()
47            and print "This element can be quantified.\n";
48
49       This method returns true if the element can be quantified.
50
51   class
52       This method returns the class name of the element. It is the same as
53       "ref $self".
54
55   column_number
56       This method returns the column number of the first character in the
57       element, or "undef" if that can not be determined.
58
59   comment
60       This method returns true if the element is a comment and false
61       otherwise.
62
63   content
64       This method returns the content of the element.
65
66   descendant_of
67       This method returns true if the object is a descendant of the argument,
68       and false otherwise. By the definition of this method, $self is its own
69       descendant.
70
71   explain
72       This method returns a brief explanation of what the element does. The
73       return will be either a string or "undef" in scalar context, but may be
74       multiple values or an empty array in list context.
75
76       This method should be considered experimental. What it returns may
77       change without notice as my understanding of what all the pieces/parts
78       of a Perl regular expression evolves. The worst case is that it will
79       prove entirely infeasible to implement satisfactorily, in which case it
80       will be put through a deprecation cycle and retracted.
81
82   error
83        say $token->error();
84
85       If an element is one of the classes that represents a parse error, this
86       method may return a brief message saying why. Otherwise it will return
87       "undef".
88
89   is_matcher
90       This method reports on whether the element potentially matches
91       something. Possible returns are a true value if it does, a false (but
92       defined) value if it does not, or "undef" if this can not be
93       determined.
94
95       The idea is to classify elements based on whether they potentially
96       match something in the target string.
97
98       This method is overridden to return "undef" in
99       PPIx::Regexp::Token::Code, PPIx::Regexp::Token::Interpolation, and
100       PPIx::Regexp::Token::Unknown.
101
102       This method is overridden to return a true value in
103       PPIx::Regexp::Token::Assertion, PPIx::Regexp::Token::CharClass,
104       PPIx::Regexp::Token::Literal, and PPIx::Regexp::Token::Reference.
105
106       For PPIx::Regexp::Node, this method is overridden to return a value
107       computed from the node's children.
108
109       For anything else this method returns a false (but defined) value.
110
111   in_regex_set
112       This method returns a true value if the invocant is contained in an
113       extended bracketed character class (also known as a regex set), and a
114       false value otherwise. This method returns true if the invocant is a
115       PPIx::Regexp::Structure::RegexSet.
116
117   is_quantifier
118        $token->is_quantifier()
119            and print "This element is a quantifier.\n";
120
121       This method returns true if the element is a quantifier. You can not
122       tell this from the element's class, because a right curly bracket may
123       represent a quantifier for the purposes of figuring out whether a
124       greediness token is possible.
125
126   line_number
127       This method returns the line number of the first character in the
128       element, or "undef" if that can not be determined.
129
130   location
131       This method returns a reference to an array describing the position of
132       the element in the regular expression, or "undef" if locations were not
133       indexed.
134
135       The array is compatible with the corresponding PPI::Element method.
136
137   logical_filename
138       This method returns the logical file name (taking "#line" directives
139       into account) of the file containing first character in the element, or
140       "undef" if that can not be determined.
141
142   logical_line_number
143       This method returns the logical line number (taking "#line" directives
144       into account) of the first character in the element, or "undef" if that
145       can not be determined.
146
147   main_structure
148       This method returns the PPIx::Regexp::Structure::Main that contains the
149       element. In practice this will be a PPIx::Regexp::Structure::Regexp or
150       a PPIx::Regexp::Structure::Replacement,
151
152       If the element is not contained in any such structure, "undef" is
153       returned. This will happen if the element is a PPIx::Regexp or one of
154       its immediate children.
155
156   modifier_asserted
157        $token->modifier_asserted( 'i' )
158            and print "Matched without regard to case.\n";
159
160       This method returns true if the given modifier is in effect for the
161       element, and false otherwise.
162
163       What it does is to walk backwards from the element until it finds a
164       modifier object that specifies the modifier, whether asserted or
165       negated. and returns the specified value. If nobody specifies the
166       modifier, it returns "undef".
167
168       This method will not work reliably if called on tokenizer output.
169
170   next_element
171       This method returns the next element, or nothing if there is none.
172
173       Unlike next_sibling(), this will cross from the content of a structure
174       into the elements that define the structure, or vice versa.
175
176   next_sibling
177       This method returns the element's next sibling, or nothing if there is
178       none.
179
180   next_token
181       This method returns the next token, or nothing if there is none.
182
183       Unlike next_element(), this will walk the parse tree.
184
185   parent
186       This method returns the parent of the element, or undef if there is
187       none.
188
189   perl_version_introduced
190       This method returns the version of Perl in which the element was
191       introduced. This will be at least 5.000. Before 5.006 I am relying on
192       the perldelta, perlre, and perlop documentation, since I have been
193       unable to build earlier Perls. Since I have found no documentation
194       before 5.003, I assume that anything found in 5.003 is also in 5.000.
195
196       Since this all depends on my ability to read and understand masses of
197       documentation, the results of this method should be viewed with
198       caution, if not downright skepticism.
199
200       There are also cases which are ambiguous in various ways. For those see
201       the PPIx::Regexp documentation, particularly Changes in Syntax.
202
203       Very occasionally, a construct will be removed and then added back. If
204       this happens, this method will return the lowest version in which the
205       construct appeared. For the known instances of this, see the
206       PPIx::Regexp documentation, particularly Equivocation.
207
208   perl_version_removed
209       This method returns the version of Perl in which the element was
210       removed. If the element is still valid the return is "undef".
211
212       All the caveats to perl_version_introduced() apply here also, though
213       perhaps less severely since although many features have been introduced
214       since 5.0, few have been removed.
215
216       Very occasionally, a construct will be removed and then added back. If
217       this happens, this method will return the "undef" if the construct is
218       present in the highest-numbered version of Perl (whether production or
219       development), or the version after the highest-numbered version in
220       which it appeared otherwise. For the known instances of this, see the
221       PPIx::Regexp documentation, particularly Equivocation.
222
223   previous_element
224       This method returns the previous element, or nothing if there is none.
225
226       Unlike previous_sibling(), this will cross from the content of a
227       structure into the elements that define the structure, or vice versa.
228
229   previous_sibling
230       This method returns the element's previous sibling, or nothing if there
231       is none.
232
233       This method is analogous to the same-named PPI::Element method, in that
234       it will not cross from the content of a structure into the elements
235       that define the structure.
236
237   previous_token
238       This method returns the previous token, or nothing if there is none.
239
240       Unlike previous_element(), this will walk the parse tree.
241
242   raw_width
243        my ( $raw_min, $raw_max ) = $self->raw_width();
244
245       This public method returns the minimum and maximum width matched by the
246       element before taking into account such details as what the element
247       actually is and how it is quantified. Either or both elements can be
248       "undef" if the width can not be determined, and the maximum can be
249       "Inf".
250
251       This method was added in version 0.085_01.
252
253   remove_insignificant
254       This method returns a new object manufactured from the invocant, but
255       containing only elements for which "$elem->significant()" returns a
256       true value.
257
258       If you call this method on a PPIx::Regexp::Node you will get back a
259       deep clone, but without the insignificant elements.
260
261       If you call this method on any other PPIx::Regexp class you will get
262       back either the invocant or nothing. This may change to a clone of the
263       invocant or nothing if unforeseen problems arise with returning the
264       invocant, or if objects become mutable (unlikely, but not impossible.)
265
266   requirements_for_perl
267        say $token->requirements_for_perl();
268
269       This method returns a string representing the Perl requirements for a
270       given module. This should only be used for informational purposes, as
271       the format of the string may be subject to change.
272
273       At the moment, the returns may be:
274
275        version <= $]
276        version <= $] < version
277        two or more of the above joined by '||'
278        ! $]
279
280       The last means that, although all the components of the regular
281       expression can be compiled by some version of Perl, there is no version
282       that will compile all of them.
283
284       I reiterate: the returned string may be subject to change, maybe
285       without warning.
286
287       This method was added in version 0.051_01.
288
289   scontent
290       This method returns the significant content of the element. That is, if
291       called on the parse of '/ f u b a r /x', it returns '/fubar/x'. If the
292       invocant contains no insignificant elements, it is the same as
293       content(). If called on an insignificant element, it returns nothing --
294       that is, "undef" in scalar context, and an empty list in list context.
295
296       This method was inspired by jb's question on Perl Monks about stripping
297       comments and white space from a regular expression:
298       <https://www.perlmonks.org/?node_id=1207556>
299
300       This method was added in version 0.053_01
301
302   significant
303       This method returns true if the element is significant and false
304       otherwise.
305
306   snext_element
307       This method returns the next significant element, or nothing if there
308       is none.
309
310       Unlike snext_sibling(), this will cross from the content of a structure
311       into the elements that define the structure, or vice versa.
312
313   snext_sibling
314       This method returns the element's next significant sibling, or nothing
315       if there is none.
316
317       This method is analogous to the same-named PPI::Element method, in that
318       it will not cross from the content of a structure into the elements
319       that define the structure.
320
321   sprevious_element
322       This method returns the previous significant element, or nothing if
323       there is none.
324
325       Unlike sprevious_sibling(), this will cross from the content of a
326       structure into the elements that define the structure, or vice versa.
327
328   sprevious_sibling
329       This method returns the element's previous significant sibling, or
330       nothing if there is none.
331
332       This method is analogous to the same-named PPI::Element method, in that
333       it will not cross from the content of a structure into the elements
334       that define the structure.
335
336   statement
337       This method returns the PPI::Statement that contains this element, or
338       nothing if the statement can not be determined.
339
340       In general this method will return something only under the following
341       conditions:
342
343       •   The element is contained in a PPIx::Regexp object;
344
345       •   That object was initialized from a PPI::Element;
346
347       •   The PPI::Element is contained in a statement.
348
349   tokens
350       This method returns all tokens contained in the element.
351
352   top
353       This method returns the top of the hierarchy.
354
355   unescaped_content
356       This method returns the content of the element, unescaped.
357
358   visual_column_number
359       This method returns the visual column number (taking tabs into account)
360       of the first character in the element, or "undef" if that can not be
361       determined.
362
363   whitespace
364       This method returns true if the element is whitespace and false
365       otherwise.
366
367   width
368        my ( $min, $max ) = $self->width();
369
370       This method returns the minimum and maximum number of characters this
371       element can match.
372
373       Either element can be "undef" if it cannot be determined. For example,
374       for "/$foo/" both elements will be "undef".  Recursions will return
375       "undef" because they can not be analyzed statically -- or at least I am
376       not smart enough to do so. Back references may return "undef" if the
377       referred-to group can not be uniquely determined.
378
379       It is possible for $max to be "Inf". For example, for "/x*/" $max will
380       be "Inf".
381
382       Elements that do not actually match anything will return zeroes.
383
384       Note: This method was added because I wanted better detection of
385       variable-length look-behinds. Both it and raw_width() (above) should be
386       considered somewhat experimental.
387
388       This method was added in version 0.085_01.
389
390   nav
391       This method returns navigation information from the top of the
392       hierarchy to this node. The return is a list of names of methods and
393       references to their argument lists. The idea is that given $elem which
394       is somewhere under $top,
395
396        my @nav = $elem->nav();
397        my $obj = $top;
398        while ( @nav ) {
399            my $method = shift @nav;
400            my $args = shift @nav;
401            $obj = $obj->$method( @{ $args } ) or die;
402        }
403        # At this point, $obj should contain the same object
404        # as $elem.
405

SUPPORT

407       Support is by the author. Please file bug reports at
408       <https://rt.cpan.org/Public/Dist/Display.html?Name=PPIx-Regexp>,
409       <https://github.com/trwyant/perl-PPIx-Regexp/issues>, or in electronic
410       mail to the author.
411

AUTHOR

413       Thomas R. Wyant, III wyant at cpan dot org
414
416       Copyright (C) 2009-2023 by Thomas R. Wyant, III
417
418       This program is free software; you can redistribute it and/or modify it
419       under the same terms as Perl 5.10.0. For more details, see the full
420       text of the licenses in the directory LICENSES.
421
422       This program is distributed in the hope that it will be useful, but
423       without any warranty; without even the implied warranty of
424       merchantability or fitness for a particular purpose.
425
426
427
428perl v5.38.0                      2023-07-21          PPIx::Regexp::Element(3)
Impressum