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   remove_insignificant
243       This method returns a new object manufactured from the invocant, but
244       containing only elements for which "$elem->significant()" returns a
245       true value.
246
247       If you call this method on a PPIx::Regexp::Node you will get back a
248       deep clone, but without the insignificant elements.
249
250       If you call this method on any other PPIx::Regexp class you will get
251       back either the invocant or nothing. This may change to a clone of the
252       invocant or nothing if unforseen problems arise with returning the
253       invocant, or if objects become mutable (unlikely, but not impossible.)
254
255   requirements_for_perl
256        say $token->requirements_for_perl();
257
258       This method returns a string representing the Perl requirements for a
259       given module. This should only be used for informational purposes, as
260       the format of the string may be subject to change.
261
262       At the moment, the returns may be:
263
264        version <= $]
265        version <= $] < version
266        two or more of the above joined by '||'
267        ! $]
268
269       The last means that, although all the components of the regular
270       expression can be compiled by some version of Perl, there is no version
271       that will compile all of them.
272
273       I reiterate: the returned string may be subject to change, maybe
274       without warning.
275
276       This method was added in version 0.051_01.
277
278   scontent
279       This method returns the significant content of the element. That is, if
280       called on the parse of '/ f u b a r /x', it returns '/fubar/x'. If the
281       invocant contains no insignificant elements, it is the same as
282       content(). If called on an insignificant element, it returns nothing --
283       that is, "undef" in scalar context, and an empty list in list context.
284
285       This method was inspired by jb's question on Perl Monks about stripping
286       comments and white space from a regular expression:
287       <https://www.perlmonks.org/?node_id=1207556>
288
289       This method was added in version 0.053_01
290
291   significant
292       This method returns true if the element is significant and false
293       otherwise.
294
295   snext_element
296       This method returns the next significant element, or nothing if there
297       is none.
298
299       Unlike snext_sibling(), this will cross from the content of a structure
300       into the elements that define the structure, or vice versa.
301
302   snext_sibling
303       This method returns the element's next significant sibling, or nothing
304       if there is none.
305
306       This method is analogous to the same-named PPI::Element method, in that
307       it will not cross from the content of a structure into the elements
308       that define the structure.
309
310   sprevious_element
311       This method returns the previous significant element, or nothing if
312       there is none.
313
314       Unlike sprevious_sibling(), this will cross from the content of a
315       structure into the elements that define the structure, or vice versa.
316
317   sprevious_sibling
318       This method returns the element's previous significant sibling, or
319       nothing if there is none.
320
321       This method is analogous to the same-named PPI::Element method, in that
322       it will not cross from the content of a structure into the elements
323       that define the structure.
324
325   statement
326       This method returns the PPI::Statement that contains this element, or
327       nothing if the statement can not be determined.
328
329       In general this method will return something only under the following
330       conditions:
331
332       ·   The element is contained in a PPIx::Regexp object;
333
334       ·   That object was initialized from a PPI::Element;
335
336       ·   The PPI::Element is contained in a statement.
337
338   tokens
339       This method returns all tokens contained in the element.
340
341   top
342       This method returns the top of the hierarchy.
343
344   unescaped_content
345       This method returns the content of the element, unescaped.
346
347   visual_column_number
348       This method returns the visual column number (taking tabs into account)
349       of the first character in the element, or "undef" if that can not be
350       determined.
351
352   whitespace
353       This method returns true if the element is whitespace and false
354       otherwise.
355
356   nav
357       This method returns navigation information from the top of the
358       hierarchy to this node. The return is a list of names of methods and
359       references to their argument lists. The idea is that given $elem which
360       is somewhere under $top,
361
362        my @nav = $elem->nav();
363        my $obj = $top;
364        while ( @nav ) {
365            my $method = shift @nav;
366            my $args = shift @nav;
367            $obj = $obj->$method( @{ $args } ) or die;
368        }
369        # At this point, $obj should contain the same object
370        # as $elem.
371

SUPPORT

373       Support is by the author. Please file bug reports at
374       <https://rt.cpan.org>, or in electronic mail to the author.
375

AUTHOR

377       Thomas R. Wyant, III wyant at cpan dot org
378
380       Copyright (C) 2009-2020 by Thomas R. Wyant, III
381
382       This program is free software; you can redistribute it and/or modify it
383       under the same terms as Perl 5.10.0. For more details, see the full
384       text of the licenses in the directory LICENSES.
385
386       This program is distributed in the hope that it will be useful, but
387       without any warranty; without even the implied warranty of
388       merchantability or fitness for a particular purpose.
389
390
391
392perl v5.32.0                      2020-07-29          PPIx::Regexp::Element(3)
Impressum