1Regex::Element(3)     User Contributed Perl Documentation    Regex::Element(3)
2
3
4

NAME

6       YAPE::Regex::Element - sub-classes for YAPE::Regex elements
7

SYNOPSIS

9         use YAPE::Regex 'MyExt::Mod';
10         # this sets up inheritence in MyExt::Mod
11         # see YAPE::Regex documentation
12

"YAPE" MODULES

14       The "YAPE" hierarchy of modules is an attempt at a unified means of
15       parsing and extracting content.  It attempts to maintain a generic
16       interface, to promote simplicity and reusability.  The API is powerful,
17       yet simple.  The modules do tokenization (which can be intercepted) and
18       build trees, so that extraction of specific nodes is doable.
19

DESCRIPTION

21       This module provides the classes for the "YAPE::Regex" objects.  The
22       base class for these objects is "YAPE::Regex::Element".  The objects
23       classes are numerous.
24
25   Methods for "YAPE::Regex::Element"
26       This class contains fallback methods for the other classes.
27
28       ·   "my $str = $obj->text;"
29
30           Returns a string representation of the content of the regex node
31           itself, not any nodes contained in it.  This is "undef" for non-
32           text nodes.
33
34       ·   "my $str = $obj->string;"
35
36           Returns a string representation of the regex node itself, not any
37           nodes contained in it.
38
39       ·   "my $str = $obj->fullstring;"
40
41           Returns a string representation of the regex node, including any
42           nodes contained in it.
43
44       ·   "my $quant = $obj->quant;"
45
46           Returns a string with the quantity, and a "?" if the node is non-
47           greedy.  The quantity is one of "*", "+", "?", "{M,N}", or an empty
48           string.
49
50       ·   "my $ng = $obj->ngreed;"
51
52           Returns a "?" if the node is non-greedy, and an empty string
53           otherwise.
54
55   Methods for "YAPE::Regex::anchor"
56       This class represents anchors.  Objects have the following methods:
57
58       ·   "my $anchor = YAPE::Regex::anchor->new($type,$q,$ng);"
59
60           Creates a "YAPE::Regex::anchor" object.  Takes three arguments:
61           the anchor ("^", "\A", "$", "\Z", "\z", "\B", "\b", or "\G"), the
62           quantity, and the non-greedy flag.  The quantity should be an empty
63           string.
64
65             my $anc = YAPE::Regex::anchor->new('\A', '', '?');
66             # /\A?/
67
68       ·   "my $type = $anchor->type;"
69
70           Returns the string "anchor".
71
72   Methods for "YAPE::Regex::macro"
73       This class represents character-class macros.  Objects have the
74       following methods:
75
76       ·   "my $macro = YAPE::Regex::macro->new($type,$q,$ng);"
77
78           Creates a "YAPE::Regex::macro" object.  Takes three arguments:  the
79           macro ("w", "W", "d", "D", "s", or "S"), the quantity, and the non-
80           greedy flag.
81
82             my $macro = YAPE::Regex::macro->new('s', '{3,5}');
83             # /\s{3,5}/
84
85       ·   "my $text = $macro->text;"
86
87           Returns the macro.
88
89             print $macro->text;  # '\s'
90
91       ·   "my $type = $macro->type;"
92
93           Returns the string "macro".
94
95   Methods for "YAPE::Regex::oct"
96       This class represents octal escapes.  Objects have the following
97       methods:
98
99       ·   "my $oct = YAPE::Regex::oct->new($type,$q,$ng);"
100
101           Creates a "YAPE::Regex::oct" object.  Takes three arguments:  the
102           octal number (as a string), the quantity, and the non-greedy flag.
103
104             my $oct = YAPE::Regex::oct->new('040');
105             # /\040/
106
107       ·   "my $text = $oct->text;"
108
109           Returns the octal escape.
110
111             print $oct->text;  # '\040'
112
113       ·   "my $type = $oct->type;"
114
115           Returns the string "oct".
116
117   Methods for "YAPE::Regex::hex"
118       This class represents hexadecimal escapes.  Objects have the following
119       methods:
120
121       ·   "my $hex = YAPE::Regex::hex->new($type,$q,$ng);"
122
123           Creates a "YAPE::Regex::hex" object.  Takes three arguments:  the
124           hexadecimal number (as a string), the quantity, and the non-greedy
125           flag.
126
127             my $hex = YAPE::Regex::hex->new('20','{2,}');
128             # /\x20{2,}/
129
130       ·   "my $text = $hex->text;"
131
132           Returns the hexadecimal escape.
133
134             print $hex->text;  # '\x20'
135
136       ·   "my $type = $hex->type;"
137
138           Returns the string "hex".
139
140   Methods for "YAPE::Regex::utf8hex"
141       This class represents UTF hexadecimal escapes.  Objects have the
142       following methods:
143
144       ·   "my $hex = YAPE::Regex::utf8hex->new($type,$q,$ng);"
145
146           Creates a "YAPE::Regex::utf8hex" object.  Takes three arguments:
147           the hexadecimal number (as a string), the quantity, and the non-
148           greedy flag.
149
150             my $utf8hex = YAPE::Regex::utf8hex->new('beef','{0,4}');
151             # /\x{beef}{2,}/
152
153       ·   "my $text = $utf8hex->text;"
154
155           Returns the hexadecimal escape.
156
157             print $utf8hex->text;  # '\x{beef}'
158
159       ·   "my $type = $utf8hex->type;"
160
161           Returns the string "utf8hex".
162
163   Methods for "YAPE::Regex::backref"
164       This class represents back-references.  Objects have the following
165       methods:
166
167       ·   "my $bref = YAPE::Regex::bref->new($type,$q,$ng);"
168
169           Creates a "YAPE::Regex::bref" object.  Takes three arguments:  the
170           number of the back-reference, the quantity, and the non-greedy
171           flag.
172
173             my $bref = YAPE::Regex::bref->new(2,'','?');
174             # /\2?/
175
176       ·   "my $text = $bref->text;"
177
178           Returns the backescape.
179
180             print $bref->text;  # '\2'
181
182       ·   "my $type = $bref->type;"
183
184           Returns the string "backref".
185
186   Methods for "YAPE::Regex::ctrl"
187       This class represents control character escapes.  Objects have the
188       following methods:
189
190       ·   "my $ctrl = YAPE::Regex::ctrl->new($type,$q,$ng);"
191
192           Creates a "YAPE::Regex::ctrl" object.  Takes three arguments:  the
193           control character, the quantity, and the non-greedy flag.
194
195             my $ctrl = YAPE::Regex::ctrl->new('M');
196             # /\cM/
197
198       ·   "my $text = $ctrl->text;"
199
200           Returns the control character escape.
201
202             print $ctrl->text;  # '\cM'
203
204       ·   "my $type = $ctrl->type;"
205
206           Returns the string "ctrl".
207
208   Methods for "YAPE::Regex::named"
209       This class represents named characters.  Objects have the following
210       methods:
211
212       ·   "my $ctrl = YAPE::Regex::named->new($type,$q,$ng);"
213
214           Creates a "YAPE::Regex::named" object.  Takes three arguments:  the
215           name of the character, the quantity, and the non-greedy flag.
216
217             my $named = YAPE::Regex::named->new('GREEK SMALL LETTER BETA');
218             # /\N{GREEK SMALL LETTER BETA}/
219
220       ·   "my $text = $named->text;"
221
222           Returns the character escape text.
223
224             print $named->text;  # '\N{GREEK SMALL LETTER BETA}'
225
226       ·   "my $type = $named->type;"
227
228           Returns the string "named".
229
230   Methods for "YAPE::Regex::Cchar"
231       This class represents C characters.  Objects have the following
232       methods:
233
234       ·   "my $ctrl = YAPE::Regex::Cchar->new($q,$ng);"
235
236           Creates a "YAPE::Regex::Cchar" object.  Takes two arguments:  the
237           quantity and the non-greedy flag.
238
239             my $named = YAPE::Regex::Char->new(2);
240             # /\C{2}/
241
242       ·   "my $text = $Cchar->text;"
243
244           Returns the escape sequence.
245
246             print $Cchar->text;  # '\C'
247
248       ·   "my $type = $Cchar->type;"
249
250           Returns the string "Cchar".
251
252   Methods for "YAPE::Regex::slash"
253       This class represents any other escaped characters.  Objects have the
254       following methods:
255
256       ·   "my $slash = YAPE::Regex::slash->new($type,$q,$ng);"
257
258           Creates a "YAPE::Regex::slash" object.  Takes three arguments:  the
259           backslashed character, the quantity, and the non-greedy flag.
260
261             my $slash = YAPE::Regex::slash->new('t','','?');
262             # /\t?/
263
264       ·   "my $text = $slash->text;"
265
266           Returns the escaped character.
267
268             print $slash->text;  # '\t'
269
270       ·   "my $type = $slash->type;"
271
272           Returns the string "slash".
273
274   Methods for "YAPE::Regex::any"
275       This class represents the dot metacharacter.  Objects have the
276       following methods:
277
278       ·   "my $any = YAPE::Regex::any->new($q,$ng);"
279
280           Creates a "YAPE::Regex::any" object.  Takes two arguments:  the
281           quantity, and the non-greedy flag.
282
283             my $any = YAPE::Regex::any->new('{1,3}');
284             # /.{1,3}/
285
286       ·   "my $type = $any->type;"
287
288           Returns the string "any".
289
290   Methods for "YAPE::Regex::class"
291       This class represents character classes.  Objects have the following
292       methods:
293
294       ·   "my $class = YAPE::Regex::class->new($chars,$neg,$q,$ng);"
295
296           Creates a "YAPE::Regex::class" object.  Takes four arguments:  the
297           characters in the class, a "^" if the class is negated (an empty
298           string otherwise), the quantity, and the non-greedy flag.
299
300             my $class = YAPE::Regex::class->new('aeiouy','^');
301             # /[^aeiouy]/
302
303       ·   "my $text = $class->text;"
304
305           Returns the character class.
306
307             print $class->text;  # [^aeiouy]
308
309       ·   "my $type = $class->type;"
310
311           Returns the string "class".
312
313   Methods for "YAPE::Regex::hex"
314       This class represents hexadecimal escapes.  Objects have the following
315       methods:
316
317       ·   "my $text = YAPE::Regex::text->new($text,$q,$ng);"
318
319           Creates a "YAPE::Regex::text" object.  Takes three arguments:  the
320           text, the quantity, and the non-greedy flag.  The quantity and non-
321           greedy modifier should only be present for single-character text,
322           because of the way the parser renders the quantity and non-greedy
323           modifier.
324
325             my $text = YAPE::Regex::text->new('alphabet','');
326             # /alphabet/
327
328             my $text = YAPE::Regex::text->new('x','?','?');
329             # /x??/
330
331       ·   "my $type = $text->type;"
332
333           Returns the string "text".
334
335   Methods for "YAPE::Regex::alt"
336       This class represents alternation.  Objects have the following methods:
337
338       ·   "my $alt = YAPE::Regex::alt->new;"
339
340           Creates a "YAPE::Regex::alt" object.
341
342             my $alt = YAPE::Regex::alt->new;
343             # /|/
344
345       ·   "my $type = $oct->type;"
346
347           Returns the string "alt".
348
349   Methods for "YAPE::Regex::comment"
350       This class represents in-line comments.  Objects have the following
351       methods:
352
353       ·   "my $comment = YAPE::Regex::comment->new($comment,$x);"
354
355           Creates a "YAPE::Regex::comment" object.  Takes two arguments:  the
356           text of the comment, and whether or not the "/x" regex modifier is
357           in effect for this comment.  Note that Perl's regex engine will
358           stop a "(?#...)" comment at the first ")", regardless of what you
359           do.
360
361             my $comment = YAPE::Regex::comment->new(
362               "match an optional string of digits"
363             );
364             # /(?#match an optional string of digits)/
365
366             my $comment = YAPE::Regex::comment->new(
367               "match an optional string of digits",
368               1
369             );
370             # /# match an optional string of digits/
371
372       ·   "my $type = $comment->type;"
373
374           Returns the string "comment".
375
376       ·   "my $x_on = $comment->xcomm;"
377
378           Returns true or false, depending on whether the comment is under
379           the "/x" regex modifier.
380
381   Methods for "YAPE::Regex::whitespace"
382       This class represents whitespace under the "/x" regex modifier.
383       Objects have the following methods:
384
385       ·   "my $ws = YAPE::Regex::whitespace->new($text);"
386
387           Creates a "YAPE::Regex::whitespace" object.  Takes one argument:
388           the text of the whitespace.
389
390             my $ws = YAPE::Regex::whitespace->new('  ');
391             # /  /x
392
393       ·   "my $text = $ws->text;"
394
395           Returns the whitespace.
396
397             print $ws->text;  # '  '
398
399       ·   "my $type = $ws->type;"
400
401           Returns the string "whitespace".
402
403   Methods for "YAPE::Regex::flags"
404       This class represents "(?ismx)" flags.  Objects have the following
405       methods:
406
407       ·   "my $flags = YAPE::Regex::flags->new($add,$sub);"
408
409           Creates a "YAPE::Regex::flags" object.  Takes two arguments:  a
410           string of the modes to have on, and a string of the modes to
411           explicitly turn off.  The flags are displayed in alphabetical
412           order.
413
414             my $flags = YAPE::Regex::flags->new('is','m');
415             # /(?is-m)/
416
417       ·   "my $type = $flags->type;"
418
419           Returns the string "flags".
420
421   Methods for "YAPE::Regex::cut"
422       This class represents the cut assertion.  Objects have the following
423       methods:
424
425       ·   "my $look = YAPE::Regex::cut->new(\@nodes);"
426
427           Creates a "YAPE::Regex::cut" object.  Takes one arguments:  a
428           reference to an array of objects to be contained in the cut.
429
430             my $REx = YAPE::Regex::class->new('aeiouy','','+');
431             my $look = YAPE::Regex::cut->new(0,[$REx]);
432             # /(?>[aeiouy]+)/
433
434       ·   "my $type = $cut->type;"
435
436           Returns the string "cut".
437
438   Methods for "YAPE::Regex::lookahead"
439       This class represents lookaheads.  Objects have the following methods:
440
441       ·   "my $look = YAPE::Regex::lookahead->new($pos,\@nodes);"
442
443           Creates a "YAPE::Regex::lookahead" object.  Takes two arguments:  a
444           boolean value indicating whether or not the lookahead is positive,
445           and a reference to an array of objects to be contained in the
446           lookahead.
447
448             my $REx = YAPE::Regex::class->new('aeiouy');
449             my $look = YAPE::Regex::lookahead->new(0,[$REx]);
450             # /(?![aeiouy])/
451
452       ·   "my $pos = $look->pos;"
453
454           Returns true if the lookahead is positive.
455
456             print $look->pos ? 'pos' : 'neg';  # 'neg'
457
458       ·   "my $type = $look->type;"
459
460           Returns the string "lookahead(pos)" or "lookahead(neg)".
461
462   Methods for "YAPE::Regex::lookbehind"
463       This class represents lookbehinds.  Objects have the following methods:
464
465       ·   "my $look = YAPE::Regex::lookbehind->new($pos,\@nodes);"
466
467           Creates a "YAPE::Regex::lookbehind" object.  Takes two arguments:
468           a boolean value indicating whether or not the lookbehind is
469           positive, and a reference to an array of objects to be contained in
470           the lookbehind.
471
472             my $REx = YAPE::Regex::class->new('aeiouy','^');
473             my $look = YAPE::Regex::lookbehind->new(1,[$REx]);
474             # /(?<=[^aeiouy])/
475
476       ·   "my $pos = $look->pos;"
477
478           Returns true if the lookbehind is positive.
479
480             print $look->pos ? 'pos' : 'neg';  # 'pos'
481
482       ·   "my $type = $look->type;"
483
484           Returns the string "lookbehind(pos)" or "lookbehind(neg)".
485
486   Methods for "YAPE::Regex::conditional"
487       This class represents conditionals.  Objects have the following
488       methods:
489
490       ·   "my $cond = YAPE::Regex::conditional->new($br,$t,$f,$q,$ng);"
491
492           Creates a "YAPE::Regex::hex" object.  Takes five arguments:  the
493           number of the back-reference (that's all that's supported in the
494           current version), an array reference to the "true" pattern, an
495           array reference to the "false" pattern, and the quantity and non-
496           greedy flag.
497
498             my $cond = YAPE::Regex::conditional->new(
499               2,
500               [],
501               [ YAPE::Regex::text->new('foo') ],
502               '?',
503             );
504             # /(?(2)|foo)?/
505
506       ·   "my $br = $cond->backref;"
507
508           Returns the number of the back-reference the conditional depends
509           on.
510
511             print $br->backref;  # 2
512
513       ·   "my $type = $cond->type;"
514
515           Returns the string "conditional(N)", where N is the number of the
516           back-reference.
517
518   Methods for "YAPE::Regex::group"
519       This class represents non-capturing groups.  Objects have the following
520       methods:
521
522       ·   "my $group = YAPE::Regex::group->new($on,$off,\@nodes,$q,$ng);"
523
524           Creates a "YAPE::Regex::group" object.  Takes five arguments:  the
525           modes turned on, the modes explicitly turned off, a reference to an
526           array of objects in the group, the quantity, and the non-greedy
527           flag.  The modes are displayed in alphabetical order.
528
529             my $group = YAPE::Regex::group->new(
530               'i',
531               's',
532               [
533                 YAPE::Regex::macro->new('d', '{2}'),
534                 YAPE::Regex::macro->new('s'),
535                 YAPE::Regex::macro->new('d', '{2}'),
536               ],
537               '?',
538             );
539             # /(?i-s:\d{2}\s\d{2})?/
540
541       ·   "my $type = $group->type;"
542
543           Returns the string "group".
544
545   Methods for "YAPE::Regex::capture"
546       This class represents capturing groups.  Objects have the following
547       methods:
548
549       ·   "my $capture = YAPE::Regex::capture->new(\@nodes,$q,$ng);"
550
551           Creates a "YAPE::Regex::capture" object.  Takes three arguments:  a
552           reference to an array of objects in the group, the quantity, and
553           the non-greedy flag.
554
555             my $capture = YAPE::Regex::capture->new(
556               [
557                 YAPE::Regex::macro->new('d', '{2}'),
558                 YAPE::Regex::macro->new('s'),
559                 YAPE::Regex::macro->new('d', '{2}'),
560               ],
561             );
562             # /(\d{2}\s\d{2})/
563
564       ·   "my $type = $capture->type;"
565
566           Returns the string "capture".
567
568   Methods for "YAPE::Regex::code"
569       This class represents code blocks.  Objects have the following methods:
570
571       ·   "my $code = YAPE::Regex::code->new($block);"
572
573           Creates a "YAPE::Regex::code" object.  Takes one arguments:  a
574           string holding a block of code.
575
576             my $code = YAPE::Regex::code->new(q({ push @poss, $1 }));
577             # /(?{ push @poss, $1 })/
578
579       ·   "my $type = $code->type;"
580
581           Returns the string "code".
582
583   Methods for "YAPE::Regex::later"
584       This class represents closed parentheses.  Objects have the following
585       methods:
586
587       ·   "my $later = YAPE::Regex::later->new($block);"
588
589           Creates a "YAPE::Regex::later" object.  Takes one arguments:  a
590           string holding a block of code.
591
592             my $later = YAPE::Regex::later->new(q({ push @poss, $1 }));
593             # /(?{{ push @poss, $1 }})/
594
595       ·   "my $type = $later->type;"
596
597           Returns the string "later".
598
599   Methods for "YAPE::Regex::close"
600       This class represents closed parentheses.  Objects have the following
601       methods:
602
603       ·   "my $close = YAPE::Regex::close->new($q,$ng);"
604
605           Creates a "YAPE::Regex::close" object.  Takes two arguments:  the
606           quantity, and the non-greedy flag.  This object is never needed in
607           the tree; however, they are returned in the parsing stage, so that
608           you know when they've been reached.
609
610             my $close = YAPE::Regex::close->new('?','?');
611             # /)??/
612
613       ·   "my $type = $close->type;"
614
615           Returns the string "close".
616

TO DO

618       This is a listing of things to add to future versions of this module.
619
620       ·   None!
621

BUGS

623       Following is a list of known or reported bugs.
624
625       ·   This documentation might be incomplete.
626

SUPPORT

628       Visit "YAPE"'s web site at http://www.pobox.com/~japhy/YAPE/.
629

SEE ALSO

631       The "YAPE::Regex" documentation, for information on the main class.
632

AUTHOR

634         Jeff "japhy" Pinyan
635         CPAN ID: PINYAN
636         japhy@pobox.com
637         http://www.pobox.com/~japhy/
638
639
640
641perl v5.12.1                      2001-05-03                 Regex::Element(3)
Impressum