home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 14 / hacker14.iso / programacao / visual / perl.exe / {app} / Library / YAPE / Regex / Element.pm next >
Encoding:
Perl POD Document  |  2001-05-03  |  23.6 KB  |  1,127 lines

  1. package YAPE::Regex::Element;
  2.  
  3. $VERSION = '3.00';
  4.  
  5.  
  6. sub text { exists $_[0]{TEXT} ? $_[0]{TEXT} : "" }
  7. sub string { $_[0]->text . "$_[0]{QUANT}$_[0]{NGREED}" }
  8. sub fullstring { $_[0]->string }
  9. sub quant { "$_[0]{QUANT}$_[0]{NGREED}" }
  10. sub ngreed { $_[0]{NGREED} }
  11.  
  12.  
  13. package YAPE::Regex::anchor;
  14.  
  15. sub new {
  16.   my ($class,$match,$q,$ng) = @_;
  17.   bless { TEXT => $match, QUANT => $q, NGREED => $ng }, $class;
  18. }
  19.  
  20. sub type { 'anchor' }
  21.  
  22.  
  23.  
  24. package YAPE::Regex::macro;
  25.  
  26. sub new {
  27.   my ($class,$match,$q,$ng) = @_;
  28.   bless { TEXT => $match, QUANT => $q, NGREED => $ng }, $class;
  29. }
  30.  
  31. sub text { "\\$_[0]{TEXT}" }
  32. sub type { 'macro' }
  33.  
  34.  
  35.  
  36. package YAPE::Regex::oct;
  37.  
  38. sub new {
  39.   my ($class,$match,$q,$ng) = @_;
  40.   bless { TEXT => $match, QUANT => $q, NGREED => $ng }, $class;
  41. }
  42.  
  43. sub text { "\\$_[0]{TEXT}" }
  44. sub type { 'oct' }
  45.  
  46.  
  47.  
  48. package YAPE::Regex::hex;
  49.  
  50. sub new {
  51.   my ($class,$match,$q,$ng) = @_;
  52.   bless { TEXT => $match, QUANT => $q, NGREED => $ng }, $class;
  53. }
  54.  
  55. sub text { "\\x$_[0]{TEXT}" }
  56. sub type { 'hex' }
  57.  
  58.  
  59.  
  60. package YAPE::Regex::backref;
  61.  
  62. sub new {
  63.   my ($class,$match,$q,$ng) = @_;
  64.   bless { TEXT => $match, QUANT => $q, NGREED => $ng }, $class;
  65. }
  66.  
  67. sub text { "\\$_[0]{TEXT}" }
  68. sub type { 'backref' }
  69.  
  70.  
  71.  
  72. package YAPE::Regex::ctrl;
  73.  
  74. sub new {
  75.   my ($class,$match,$q,$ng) = @_;
  76.   bless { TEXT => $match, QUANT => $q, NGREED => $ng }, $class;
  77. }
  78.  
  79. sub text { "\\c$_[0]{TEXT}" }
  80. sub type { 'ctrl' }
  81.  
  82.  
  83.  
  84. package YAPE::Regex::named;
  85.  
  86. sub new {
  87.   my ($class,$match,$q,$ng) = @_;
  88.   bless { TEXT => $match, QUANT => $q, NGREED => $ng }, $class;
  89. }
  90.  
  91. sub text { "\\N{$_[0]{TEXT}}" }
  92. sub type { 'named' }
  93.  
  94.  
  95.  
  96. package YAPE::Regex::Cchar;
  97.  
  98. sub new {
  99.   my ($class,$q,$ng) = @_;
  100.   bless { QUANT => $q, NGREED => $ng }, $class;
  101. }
  102.  
  103. sub text { '\C' }
  104. sub type { 'Cchar' }
  105.  
  106.  
  107.  
  108. package YAPE::Regex::slash;
  109.  
  110. sub new {
  111.   my ($class,$match,$q,$ng) = @_;
  112.   bless { TEXT => $match, QUANT => $q, NGREED => $ng }, $class;
  113. }
  114.  
  115. sub text { "\\$_[0]{TEXT}" }
  116. sub type { 'slash' }
  117.  
  118.  
  119.  
  120. package YAPE::Regex::any;
  121.  
  122. sub new {
  123.   my ($class,$q,$ng) = @_;
  124.   bless { TEXT => '.', QUANT => $q, NGREED => $ng }, $class;
  125. }
  126.  
  127. sub type { 'any' }
  128.  
  129.  
  130.  
  131. package YAPE::Regex::class;
  132.  
  133. sub new {
  134.   my ($class,$match,$neg,$q,$ng) = @_;
  135.   bless { TEXT => $match, NEG => $neg, QUANT => $q, NGREED => $ng }, $class;
  136. }
  137.  
  138. sub text {
  139.     $_[0]{NEG} =~ /[pP]/ ?
  140.       "\\$_[0]{NEG}\{$_[0]{TEXT}\}" :
  141.       "[$_[0]{NEG}$_[0]{TEXT}]"
  142. }
  143. sub type { 'class' }
  144.  
  145.  
  146.  
  147. package YAPE::Regex::text;
  148.  
  149. sub new {
  150.   my ($class,$match,$q,$ng) = @_;
  151.   bless { TEXT => $match, QUANT => $q, NGREED => $ng }, $class;
  152. }
  153.  
  154. sub type { 'text' }
  155.  
  156.  
  157.  
  158. package YAPE::Regex::alt;
  159.  
  160. sub new { bless { NGREED => "", QUANT => "" }, $_[0] }
  161. sub text { '' }
  162. sub string { '|' }
  163. sub type { 'alt' }
  164.  
  165.  
  166.  
  167. package YAPE::Regex::comment;
  168.  
  169. sub new {
  170.   my ($class,$text,$X) = @_;
  171.   bless { TEXT => $text, XCOMM => $X }, $class;
  172. }
  173.  
  174. sub string { $_[0]{XCOMM} ? " # $_[0]{TEXT}" : "(?#$_[0]{TEXT})" }
  175. sub xcomm { $_[0]{XCOMM} }
  176. sub type { 'comment' }
  177.  
  178.  
  179.  
  180. package YAPE::Regex::whitespace;
  181.  
  182. sub new {
  183.   my ($class,$text) = @_;
  184.   bless { TEXT => $text }, $class;
  185. }
  186.  
  187. sub type { 'whitespace' }
  188. sub string { $_[0]{TEXT} }
  189.  
  190.  
  191.  
  192. package YAPE::Regex::flags;
  193.  
  194. sub new {
  195.   my ($class,$add,$sub) = @_;
  196.   my %mode = map { $_ => 1 } split //, $add ||= "";
  197.   delete @mode{split //, $sub ||= ""};
  198.   $add = join "", sort split //, $add;
  199.   $sub = join "", sort split //, $sub;
  200.   bless { MODE => \%mode, ON => $add, OFF => $sub }, $class;
  201. }
  202.  
  203. sub string { "(?$_[0]{ON}" . ($_[0]{OFF} && "-$_[0]{OFF}") . ')' }
  204. sub type { 'flags' }
  205.  
  206.  
  207.  
  208. package YAPE::Regex::cut;
  209.  
  210. sub new {
  211.   bless {
  212.     CONTENT => $_[1] || [],
  213.     QUANT => $_[2] || "",
  214.     NGREED => $_[3] || "",
  215.   }, $_[0]
  216. }
  217.  
  218. sub fullstring {
  219.   join "",
  220.     $_[0]->string,
  221.     map($_->fullstring, @{ $_[0]{CONTENT} }),
  222.     ")$_[0]{QUANT}$_[0]{NGREED}"
  223. }
  224.  
  225. sub string { '(?>' }
  226. sub type { 'cut' }
  227.  
  228.  
  229.  
  230. package YAPE::Regex::lookahead;
  231.  
  232. sub new { bless { POS => $_[1], CONTENT => $_[2] || [] }, $_[0] }
  233.  
  234. sub fullstring {
  235.   join "",
  236.     $_[0]->string,
  237.     map($_->fullstring, @{ $_[0]{CONTENT} }),
  238.     ')'
  239. }
  240.  
  241. sub string { '(?' . ('!','=')[$_[0]{POS}] }
  242. sub type { 'lookahead' }
  243. sub pos { $_[0]{POS} }
  244.  
  245.  
  246.  
  247. package YAPE::Regex::lookbehind;
  248.  
  249. sub new { bless { POS => $_[1], CONTENT => $_[2] || [] }, $_[0] }
  250.  
  251. sub fullstring {
  252.   join "",
  253.     $_[0]->string,
  254.     map($_->fullstring, @{ $_[0]{CONTENT} }),
  255.     ')'
  256. }
  257.  
  258. sub string { '(?<' . ('!','=')[$_[0]{POS}] }
  259. sub type { 'lookbehind' }
  260. sub pos { $_[0]{POS} }
  261.  
  262.  
  263.  
  264. package YAPE::Regex::conditional;
  265.  
  266. sub new {
  267.   bless {
  268.     OPTS => 1,
  269.     CONTENT => $_[1] || [],
  270.     TRUE => $_[2] || [],
  271.     FALSE => $_[3] || [],
  272.     QUANT => $_[4] || "",
  273.     NGREED => $_[5] || "",
  274.   }, $_[0];
  275. }
  276.  
  277. sub fullstring {
  278.   join "",
  279.     $_[0]->string,
  280.     map($_->fullstring, @{ $_[0]{TRUE} }),
  281.     $_[0]{OPTS} == 2 ? (
  282.       '|', map($_->fullstring, @{ $_[0]{FALSE} }),
  283.     ) : (),
  284.     ")$_[0]{QUANT}$_[0]{NGREED}";
  285. }
  286.  
  287. sub string {
  288.   '(?' . (ref $_[0]{CONTENT} ?
  289.     $_[0]{CONTENT}[0]->fullstring :
  290.     "($_[0]{CONTENT})"
  291.   )
  292. }
  293. sub backref { $_[0]{CONTENT} }
  294. sub type { 'cond' }
  295.  
  296.  
  297.  
  298. package YAPE::Regex::group;
  299.  
  300. sub new {
  301.   my $on = join "", sort split //, $_[1] || "";
  302.   my $off = join "", sort split //, $_[2] || "";
  303.   bless {
  304.     ON => $on,
  305.     OFF => $off,
  306.     CONTENT => $_[3] || [],
  307.     QUANT => $_[4] || "",
  308.     NGREED => $_[5] || "",
  309.   }, $_[0]
  310. }
  311.  
  312. sub fullstring {
  313.   join "",
  314.     $_[0]->string,
  315.     map($_->fullstring, @{ $_[0]{CONTENT} }),
  316.     ")$_[0]{QUANT}$_[0]{NGREED}"
  317. }
  318. sub string { $_[0]{OFF} ? "(?$_[0]{ON}-$_[0]{OFF}:" : "(?$_[0]{ON}:" }
  319. sub type { 'group' }
  320.  
  321.  
  322.  
  323. package YAPE::Regex::capture;
  324.  
  325. sub new {
  326.   bless {
  327.     CONTENT => $_[1] || [],
  328.     QUANT => $_[2] || "",
  329.     NGREED => $_[3] || "",
  330.   }, $_[0]
  331. }
  332.  
  333. sub fullstring {
  334.   join "",
  335.     $_[0]->string,
  336.     map($_->fullstring, @{ $_[0]{CONTENT} }),
  337.     ")$_[0]{QUANT}$_[0]{NGREED}"
  338. }
  339.  
  340. sub string { '(' }
  341. sub type { 'capture' }
  342.  
  343.  
  344.  
  345. package YAPE::Regex::code;
  346.  
  347. sub new { bless { CONTENT => $_[1], QUANT => "", NGREED => "", }, $_[0] }
  348. sub text { "(?$_[0]{CONTENT})" }
  349. sub type { 'code' }
  350.  
  351.  
  352.  
  353. package YAPE::Regex::later;
  354.  
  355. sub new { bless { CONTENT => $_[1], QUANT => "", NGREED => "", }, $_[0] }
  356. sub text { "(??$_[0]{CONTENT})" }
  357. sub type { 'later' }
  358.  
  359.  
  360.  
  361. package YAPE::Regex::close;
  362.  
  363. sub new { bless { QUANT => $_[1] || "", NGREED => $_[2] || "" }, $_[0] }
  364. sub string { ")$_[0]{QUANT}$_[0]{NGREED}" }
  365. sub type { 'close' }
  366.  
  367.  
  368. 1;
  369.  
  370. __END__
  371.  
  372. =head1 NAME
  373.  
  374. YAPE::Regex::Element - sub-classes for YAPE::Regex elements
  375.  
  376. =head1 SYNOPSIS
  377.  
  378.   use YAPE::Regex 'MyExt::Mod';
  379.   # this sets up inheritence in MyExt::Mod
  380.   # see YAPE::Regex documentation
  381.  
  382. =head1 C<YAPE> MODULES
  383.  
  384. The C<YAPE> hierarchy of modules is an attempt at a unified means of parsing
  385. and extracting content.  It attempts to maintain a generic interface, to
  386. promote simplicity and reusability.  The API is powerful, yet simple.  The
  387. modules do tokenization (which can be intercepted) and build trees, so that
  388. extraction of specific nodes is doable.
  389.  
  390. =head1 DESCRIPTION
  391.  
  392. This module provides the classes for the C<YAPE::Regex> objects.  The base
  393. class for these objects is C<YAPE::Regex::Element>.  The objects classes are
  394. numerous.
  395.  
  396. =head2 Methods for C<YAPE::Regex::Element>
  397.  
  398. This class contains fallback methods for the other classes.
  399.  
  400. =over 4
  401.  
  402. =item * C<my $str = $obj-E<gt>text;>
  403.  
  404. Returns a string representation of the content of the regex node I<itself>, not
  405. any nodes contained in it.  This is C<undef> for non-text nodes.
  406.  
  407. =item * C<my $str = $obj-E<gt>string;>
  408.  
  409. Returns a string representation of the regex node I<itself>, not any nodes
  410. contained in it.
  411.  
  412. =item * C<my $str = $obj-E<gt>fullstring;>
  413.  
  414. Returns a string representation of the regex node, including any nodes contained
  415. in it.
  416.  
  417. =item * C<my $quant = $obj-E<gt>quant;>
  418.  
  419. Returns a string with the quantity, and a C<?> if the node is non-greedy.  The
  420. quantity is one of C<*>, C<+>, C<?>, C<{I<M>,I<N>}>, or an empty string.
  421.  
  422. =item * C<my $ng = $obj-E<gt>ngreed;>
  423.  
  424. Returns a C<?> if the node is non-greedy, and an empty string otherwise.
  425.  
  426. =back
  427.  
  428. =head2 Methods for C<YAPE::Regex::anchor>
  429.  
  430. This class represents anchors.  Objects have the following methods:
  431.  
  432. =over 4
  433.  
  434. =item * C<my $anchor = YAPE::Regex::anchor-E<gt>new($type,$q,$ng);>
  435.  
  436. Creates a C<YAPE::Regex::anchor> object.  Takes three arguments:  the anchor
  437. (C<^>, C<\A>, C<$>, C<\Z>, C<\z>, C<\B>, C<\b>, or C<\G>), the quantity, and
  438. the non-greedy flag.  The quantity I<should> be an empty string.
  439.  
  440.   my $anc = YAPE::Regex::anchor->new('\A', '', '?');
  441.   # /\A?/
  442.  
  443. =item * C<my $type = $anchor-E<gt>type;>
  444.  
  445. Returns the string C<anchor>.
  446.  
  447. =back
  448.  
  449. =head2 Methods for C<YAPE::Regex::macro>
  450.  
  451. This class represents character-class macros.  Objects have the following
  452. methods:
  453.  
  454. =over 4
  455.  
  456. =item * C<my $macro = YAPE::Regex::macro-E<gt>new($type,$q,$ng);>
  457.  
  458. Creates a C<YAPE::Regex::macro> object.  Takes three arguments:  the macro
  459. (C<w>, C<W>, C<d>, C<D>, C<s>, or C<S>), the quantity, and the non-greedy
  460. flag.
  461.  
  462.   my $macro = YAPE::Regex::macro->new('s', '{3,5}');
  463.   # /\s{3,5}/
  464.  
  465. =item * C<my $text = $macro-E<gt>text;>
  466.  
  467. Returns the macro.
  468.  
  469.   print $macro->text;  # '\s'
  470.  
  471. =item * C<my $type = $macro-E<gt>type;>
  472.  
  473. Returns the string C<macro>.
  474.  
  475. =back
  476.  
  477. =head2 Methods for C<YAPE::Regex::oct>
  478.  
  479. This class represents octal escapes.  Objects have the following methods:
  480.  
  481. =over 4
  482.  
  483. =item * C<my $oct = YAPE::Regex::oct-E<gt>new($type,$q,$ng);>
  484.  
  485. Creates a C<YAPE::Regex::oct> object.  Takes three arguments:  the octal number
  486. (as a string), the quantity, and the non-greedy flag.
  487.  
  488.   my $oct = YAPE::Regex::oct->new('040');
  489.   # /\040/
  490.  
  491. =item * C<my $text = $oct-E<gt>text;>
  492.  
  493. Returns the octal escape.
  494.  
  495.   print $oct->text;  # '\040'
  496.  
  497. =item * C<my $type = $oct-E<gt>type;>
  498.  
  499. Returns the string C<oct>.
  500.  
  501. =back
  502.  
  503. =head2 Methods for C<YAPE::Regex::hex>
  504.  
  505. This class represents hexadecimal escapes.  Objects have the following methods:
  506.  
  507. =over 4
  508.  
  509. =item * C<my $hex = YAPE::Regex::hex-E<gt>new($type,$q,$ng);>
  510.  
  511. Creates a C<YAPE::Regex::hex> object.  Takes three arguments:  the hexadecimal
  512. number (as a string), the quantity, and the non-greedy flag.
  513.  
  514.   my $hex = YAPE::Regex::hex->new('20','{2,}');
  515.   # /\x20{2,}/
  516.  
  517. =item * C<my $text = $hex-E<gt>text;>
  518.  
  519. Returns the hexadecimal escape.
  520.  
  521.   print $hex->text;  # '\x20'
  522.  
  523. =item * C<my $type = $hex-E<gt>type;>
  524.  
  525. Returns the string C<hex>.
  526.  
  527. =back
  528.  
  529. =head2 Methods for C<YAPE::Regex::utf8hex>
  530.  
  531. This class represents UTF hexadecimal escapes.  Objects have the following
  532. methods:
  533.  
  534. =over 4
  535.  
  536. =item * C<my $hex = YAPE::Regex::utf8hex-E<gt>new($type,$q,$ng);>
  537.  
  538. Creates a C<YAPE::Regex::utf8hex> object.  Takes three arguments:  the
  539. hexadecimal number (as a string), the quantity, and the non-greedy flag.
  540.  
  541.   my $utf8hex = YAPE::Regex::utf8hex->new('beef','{0,4}');
  542.   # /\x{beef}{2,}/
  543.  
  544. =item * C<my $text = $utf8hex-E<gt>text;>
  545.  
  546. Returns the hexadecimal escape.
  547.  
  548.   print $utf8hex->text;  # '\x{beef}'
  549.  
  550. =item * C<my $type = $utf8hex-E<gt>type;>
  551.  
  552. Returns the string C<utf8hex>.
  553.  
  554. =back
  555.  
  556. =head2 Methods for C<YAPE::Regex::backref>
  557.  
  558. This class represents back-references.  Objects have the following methods:
  559.  
  560. =over 4
  561.  
  562. =item * C<my $bref = YAPE::Regex::bref-E<gt>new($type,$q,$ng);>
  563.  
  564. Creates a C<YAPE::Regex::bref> object.  Takes three arguments:  the number of
  565. the back-reference, the quantity, and the non-greedy flag.
  566.  
  567.   my $bref = YAPE::Regex::bref->new(2,'','?');
  568.   # /\2?/
  569.  
  570. =item * C<my $text = $bref-E<gt>text;>
  571.  
  572. Returns the backescape.
  573.  
  574.   print $bref->text;  # '\2'
  575.  
  576. =item * C<my $type = $bref-E<gt>type;>
  577.  
  578. Returns the string C<backref>.
  579.  
  580. =back
  581.  
  582. =head2 Methods for C<YAPE::Regex::ctrl>
  583.  
  584. This class represents control character escapes.  Objects have the following
  585. methods:
  586.  
  587. =over 4
  588.  
  589. =item * C<my $ctrl = YAPE::Regex::ctrl-E<gt>new($type,$q,$ng);>
  590.  
  591. Creates a C<YAPE::Regex::ctrl> object.  Takes three arguments:  the control
  592. character, the quantity, and the non-greedy flag.
  593.  
  594.   my $ctrl = YAPE::Regex::ctrl->new('M');
  595.   # /\cM/
  596.  
  597. =item * C<my $text = $ctrl-E<gt>text;>
  598.  
  599. Returns the control character escape.
  600.  
  601.   print $ctrl->text;  # '\cM'
  602.  
  603. =item * C<my $type = $ctrl-E<gt>type;>
  604.  
  605. Returns the string C<ctrl>.
  606.  
  607. =back
  608.  
  609. =head2 Methods for C<YAPE::Regex::named>
  610.  
  611. This class represents named characters.  Objects have the following methods:
  612.  
  613. =over 4
  614.  
  615. =item * C<my $ctrl = YAPE::Regex::named-E<gt>new($type,$q,$ng);>
  616.  
  617. Creates a C<YAPE::Regex::named> object.  Takes three arguments:  the name of the
  618. character, the quantity, and the non-greedy flag.
  619.  
  620.   my $named = YAPE::Regex::named->new('GREEK SMALL LETTER BETA');
  621.   # /\N{GREEK SMALL LETTER BETA}/
  622.  
  623. =item * C<my $text = $named-E<gt>text;>
  624.  
  625. Returns the character escape text.
  626.  
  627.   print $named->text;  # '\N{GREEK SMALL LETTER BETA}'
  628.  
  629. =item * C<my $type = $named-E<gt>type;>
  630.  
  631. Returns the string C<named>.
  632.  
  633. =back
  634.  
  635. =head2 Methods for C<YAPE::Regex::Cchar>
  636.  
  637. This class represents C characters.  Objects have the following methods:
  638.  
  639. =over 4
  640.  
  641. =item * C<my $ctrl = YAPE::Regex::Cchar-E<gt>new($q,$ng);>
  642.  
  643. Creates a C<YAPE::Regex::Cchar> object.  Takes two arguments:  the quantity and
  644. the non-greedy flag.
  645.  
  646.   my $named = YAPE::Regex::Char->new(2);
  647.   # /\C{2}/
  648.  
  649. =item * C<my $text = $Cchar-E<gt>text;>
  650.  
  651. Returns the escape sequence.
  652.  
  653.   print $Cchar->text;  # '\C'
  654.  
  655. =item * C<my $type = $Cchar-E<gt>type;>
  656.  
  657. Returns the string C<Cchar>.
  658.  
  659. =back
  660.  
  661. =head2 Methods for C<YAPE::Regex::slash>
  662.  
  663. This class represents any other escaped characters.  Objects have the following
  664. methods:
  665.  
  666. =over 4
  667.  
  668. =item * C<my $slash = YAPE::Regex::slash-E<gt>new($type,$q,$ng);>
  669.  
  670. Creates a C<YAPE::Regex::slash> object.  Takes three arguments:  the backslashed
  671. character, the quantity, and the non-greedy flag.
  672.  
  673.   my $slash = YAPE::Regex::slash->new('t','','?');
  674.   # /\t?/
  675.  
  676. =item * C<my $text = $slash-E<gt>text;>
  677.  
  678. Returns the escaped character.
  679.  
  680.   print $slash->text;  # '\t'
  681.  
  682. =item * C<my $type = $slash-E<gt>type;>
  683.  
  684. Returns the string C<slash>.
  685.  
  686. =back
  687.  
  688. =head2 Methods for C<YAPE::Regex::any>
  689.  
  690. This class represents the dot metacharacter.  Objects have the following methods:
  691.  
  692. =over 4
  693.  
  694. =item * C<my $any = YAPE::Regex::any-E<gt>new($q,$ng);>
  695.  
  696. Creates a C<YAPE::Regex::any> object.  Takes two arguments:  the quantity, and
  697. the non-greedy flag.
  698.  
  699.   my $any = YAPE::Regex::any->new('{1,3}');
  700.   # /.{1,3}/
  701.  
  702. =item * C<my $type = $any-E<gt>type;>
  703.  
  704. Returns the string C<any>.
  705.  
  706. =back
  707.  
  708. =head2 Methods for C<YAPE::Regex::class>
  709.  
  710. This class represents character classes.  Objects have the following methods:
  711.  
  712. =over 4
  713.  
  714. =item * C<my $class = YAPE::Regex::class-E<gt>new($chars,$neg,$q,$ng);>
  715.  
  716. Creates a C<YAPE::Regex::class> object.  Takes four arguments:  the characters
  717. in the class, a C<^> if the class is negated (an empty string otherwise), the
  718. quantity, and the non-greedy flag.
  719.  
  720.   my $class = YAPE::Regex::class->new('aeiouy','^');
  721.   # /[^aeiouy]/
  722.  
  723. =item * C<my $text = $class-E<gt>text;>
  724.  
  725. Returns the character class.
  726.  
  727.   print $class->text;  # [^aeiouy]
  728.  
  729. =item * C<my $type = $class-E<gt>type;>
  730.  
  731. Returns the string C<class>.
  732.  
  733. =back
  734.  
  735. =head2 Methods for C<YAPE::Regex::hex>
  736.  
  737. This class represents hexadecimal escapes.  Objects have the following methods:
  738.  
  739. =over 4
  740.  
  741. =item * C<my $text = YAPE::Regex::text-E<gt>new($text,$q,$ng);>
  742.  
  743. Creates a C<YAPE::Regex::text> object.  Takes three arguments:  the text, the
  744. quantity, and the non-greedy flag.  The quantity and non-greedy modifier should
  745. only be present for I<single-character> text, because of the way the parser
  746. renders the quantity and non-greedy modifier.
  747.  
  748.   my $text = YAPE::Regex::text->new('alphabet','');
  749.   # /alphabet/
  750.   
  751.   my $text = YAPE::Regex::text->new('x','?','?');
  752.   # /x??/
  753.  
  754. =item * C<my $type = $text-E<gt>type;>
  755.  
  756. Returns the string C<text>.
  757.  
  758. =back
  759.  
  760. =head2 Methods for C<YAPE::Regex::alt>
  761.  
  762. This class represents alternation.  Objects have the following methods:
  763.  
  764. =over 4
  765.  
  766. =item * C<my $alt = YAPE::Regex::alt-E<gt>new;>
  767.  
  768. Creates a C<YAPE::Regex::alt> object.
  769.  
  770.   my $alt = YAPE::Regex::alt->new;
  771.   # /|/
  772.  
  773. =item * C<my $type = $oct-E<gt>type;>
  774.  
  775. Returns the string C<alt>.
  776.  
  777. =back
  778.  
  779. =head2 Methods for C<YAPE::Regex::comment>
  780.  
  781. This class represents in-line comments.  Objects have the following methods:
  782.  
  783. =over 4
  784.  
  785. =item * C<my $comment = YAPE::Regex::comment-E<gt>new($comment,$x);>
  786.  
  787. Creates a C<YAPE::Regex::comment> object.  Takes two arguments:  the text of the
  788. comment, and whether or not the C</x> regex modifier is in effect for this
  789. comment.  Note that Perl's regex engine will stop a C<(?#...)> comment at the
  790. first C<)>, regardless of what you do.
  791.  
  792.   my $comment = YAPE::Regex::comment->new(
  793.     "match an optional string of digits"
  794.   );
  795.   # /(?#match an optional string of digits)/
  796.  
  797.   my $comment = YAPE::Regex::comment->new(
  798.     "match an optional string of digits",
  799.     1
  800.   );
  801.   # /# match an optional string of digits/
  802.  
  803. =item * C<my $type = $comment-E<gt>type;>
  804.  
  805. Returns the string C<comment>.
  806.  
  807. =item * C<my $x_on = $comment-E<gt>xcomm;>
  808.  
  809. Returns true or false, depending on whether the comment is under the C</x> regex
  810. modifier.
  811.  
  812. =back
  813.  
  814. =head2 Methods for C<YAPE::Regex::whitespace>
  815.  
  816. This class represents whitespace under the C</x> regex modifier.  Objects have
  817. the following methods:
  818.  
  819. =over 4
  820.  
  821. =item * C<my $ws = YAPE::Regex::whitespace-E<gt>new($text);>
  822.  
  823. Creates a C<YAPE::Regex::whitespace> object.  Takes one argument:  the text of
  824. the whitespace.
  825.  
  826.   my $ws = YAPE::Regex::whitespace->new('  ');
  827.   # /  /x
  828.  
  829. =item * C<my $text = $ws-E<gt>text;>
  830.  
  831. Returns the whitespace.
  832.  
  833.   print $ws->text;  # '  '
  834.  
  835. =item * C<my $type = $ws-E<gt>type;>
  836.  
  837. Returns the string C<whitespace>.
  838.  
  839. =back
  840.  
  841. =head2 Methods for C<YAPE::Regex::flags>
  842.  
  843. This class represents C<(?ismx)> flags.  Objects have the following methods:
  844.  
  845. =over 4
  846.  
  847. =item * C<my $flags = YAPE::Regex::flags-E<gt>new($add,$sub);>
  848.  
  849. Creates a C<YAPE::Regex::flags> object.  Takes two arguments:  a string of the
  850. modes to have on, and a string of the modes to explicitly turn off.  The flags
  851. are displayed in alphabetical order.
  852.  
  853.   my $flags = YAPE::Regex::flags->new('is','m');
  854.   # /(?is-m)/
  855.  
  856. =item * C<my $type = $flags-E<gt>type;>
  857.  
  858. Returns the string C<flags>.
  859.  
  860. =back
  861.  
  862. =head2 Methods for C<YAPE::Regex::cut>
  863.  
  864. This class represents the cut assertion.  Objects have the following methods:
  865.  
  866. =over 4
  867.  
  868. =item * C<my $look = YAPE::Regex::cut-E<gt>new(\@nodes);>
  869.  
  870. Creates a C<YAPE::Regex::cut> object.  Takes one arguments:  a reference to an
  871. array of objects to be contained in the cut.
  872.  
  873.   my $REx = YAPE::Regex::class->new('aeiouy','','+');
  874.   my $look = YAPE::Regex::cut->new(0,[$REx]);
  875.   # /(?>[aeiouy]+)/
  876.  
  877. =item * C<my $type = $cut-E<gt>type;>
  878.  
  879. Returns the string C<cut>.
  880.  
  881. =back
  882.  
  883. =head2 Methods for C<YAPE::Regex::lookahead>
  884.  
  885. This class represents lookaheads.  Objects have the following methods:
  886.  
  887. =over 4
  888.  
  889. =item * C<my $look = YAPE::Regex::lookahead-E<gt>new($pos,\@nodes);>
  890.  
  891. Creates a C<YAPE::Regex::lookahead> object.  Takes two arguments:  a boolean
  892. value indicating whether or not the lookahead is positive, and a reference to an
  893. array of objects to be contained in the lookahead.
  894.  
  895.   my $REx = YAPE::Regex::class->new('aeiouy');
  896.   my $look = YAPE::Regex::lookahead->new(0,[$REx]);
  897.   # /(?![aeiouy])/
  898.  
  899. =item * C<my $pos = $look-E<gt>pos;>
  900.  
  901. Returns true if the lookahead is positive.
  902.  
  903.   print $look->pos ? 'pos' : 'neg';  # 'neg'
  904.  
  905. =item * C<my $type = $look-E<gt>type;>
  906.  
  907. Returns the string C<lookahead(pos)> or C<lookahead(neg)>.
  908.  
  909. =back
  910.  
  911. =head2 Methods for C<YAPE::Regex::lookbehind>
  912.  
  913. This class represents lookbehinds.  Objects have the following methods:
  914.  
  915. =over 4
  916.  
  917. =item * C<my $look = YAPE::Regex::lookbehind-E<gt>new($pos,\@nodes);>
  918.  
  919. Creates a C<YAPE::Regex::lookbehind> object.  Takes two arguments:  a boolean
  920. value indicating whether or not the lookbehind is positive, and a reference to
  921. an array of objects to be contained in the lookbehind.
  922.  
  923.   my $REx = YAPE::Regex::class->new('aeiouy','^');
  924.   my $look = YAPE::Regex::lookbehind->new(1,[$REx]);
  925.   # /(?<=[^aeiouy])/
  926.  
  927. =item * C<my $pos = $look-E<gt>pos;>
  928.  
  929. Returns true if the lookbehind is positive.
  930.  
  931.   print $look->pos ? 'pos' : 'neg';  # 'pos'
  932.  
  933. =item * C<my $type = $look-E<gt>type;>
  934.  
  935. Returns the string C<lookbehind(pos)> or C<lookbehind(neg)>.
  936.  
  937. =back
  938.  
  939. =head2 Methods for C<YAPE::Regex::conditional>
  940.  
  941. This class represents conditionals.  Objects have the following methods:
  942.  
  943. =over 4
  944.  
  945. =item * C<my $cond = YAPE::Regex::conditional-E<gt>new($br,$t,$f,$q,$ng);>
  946.  
  947. Creates a C<YAPE::Regex::hex> object.  Takes five arguments:  the number of the
  948. back-reference (that's all that's supported in the current version), an array
  949. reference to the "true" pattern, an array reference to the "false" pattern, and
  950. the quantity and non-greedy flag.
  951.  
  952.   my $cond = YAPE::Regex::conditional->new(
  953.     2,
  954.     [],
  955.     [ YAPE::Regex::text->new('foo') ],
  956.     '?',
  957.   );
  958.   # /(?(2)|foo)?/
  959.  
  960. =item * C<my $br = $cond-E<gt>backref;>
  961.  
  962. Returns the number of the back-reference the conditional depends on.
  963.  
  964.   print $br->backref;  # 2
  965.  
  966. =item * C<my $type = $cond-E<gt>type;>
  967.  
  968. Returns the string C<conditional(I<N>)>, where I<N> is the number of the
  969. back-reference.
  970.  
  971. =back
  972.  
  973. =head2 Methods for C<YAPE::Regex::group>
  974.  
  975. This class represents non-capturing groups.  Objects have the following methods:
  976.  
  977. =over 4
  978.  
  979. =item * C<my $group = YAPE::Regex::group-E<gt>new($on,$off,\@nodes,$q,$ng);>
  980.  
  981. Creates a C<YAPE::Regex::group> object.  Takes five arguments:  the modes turned
  982. on, the modes explicitly turned off, a reference to an array of objects in the
  983. group, the quantity, and the non-greedy flag.  The modes are displayed in
  984. alphabetical order.
  985.  
  986.   my $group = YAPE::Regex::group->new(
  987.     'i',
  988.     's',
  989.     [
  990.       YAPE::Regex::macro->new('d', '{2}'),
  991.       YAPE::Regex::macro->new('s'),
  992.       YAPE::Regex::macro->new('d', '{2}'),
  993.     ],
  994.     '?',
  995.   );
  996.   # /(?i-s:\d{2}\s\d{2})?/
  997.  
  998. =item * C<my $type = $group-E<gt>type;>
  999.  
  1000. Returns the string C<group>.
  1001.  
  1002. =back
  1003.  
  1004. =head2 Methods for C<YAPE::Regex::capture>
  1005.  
  1006. This class represents capturing groups.  Objects have the following methods:
  1007.  
  1008. =over 4
  1009.  
  1010. =item * C<my $capture = YAPE::Regex::capture-E<gt>new(\@nodes,$q,$ng);>
  1011.  
  1012. Creates a C<YAPE::Regex::capture> object.  Takes three arguments:  a reference
  1013. to an array of objects in the group, the quantity, and the non-greedy flag.
  1014.  
  1015.   my $capture = YAPE::Regex::capture->new(
  1016.     [
  1017.       YAPE::Regex::macro->new('d', '{2}'),
  1018.       YAPE::Regex::macro->new('s'),
  1019.       YAPE::Regex::macro->new('d', '{2}'),
  1020.     ],
  1021.   );
  1022.   # /(\d{2}\s\d{2})/
  1023.  
  1024. =item * C<my $type = $capture-E<gt>type;>
  1025.  
  1026. Returns the string C<capture>.
  1027.  
  1028. =back
  1029.  
  1030. =head2 Methods for C<YAPE::Regex::code>
  1031.  
  1032. This class represents code blocks.  Objects have the following methods:
  1033.  
  1034. =over 4
  1035.  
  1036. =item * C<my $code = YAPE::Regex::code-E<gt>new($block);>
  1037.  
  1038. Creates a C<YAPE::Regex::code> object.  Takes one arguments:  a string holding
  1039. a block of code.
  1040.  
  1041.   my $code = YAPE::Regex::code->new(q({ push @poss, $1 }));
  1042.   # /(?{ push @poss, $1 })/
  1043.  
  1044. =item * C<my $type = $code-E<gt>type;>
  1045.  
  1046. Returns the string C<code>.
  1047.  
  1048. =back
  1049.  
  1050. =head2 Methods for C<YAPE::Regex::later>
  1051.  
  1052. This class represents closed parentheses.  Objects have the following methods:
  1053.  
  1054. =over 4
  1055.  
  1056. =item * C<my $later = YAPE::Regex::later-E<gt>new($block);>
  1057.  
  1058. Creates a C<YAPE::Regex::later> object.  Takes one arguments:  a string holding
  1059. a block of code.
  1060.  
  1061.   my $later = YAPE::Regex::later->new(q({ push @poss, $1 }));
  1062.   # /(?{{ push @poss, $1 }})/
  1063.  
  1064. =item * C<my $type = $later-E<gt>type;>
  1065.  
  1066. Returns the string C<later>.
  1067.  
  1068. =back
  1069.  
  1070. =head2 Methods for C<YAPE::Regex::close>
  1071.  
  1072. This class represents closed parentheses.  Objects have the following methods:
  1073.  
  1074. =over 4
  1075.  
  1076. =item * C<my $close = YAPE::Regex::close-E<gt>new($q,$ng);>
  1077.  
  1078. Creates a C<YAPE::Regex::close> object.  Takes two arguments:  the quantity, and
  1079. the non-greedy flag.  This object is never needed in the tree; however, they are
  1080. returned in the parsing stage, so that you know when they've been reached.
  1081.  
  1082.   my $close = YAPE::Regex::close->new('?','?');
  1083.   # /)??/
  1084.  
  1085. =item * C<my $type = $close-E<gt>type;>
  1086.  
  1087. Returns the string C<close>.
  1088.  
  1089. =back
  1090.  
  1091. =head1 TO DO
  1092.  
  1093. This is a listing of things to add to future versions of this module.
  1094.  
  1095. =over 4
  1096.  
  1097. =item * None!
  1098.  
  1099. =back
  1100.  
  1101. =head1 BUGS
  1102.  
  1103. Following is a list of known or reported bugs.
  1104.  
  1105. =over 4
  1106.  
  1107. =item * This documentation might be incomplete.
  1108.  
  1109. =back
  1110.  
  1111. =head1 SUPPORT
  1112.  
  1113. Visit C<YAPE>'s web site at F<http://www.pobox.com/~japhy/YAPE/>.
  1114.  
  1115. =head1 SEE ALSO
  1116.  
  1117. The C<YAPE::Regex> documentation, for information on the main class.
  1118.  
  1119. =head1 AUTHOR
  1120.  
  1121.   Jeff "japhy" Pinyan
  1122.   CPAN ID: PINYAN
  1123.   japhy@pobox.com
  1124.   http://www.pobox.com/~japhy/
  1125.  
  1126. =cut
  1127.