Regexp-Assemble-0.38/0000755000175000017500000000000013122055201012574 5ustar ronronRegexp-Assemble-0.38/examples/0000755000175000017500000000000013122055201014412 5ustar ronronRegexp-Assemble-0.38/examples/naive0000755000175000017500000000270311022301342015441 0ustar ronron#! /usr/local/bin/perl -w # # naive - generate a regular expression that will lex regular expressions # it is naive in the sense that it can't lex certain patterns, such as a # pattern that contains nested parentheses (e.g. /ab(?:cd(?ef)?gh)+ij/ ) # # The emitted regular expression is the default pattern that Regexp::Assemble # uses to pick apart a string into tokens suitable for being assembled. If it # isn't sufficiently sophisticated, you will have to supply your own lexer. # # Copyright (C) David Landgren 2004-2005 use strict; my $directive = q{[bABCEGLQUXZ]}; my $punct = q{[^\\w]}; my $meta = q{[aefnrtdDwWsS]}; my $ctrl = q{c.}; my $octal = q{0\\d{2}}; my $hex = q{x(?:[\\da-fA-F]{2}|{[\\da-fA-F]{4}})}; my $named = q{N\\{\w+\\}}; my $prop = q{[Pp](?:\\{\w+\\}|.)}; my $single = q{[^\\w\\/{|}-]}; my $modifiable = qq{$punct|$meta|$ctrl|$octal|$hex|$named|$prop}; my $modifier = q{(?:[*+?]\\??|\\{\\d+(?:,\\d*)?\\}\\??)?}; my $backslash = qq{\\\\(?:$directive|[lu].|(?:$modifiable)$modifier)}; my $class = q{\\[.*?(?new->add( qw[ fee fie foe fum ] ); while( ) { chomp; if( /($re)/ ) { print "Here be giants: $1\n"; } } print $re->as_string, "\n"; __DATA__ feedbag airfield foe fumble blorp Regexp-Assemble-0.38/examples/debugging0000755000175000017500000000550611022301342016276 0ustar ronron#! /usr/bin/perl -w # # debugging - strategies for dealing with assembled patterns that # cannot be compiled. Usual message is # "Unmatched ( in regex; marked by <-- HERE in m/a( <-- HERE" # # Copyright (C) David Landgren 2005 use strict; use Getopt::Std; use Regexp::Assemble; use vars '$VERSION'; $VERSION = '0.1'; getopts( 'v', \my %opt ); print "$VERSION\n" and exit if $opt{v}; my $r = Regexp::Assemble->new; while( <> ) { chomp; # take a copy of the assembly and add the next pattern my $clone = $r->clone; $clone->add($_); # if we compile the regexp, does it blow up? eval { my $regexp = $clone->re }; # it blew up if( $@ ) { report(); } else { # ok, now add it for real to the assembly $r->add( $_ ); } } sub report { my $lsqb = $_ =~ tr/[/[/; my $rsqb = $_ =~ tr/]/]/; my $lpar = $_ =~ tr/(/(/; my $rpar = $_ =~ tr/)/)/; warn < file-of-patterns =head1 OPTIONS =over 5 =item B<-v> prints out the version of script. =back =head1 DESCRIPTION By default, C uses a naive strategy for chopping up input. It can get upset if you try to feed it a pattern with nested parentheses. For instance, C and C will cause it to fail. If you really want to do that, you'll have to come up with a regexp that can chop the above into C, C<(b(c))> and C, C<(b(d))>. Of course, that will only buy you C at the present time. Teaching it to produce C would be considerably more complex. Patches welcome. So, when adding hundreds of patterns, it's not always obvious figuring out a way of isolating the offending pattern, especially when they are coming out of a file or some other process you don't have control over. The trick, then, consists of adding a pattern one at a time, and then standing back and watching whether producing a regexp from the list of patterns seen so far will cause things to blow up. So you take a copy of the assembly, and add the pattern to the copy. If that works, then add it to the real assembly. Repeat until done. You don't want to do this all the time, because it is of course much less efficient. =head1 SEE ALSO L =head1 AUTHOR Copyright (C) 2005 David Landgren. All rights reserved. =head1 LICENSE This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Regexp-Assemble-0.38/examples/file.10000644000175000017500000000002411022301342015404 0ustar ronronsang sing song sung Regexp-Assemble-0.38/examples/unquotemeta0000644000175000017500000000061311022301342016701 0ustar ronron#! /usr/bin/perl # # unquotemeta - how to fix up quotemeta # # part of the Regexp::Assemble module # David Landgren, copyright (c) 2005 use strict; for my $ord( 0 .. 255 ) { my $ch = chr($ord); my $qm = quotemeta($ch); my $fix = fixup($qm); print "o=$ord c=$ch q=$qm f=$fix\n"; } sub fixup { my $ch = shift; $ch =~ s/^\\([^-\w$()*+.\/?@\[\\\]^{|}])$/$1/; $ch; } Regexp-Assemble-0.38/examples/hostmatch/0000755000175000017500000000000013122055201016404 5ustar ronronRegexp-Assemble-0.38/examples/hostmatch/good.canonical0000644000175000017500000000175711022301342021214 0ustar ronronmail.merlin.atlantis.co.ac smtp4.sms.ac smtp7.sms.ac domail1.emirates.net.ae avas-mr09.fibertel.com.ar avas-mr10.fibertel.com.ar cumeil9.prima.com.ar mail.tisa-sistemas.com.ar cabel243b.bkf.at viefep11-int.chello.at viefep12-int.chello.at viefep15-int.chello.at viefep18-int.chello.at viefep19-int.chello.at static81-223-147-187.xdsl-line.inode.at 83-64-139-186.work.xdsl-line.inode.at chello213047128247.15.vie.surfer.at cust170.120.nw.tplus.at mail1.acnielsen.com.au mail.gtlaw.com.au orcus.its.uow.edu.au smtprelay.intellicentre.net.au 201.c.002.mel.iprimus.net.au smtp02.syd.iprimus.net.au s089c.static.pacific.net.au webmail3.onatel.bf aktor1.adeli.biz ns1.cheznous.biz w7.creditland.biz ns1.gazduire.biz mail2.hitechpros.biz relay.link2biz.biz mx2.wendhlp.biz mx2.wowie.biz mail2.comdominio.com.br pn41.neoline.com.br sv6.srnet.com.br cacheflow.sul.com.br itajuba.terra.com.br itaparica.terra.com.br itapoa.terra.com.br smtpout3.uol.com.br smtpout6.uol.com.br web6.vanet.com.br ricardo.adm.ita.cta.br Regexp-Assemble-0.38/examples/hostmatch/hostmatch0000755000175000017500000001322011022301342020317 0ustar ronron#! /usr/local/bin/perl -w # # hostmatch -- determine whether a DNS hostname matches a regular expression # use strict; use Regexp::Assemble; my $ra = Regexp::Assemble->new(chomp=>1)->add( ); open GOOD, '>good.out' or die "Cannot open good.out for output: $!\n"; open BAD, '>bad.out' or die "Cannot open bad.out for output: $!\n"; my( $good, $bad ) = (0, 0); while( <> ) { chomp; if( /^$ra$/ ) { ++$bad; } else { print GOOD "$_\n"; ++$good; } } close GOOD; close BAD; print "$good good record(s), $bad bad record(s), $. total\n"; __DATA__ m\d+-\d+-\d+-\d+\.andorpac\.ad de\d+\.alshamil\.net\.ae \d+-\d+-\d+-\d+\.fibertel\.com\.ar ol\d+-\d+\.fibertel\.com\.ar host\d+\.\d+\.\d+\.\d+\.ifxnw\.com\.ar int-\d+-\d+-\d+-\d+\.movi\.com\.ar host-\d+\.\d+\.\d+\.\d+-ta\.adsl\.netizen\.com\.ar dsl-\d+-\d+-\d+-\d+\.users\.telpin\.com\.ar \d+-\d+-\d+-\d+\.bbt\.net\.ar \d+-\d+-\d+-\d+\.prima\.net\.ar \d+-\d+-\d+-\d+\.cab\.prima\.net\.ar \d+-\d+-\d+-\d+\.dsl\.prima\.net\.ar \d+-\d+-\d+-\d+\.dup\.prima\.net\.ar \d+-\d+-\d+-\d+\.dup\.prima\.net\.ar \d+-\d+-\d+-\d+\.wll\.prima\.net\.ar host\d+\.\d+-\d+-\d+\.telecom\.net\.ar chello\d+\.\d+\.sc-graz\.chello\.at \d+-\d+-\d+-\d+\.dynamic\.home\.xdsl-line\.inode\.at \d+-\d+-\d+-\d+\.paris-lodron\.xdsl-line\.inode\.at h\d+\.dyn\.cm\.kabsi\.at h\d+\.med\.cm\.kabsi\.at h\d+\.moe\.cm\.kabsi\.at cm\d+-\d+\.liwest\.at \d+-\d+-\d+-\d+\.pircher\.at \d+-\d+-\d+-\d+\.dyn\.salzburg-online\.at chello\d+\.\d+\.graz\.surfer\.at chello\d+\.\d+\.klafu\.surfer\.at chello\d+\.tirol\.surfer\.at chello\d+\.\d+\.\d+\.vie\.surfer\.at d\d+-\d+-\d+-\d+\.cust\.tele\d+\.at m\d+p\d+\.adsl\.highway\.telekom\.at n\d+p\d+\.adsl\.highway\.telekom\.at l\d+p\d+\.dipool\.highway\.telekom\.at chello\d+\.\d+\.\d+\.univie\.teleweb\.at chello\d+\.\d+\.\d+\.wu-wien\.teleweb\.at dsl-linz\d+-\d+-\d+\.utaonline\.at dialup-\d+\.syd\.ar\.com\.au dialup-\d+\.\d+\.\d+\.\d+\.acc\d+-ball-lis\.comindico\.com\.au dialup-\d+\.\d+\.\d+\.\d+\.acc\d+-mcmi-dwn\.comindico\.com\.au dsl-\d+\.\d+\.\d+\.\d+\.dsl\.comindico\.com\.au \d+-\d+-\d+-\d+\.netspeed\.com\.au blaax\d+-a\d+\.dialup\.optusnet\.com\.au chtax\d+-\d+\.dialup\.optusnet\.com\.au lonax\d+-b\d+\.dialup\.optusnet\.com\.au rohax\d+-\d+\.dialup\.optusnet\.com\.au wayax\d+-\d+\.dialup\.optusnet\.com\.au winax\d+-\d+\.dialup\.optusnet\.com\.au wooax\d+-b\d+\.dialup\.optusnet\.com\.au d\d+-\d+-\d+-\d+\.dsl\.nsw\.optusnet\.com\.au c\d+-\d+-\d+-\d+\.eburwd\d+\.vic\.optusnet\.com\.au c\d+-\d+-\d+-\d+\.lowrp\d+\.vic\.optusnet\.com\.au \d+\.fip-\d+\.permisdn\.ozemail\.com\.au \d+-\d+-\d+-\d+-bri-ts\d+-\d+\.tpgi\.com\.au \d+-\d+-\d+-\d+-vic-pppoe\.tpgi\.com\.au \d+-\d+-\d+-\d+\.tpgi\.com\.au dar-\d+k-\d+\.tpgi\.com\.au sou-ts\d+-\d+-\d+\.tpgi\.com\.au ains-\d+-\d+-\d+-\d+\.ains\.net\.au cpe-\d+-\d+-\d+-\d+\.nsw\.bigpond\.net\.au cpe-\d+-\d+-\d+-\d+\.qld\.bigpond\.net\.au cpe-\d+-\d+-\d+-\d+\.sa\.bigpond\.net\.au cpe-\d+-\d+-\d+-\d+\.vic\.bigpond\.net\.au cpe-\d+-\d+-\d+-\d+\.wa\.bigpond\.net\.au ppp-\d+\.cust\d+-\d+-\d+\.ghr\.chariot\.net\.au adsl-\d+\.cust\d+-\d+-\d+\.qld\.chariot\.net\.au \d+-\d+-\d+-\d+\.dyn\.iinet\.net\.au \d+\.a\.\d+\.mel\.iprimus\.net\.au \d+\.b\.\d+\.pth\.iprimus\.net\.au \d+\.a\.\d+\.sop\.iprimus\.net\.au r\d+-\d+-\d+-\d+\.cpe\.unwired\.net\.au dial-\d+\.\d+\.\d+\.\d+\.cotas\.com\.bo \d+-dial-user-ecp\.acessonet\.com\.br \d+-\d+-\d+-\d+\.corp\.ajato\.com\.br \d+\.\d+\.\d+\.\d+\.user\.ajato\.com\.br \d+-\d+-\d+-\d+\.user\.ajato\.com\.br \d+\.\d+\.\d+\.\d+\.user\.ajato\.com\.br cm-net-cwb-c[\da-f]+\.brdterra\.com\.br cm-net-poa-c[\da-f]+\.brdterra\.com\.br cm-tvcidade-rec-c[\da-f]+\.brdterra\.com\.br cm-tvcidade-ssa-c[\da-f]+\.brdterra\.com\.br cm-virtua-fln-c[\da-f]+\.brdterra\.com\.br cm-virtua-poa-c[\da-f]+\.brdterra\.com\.br net-\d+-\d+\.cable\.cpunet\.com\.br \d+-\d+-\d+\.xdsl-dinamico\.ctbcnetsuper\.com\.br \d+-\d+-\d+\.xdsl-fixo\.ctbcnetsuper\.com\.br dl-nas\d+-poa-c[\da-f]+\.dialterra\.com\.br \d+-\d+-\d+-\d+\.brt\.dialuol\.com\.br \d+-\d+-\d+-\d+\.tlf\.dialuol\.com\.br \d+-\d+-\d+-\d+\.tlm\.dialuol\.com\.br \d+-\d+-\d+-\d+\.rev\.easyband\.com\.br max-\d+-\d+-\d+\.nwnet\.com\.br \d+-\d+-\d+-\d+\.papalegua\.com\.br adsl\d+c\d+\.sercomtel\.com\.br \d+\.user\.veloxzone\.com\.br \d+\.virtua\.com\.br \d+\.bhz\.virtua\.com\.br [\da-f]+\.bhz\.virtua\.com\.br [\da-f]+\.rjo\.virtua\.com\.br [\da-f]+\.soc\.virtua\.com\.br [\da-f]+\.virtua\.com\.br \d+\.rjo\.virtua\.com\.br bhe\d+\.res-com\.wayinternet\.com\.br \d+-\d+-\d+-\d+\.mganm\d+\.dial\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.pmjce\d+\.dial\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.pnisir\d+\.dial\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.pvoce\d+\.dial\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.sance\d+\.dial\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.bnut\d+\.dsl\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.bsace\d+\.dsl\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.cbabm\d+\.dsl\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.cpece\d+\.dsl\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.cslce\d+\.dsl\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.ctame\d+\.dsl\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.gnace\d+\.dsl\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.jvece\d+\.dsl\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.nhoce\d+\.dsl\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.paemt\d+\.dsl\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.pltce\d+\.dsl\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.pvoce\d+\.dsl\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.smace\d+\.dsl\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.smace\d+\.e\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.dialdata\.net\.br \d+\.\d+\.\d+\.\d+\.dialup\.gvt\.net\.br \d+\.\d+\.\d+\.\d+\.tbprof\.gvt\.net\.br \d+-\d+-\d+-\d+\.customer\.telesp\.net\.br \d+-\d+-\d+-\d+\.dial-up\.telesp\.net\.br \d+-\d+-\d+-\d+\.dsl\.telesp\.net\.br Regexp-Assemble-0.38/examples/hostmatch/bad.canonical0000644000175000017500000004350411022301342021006 0ustar ronronm194-158-65-134.andorpac.ad m194-158-83-34.andorpac.ad de11929.alshamil.net.ae de21057.alshamil.net.ae de23208.alshamil.net.ae de2334.alshamil.net.ae de23392.alshamil.net.ae de24037.alshamil.net.ae de24435.alshamil.net.ae de25655.alshamil.net.ae 106-172-89-200.fibertel.com.ar 106-186-89-200.fibertel.com.ar 114-196-126-200.fibertel.com.ar 12-142-126-200.fibertel.com.ar 140-208-114-200.fibertel.com.ar 148-148-114-200.fibertel.com.ar 148-230-114-200.fibertel.com.ar 188-137-89-200.fibertel.com.ar 200-155-126-200.fibertel.com.ar 207-181-89-200.fibertel.com.ar 224-130-89-200.fibertel.com.ar 240-196-114-200.fibertel.com.ar 241-156-114-200.fibertel.com.ar 241-251-114-200.fibertel.com.ar 26-159-114-200.fibertel.com.ar 40-140-126-200.fibertel.com.ar 5-242-114-200.fibertel.com.ar 76-191-89-200.fibertel.com.ar ol126-12.fibertel.com.ar ol13-78.fibertel.com.ar ol134-243.fibertel.com.ar ol146-22.fibertel.com.ar ol159-75.fibertel.com.ar ol169-14.fibertel.com.ar ol191-125.fibertel.com.ar ol196-185.fibertel.com.ar ol199-183.fibertel.com.ar ol243-132.fibertel.com.ar ol249-11.fibertel.com.ar ol249-56.fibertel.com.ar ol3-37.fibertel.com.ar ol30-250.fibertel.com.ar ol55-13.fibertel.com.ar ol57-192.fibertel.com.ar ol65-51.fibertel.com.ar ol68-150.fibertel.com.ar host13.200.80.24.ifxnw.com.ar int-200-49-220-42.movi.com.ar int-200-49-223-245.movi.com.ar host-239.28.60.66-ta.adsl.netizen.com.ar dsl-200-43-19-83.users.telpin.com.ar 200-112-152-211.bbt.net.ar 200-122-96-189.prima.net.ar 200-122-72-230.cab.prima.net.ar 200-122-72-242.cab.prima.net.ar 200-122-89-133.cab.prima.net.ar 200-122-89-187.cab.prima.net.ar 200-122-90-89.cab.prima.net.ar 200-42-86-250.cab.prima.net.ar 200-122-19-254.dsl.prima.net.ar 200-122-44-246.dsl.prima.net.ar 200-122-47-219.dsl.prima.net.ar 200-122-51-48.dsl.prima.net.ar 200-122-62-222.dsl.prima.net.ar 200-122-8-86.dsl.prima.net.ar 200-55-109-42.dsl.prima.net.ar 200-42-118-237.dup.prima.net.ar 200-42-27-86.dup.prima.net.ar 200-42-74-242.wll.prima.net.ar host3.200-117-255.telecom.net.ar host161.200-45-119.telecom.net.ar host9.200-45-119.telecom.net.ar host52.200-45-154.telecom.net.ar host10.200-45-234.telecom.net.ar host135.200-45-236.telecom.net.ar host53.201-252-211.telecom.net.ar host52.201-252-215.telecom.net.ar host23.201-252-89.telecom.net.ar chello213047046194.1.sc-graz.chello.at chello080109200248.3.sc-graz.chello.at 83-64-21-44.dynamic.home.xdsl-line.inode.at 81-223-84-107.paris-lodron.xdsl-line.inode.at h081217134143.dyn.cm.kabsi.at h062040180106.med.cm.kabsi.at h062040175110.moe.cm.kabsi.at cm101-198.liwest.at cm105-115.liwest.at cm127-80.liwest.at cm130-144.liwest.at cm133-85.liwest.at cm144-88.liwest.at cm152-253.liwest.at cm156-27.liwest.at cm176-247.liwest.at cm220-124.liwest.at cm238-223.liwest.at cm239-76.liwest.at cm240-25.liwest.at cm249-96.liwest.at cm62-144.liwest.at 217-25-113-249.pircher.at 195-70-102-67.dyn.salzburg-online.at 195-70-97-81.dyn.salzburg-online.at 213-153-47-21.dyn.salzburg-online.at 213-153-48-39.dyn.salzburg-online.at 82-194-133-193.dyn.salzburg-online.at 82-194-135-243.dyn.salzburg-online.at chello213047046108.1.graz.surfer.at chello080109197149.2.graz.surfer.at chello080109203248.4.graz.surfer.at chello080109219252.4.graz.surfer.at chello213047048050.4.graz.surfer.at chello084115129099.5.graz.surfer.at chello080109218197.6.graz.surfer.at chello212017123151.4.klafu.surfer.at chello080109132150.tirol.surfer.at chello080109140115.tirol.surfer.at chello080109143084.tirol.surfer.at chello080109164042.tirol.surfer.at chello062178035093.12.11.vie.surfer.at chello213047117026.13.11.vie.surfer.at chello062178052028.18.11.vie.surfer.at chello080108080045.18.11.vie.surfer.at chello212017114099.18.11.vie.surfer.at chello062178054043.19.11.vie.surfer.at chello212186109127.19.11.vie.surfer.at chello062178004217.2.11.vie.surfer.at chello062178059119.20.11.vie.surfer.at chello080108016046.20.11.vie.surfer.at chello080108053192.25.11.vie.surfer.at chello084112028116.25.11.vie.surfer.at chello062178080107.27.11.vie.surfer.at chello084112018017.27.11.vie.surfer.at chello080108036122.31.11.vie.surfer.at chello212186208124.32.11.vie.surfer.at chello212186123139.33.11.vie.surfer.at chello213047134251.33.11.vie.surfer.at chello212186162128.4.11.vie.surfer.at chello062178012122.5.11.vie.surfer.at chello212186105092.6.11.vie.surfer.at chello080108087243.7.11.vie.surfer.at chello080108100084.8.11.vie.surfer.at chello084112006132.8.11.vie.surfer.at chello062178185143.1.12.vie.surfer.at chello213047104145.1.12.vie.surfer.at chello062178230148.10.12.vie.surfer.at chello084113020081.2.12.vie.surfer.at chello080108137131.3.12.vie.surfer.at chello213047105222.3.12.vie.surfer.at chello080108151071.5.12.vie.surfer.at chello213047103203.6.12.vie.surfer.at chello080108168243.9.12.vie.surfer.at chello080108196048.1.13.vie.surfer.at chello080108198050.2.13.vie.surfer.at chello062178125241.3.13.vie.surfer.at chello080108220235.3.13.vie.surfer.at chello084113196053.1.14.vie.surfer.at chello062178164066.11.14.vie.surfer.at chello080109022046.11.14.vie.surfer.at chello213047087197.11.14.vie.surfer.at chello062178165114.12.14.vie.surfer.at chello084113002037.12.14.vie.surfer.at chello213047164075.13.14.vie.surfer.at chello080109053218.14.14.vie.surfer.at chello062178176224.15.14.vie.surfer.at chello062178179196.16.14.vie.surfer.at chello213047061057.2.14.vie.surfer.at chello212186068249.3.14.vie.surfer.at chello213047080068.4.14.vie.surfer.at chello080109092182.15.15.vie.surfer.at chello080109065078.17.15.vie.surfer.at chello062178190124.2.15.vie.surfer.at chello062178231059.3.15.vie.surfer.at chello080109074169.4.15.vie.surfer.at chello080109116237.4.15.vie.surfer.at d213-102-130-44.cust.tele2.at m097p028.adsl.highway.telekom.at m1524p010.adsl.highway.telekom.at m1945p003.adsl.highway.telekom.at m2236p004.adsl.highway.telekom.at m369p019.adsl.highway.telekom.at m763p027.adsl.highway.telekom.at m898p012.adsl.highway.telekom.at n219p025.adsl.highway.telekom.at l1420p29.dipool.highway.telekom.at chello062178018161.7.11.univie.teleweb.at chello212017075138.2.15.univie.teleweb.at chello062178195142.4.15.univie.teleweb.at chello062178024246.9.11.wu-wien.teleweb.at dsl-linz7-17-24.utaonline.at dialup-342.syd.ar.com.au dialup-246.152.220.203.acc01-ball-lis.comindico.com.au dialup-128.118.221.203.acc02-mcmi-dwn.comindico.com.au dsl-3.117.240.220.dsl.comindico.com.au 210-9-142-38.netspeed.com.au blaax10-a224.dialup.optusnet.com.au chtax3-069.dialup.optusnet.com.au lonax10-b172.dialup.optusnet.com.au rohax5-023.dialup.optusnet.com.au wayax5-131.dialup.optusnet.com.au winax22-179.dialup.optusnet.com.au wooax17-b154.dialup.optusnet.com.au d211-29-190-138.dsl.nsw.optusnet.com.au d211-31-90-216.dsl.nsw.optusnet.com.au d220-236-28-253.dsl.nsw.optusnet.com.au c211-28-155-233.eburwd2.vic.optusnet.com.au c210-49-192-205.lowrp1.vic.optusnet.com.au 81.fip-213.permisdn.ozemail.com.au 203-219-27-145-bri-ts4-2600.tpgi.com.au 220-245-134-144-vic-pppoe.tpgi.com.au 220-245-144-147.tpgi.com.au dar-56k-113.tpgi.com.au sou-ts1-2600-146.tpgi.com.au ains-202-126-103-14.ains.net.au cpe-138-130-132-37.nsw.bigpond.net.au cpe-138-130-15-219.nsw.bigpond.net.au cpe-138-130-173-1.nsw.bigpond.net.au cpe-138-130-8-223.nsw.bigpond.net.au cpe-138-130-90-36.nsw.bigpond.net.au cpe-141-168-14-244.nsw.bigpond.net.au cpe-144-132-205-209.nsw.bigpond.net.au cpe-144-133-115-237.nsw.bigpond.net.au cpe-144-133-125-203.nsw.bigpond.net.au cpe-144-137-82-174.nsw.bigpond.net.au cpe-203-45-119-176.nsw.bigpond.net.au cpe-203-45-92-93.nsw.bigpond.net.au cpe-203-45-94-42.nsw.bigpond.net.au cpe-203-51-90-221.nsw.bigpond.net.au cpe-203-51-90-240.nsw.bigpond.net.au cpe-144-136-138-113.qld.bigpond.net.au cpe-203-45-161-116.qld.bigpond.net.au cpe-203-45-186-80.qld.bigpond.net.au cpe-203-45-247-34.qld.bigpond.net.au cpe-203-45-253-56.qld.bigpond.net.au cpe-144-137-206-28.sa.bigpond.net.au cpe-138-217-6-251.vic.bigpond.net.au cpe-144-132-31-148.vic.bigpond.net.au cpe-144-132-89-223.vic.bigpond.net.au cpe-144-136-39-116.vic.bigpond.net.au cpe-144-136-44-223.vic.bigpond.net.au cpe-147-10-4-128.vic.bigpond.net.au cpe-203-45-13-33.vic.bigpond.net.au cpe-203-45-13-59.vic.bigpond.net.au cpe-203-45-20-2.vic.bigpond.net.au cpe-203-45-26-141.vic.bigpond.net.au cpe-203-45-3-236.vic.bigpond.net.au cpe-203-45-52-250.vic.bigpond.net.au cpe-203-45-52-56.vic.bigpond.net.au cpe-203-45-54-26.vic.bigpond.net.au cpe-203-45-57-20.vic.bigpond.net.au cpe-141-168-117-123.wa.bigpond.net.au ppp-128.cust203-87-114.ghr.chariot.net.au adsl-172.cust203-87-58.qld.chariot.net.au 203-206-83-82.dyn.iinet.net.au 203-217-67-65.dyn.iinet.net.au 118.a.002.mel.iprimus.net.au 192.a.004.mel.iprimus.net.au 132.a.005.mel.iprimus.net.au 078.b.003.pth.iprimus.net.au 191.a.002.sop.iprimus.net.au r220-101-32-36.cpe.unwired.net.au r220-101-51-168.cpe.unwired.net.au dial-200.58.187.180.cotas.com.bo 200191136244-dial-user-ecp.acessonet.com.br 200191137028-dial-user-ecp.acessonet.com.br 200-162-218-205.corp.ajato.com.br 200-162-236-62.corp.ajato.com.br 200.162.209.101.user.ajato.com.br 200.162.240.106.user.ajato.com.br 200.162.226.111.user.ajato.com.br 200.162.237.151.user.ajato.com.br 200.162.233.160.user.ajato.com.br 200.162.248.162.user.ajato.com.br 200.162.237.184.user.ajato.com.br 200.162.242.191.user.ajato.com.br 200-150-186-129.user.ajato.com.br 200-150-186-146.user.ajato.com.br 200-170-123-50.user.ajato.com.br 200.162.225.246.user.ajato.com.br cm-net-cwb-c8b0318f.brdterra.com.br cm-net-cwb-c8b032da.brdterra.com.br cm-net-poa-c8b012fd.brdterra.com.br cm-tvcidade-rec-c8b14b0c.brdterra.com.br cm-tvcidade-ssa-c8b1a7d2.brdterra.com.br cm-virtua-fln-c8b08fef.brdterra.com.br cm-virtua-poa-c8b0cf9a.brdterra.com.br net-69-014.cable.cpunet.com.br 233-134-094.xdsl-dinamico.ctbcnetsuper.com.br 233-160-025.xdsl-dinamico.ctbcnetsuper.com.br 233-162-060.xdsl-dinamico.ctbcnetsuper.com.br 233-162-219.xdsl-dinamico.ctbcnetsuper.com.br 225-238-082.xdsl-fixo.ctbcnetsuper.com.br dl-nas8-poa-c89a162f.dialterra.com.br 200-187-248-101.brt.dialuol.com.br 200-98-100-214.tlf.dialuol.com.br 200-98-104-13.tlf.dialuol.com.br 200-98-34-36.tlf.dialuol.com.br 200-98-42-24.tlf.dialuol.com.br 200-98-56-228.tlf.dialuol.com.br 200-98-90-231.tlf.dialuol.com.br 200-147-139-241.tlm.dialuol.com.br 200-147-139-90.tlm.dialuol.com.br 200-147-50-111.tlm.dialuol.com.br 200-147-56-34.tlm.dialuol.com.br 200-147-63-30.tlm.dialuol.com.br 200-146-180-37.rev.easyband.com.br max-195-2-59.nwnet.com.br 200-208-226-202.papalegua.com.br adsl009c249.sercomtel.com.br adsl010c062.sercomtel.com.br adsl011c045.sercomtel.com.br adsl028c169.sercomtel.com.br adsl037c142.sercomtel.com.br adsl041c101.sercomtel.com.br 200141090077.user.veloxzone.com.br 200141118124.user.veloxzone.com.br 200141237250.user.veloxzone.com.br 200164026195.user.veloxzone.com.br 200164030128.user.veloxzone.com.br 200164051123.user.veloxzone.com.br 200164139135.user.veloxzone.com.br 200164244039.user.veloxzone.com.br 200165017149.user.veloxzone.com.br 200165020086.user.veloxzone.com.br 200165025091.user.veloxzone.com.br 200165085049.user.veloxzone.com.br 200165103194.user.veloxzone.com.br 200165181005.user.veloxzone.com.br 200165192141.user.veloxzone.com.br 200165203097.user.veloxzone.com.br 200165203183.user.veloxzone.com.br 200165207241.user.veloxzone.com.br 200165211136.user.veloxzone.com.br 200165225067.user.veloxzone.com.br 200165227253.user.veloxzone.com.br 200165237002.user.veloxzone.com.br 200216098185.user.veloxzone.com.br 200216122136.user.veloxzone.com.br 200216200048.user.veloxzone.com.br 201008022127.user.veloxzone.com.br 201008026250.user.veloxzone.com.br 201008028015.user.veloxzone.com.br 201008040176.user.veloxzone.com.br 201008052192.user.veloxzone.com.br 201008061141.user.veloxzone.com.br 201008093034.user.veloxzone.com.br 201008100159.user.veloxzone.com.br 201008142162.user.veloxzone.com.br 201008205051.user.veloxzone.com.br 201009017015.user.veloxzone.com.br 201009051176.user.veloxzone.com.br 201009073074.user.veloxzone.com.br 201009116225.user.veloxzone.com.br 201009120103.user.veloxzone.com.br 201009175111.user.veloxzone.com.br 201009175118.user.veloxzone.com.br 201009194232.user.veloxzone.com.br 201009197039.user.veloxzone.com.br 201009198135.user.veloxzone.com.br 201009253081.user.veloxzone.com.br 201009253186.user.veloxzone.com.br 201009255037.user.veloxzone.com.br 99156.virtua.com.br 233104.bhz.virtua.com.br 23370.bhz.virtua.com.br 235136.bhz.virtua.com.br 235205.bhz.virtua.com.br 2438.bhz.virtua.com.br 24513.bhz.virtua.com.br 2467.bhz.virtua.com.br 252168.bhz.virtua.com.br 254154.bhz.virtua.com.br c8a65a23.bhz.virtua.com.br c8a65c59.bhz.virtua.com.br c8a65cf6.bhz.virtua.com.br c8fbc841.bhz.virtua.com.br c9060d6a.virtua.com.br c906127a.virtua.com.br c9062391.virtua.com.br c90634c2.virtua.com.br c9063c5d.virtua.com.br c90654cd.virtua.com.br c9065cd8.virtua.com.br c9066a23.virtua.com.br c9067080.virtua.com.br c9068dd8.virtua.com.br c9069de4.virtua.com.br c906a41e.virtua.com.br c906c25f.virtua.com.br c906d21c.virtua.com.br c906dc27.virtua.com.br c906dfdf.virtua.com.br c906f4cd.virtua.com.br 16023099.rjo.virtua.com.br 179231105.rjo.virtua.com.br 179231167.rjo.virtua.com.br 179232179.rjo.virtua.com.br 179235162.rjo.virtua.com.br 179252126.rjo.virtua.com.br 179252135.rjo.virtua.com.br 22349.rjo.virtua.com.br c9111e57.rjo.virtua.com.br 44203.soc.virtua.com.br bhe045156.res-com.wayinternet.com.br bhe049142.res-com.wayinternet.com.br 200-203-158-211.mganm202.dial.brasiltelecom.net.br 200-163-069-170.pmjce204.dial.brasiltelecom.net.br 200-163-222-060.pnisir201.dial.brasiltelecom.net.br 200-181-088-098.pvoce205.dial.brasiltelecom.net.br 200-181-088-219.pvoce205.dial.brasiltelecom.net.br 200-180-203-206.sance200.dial.brasiltelecom.net.br 201-002-217-163.bnut37002.dsl.brasiltelecom.net.br 200-180-079-061.bnut37003.dsl.brasiltelecom.net.br 200-102-026-056.bnut37004.dsl.brasiltelecom.net.br 200-101-243-090.bnut37008.dsl.brasiltelecom.net.br 201-003-254-192.bnut37008.dsl.brasiltelecom.net.br 201-003-062-073.bsace7031.dsl.brasiltelecom.net.br 200-103-116-169.bsace704.dsl.brasiltelecom.net.br 200-140-013-061.bsace705.dsl.brasiltelecom.net.br 200-140-039-065.cbabm7001.dsl.brasiltelecom.net.br 200-140-042-237.cbabm7003.dsl.brasiltelecom.net.br 200-103-007-133.cbabm7004.dsl.brasiltelecom.net.br 200-096-131-068.cpece7007.dsl.brasiltelecom.net.br 200-096-131-236.cpece7007.dsl.brasiltelecom.net.br 200-096-209-080.cpece7007.dsl.brasiltelecom.net.br 200-203-073-182.cslce7001.dsl.brasiltelecom.net.br 200-203-075-059.cslce7002.dsl.brasiltelecom.net.br 200-103-144-122.ctame7014.dsl.brasiltelecom.net.br 200-103-150-101.ctame7041.dsl.brasiltelecom.net.br 200-103-131-132.ctame7044.dsl.brasiltelecom.net.br 200-140-061-027.gnace7003.dsl.brasiltelecom.net.br 200-140-064-035.gnace7003.dsl.brasiltelecom.net.br 200-140-066-032.gnace7005.dsl.brasiltelecom.net.br 200-140-069-073.gnace7005.dsl.brasiltelecom.net.br 200-101-044-103.gnace7006.dsl.brasiltelecom.net.br 200-101-044-142.gnace7006.dsl.brasiltelecom.net.br 200-101-046-032.gnace7006.dsl.brasiltelecom.net.br 200-103-110-204.gnace7007.dsl.brasiltelecom.net.br 200-101-241-064.jvece7001.dsl.brasiltelecom.net.br 200-203-052-062.nhoce7003.dsl.brasiltelecom.net.br 200-180-161-096.paemt7001.dsl.brasiltelecom.net.br 200-203-056-030.pltce7001.dsl.brasiltelecom.net.br 200-101-093-159.pvoce7003.dsl.brasiltelecom.net.br 200-203-069-095.smace7003.dsl.brasiltelecom.net.br 200-203-110-185.smace7006.dsl.brasiltelecom.net.br 200-102-095-016.smace7002.e.brasiltelecom.net.br 200-161-30-58.dialdata.net.br 200-171-21-221.dialdata.net.br 200-171-5-12.dialdata.net.br 200.175.154.107.dialup.gvt.net.br 200.175.17.186.dialup.gvt.net.br 200.175.2.23.dialup.gvt.net.br 200.175.156.70.tbprof.gvt.net.br 200-171-228-241.customer.telesp.net.br 200-100-115-171.dial-up.telesp.net.br 200-148-37-93.dsl.telesp.net.br 200-148-40-152.dsl.telesp.net.br 200-148-64-206.dsl.telesp.net.br 200-148-7-107.dsl.telesp.net.br 200-148-9-39.dsl.telesp.net.br 200-153-131-175.dsl.telesp.net.br 200-153-145-232.dsl.telesp.net.br 200-153-156-145.dsl.telesp.net.br 200-153-192-1.dsl.telesp.net.br 200-153-192-78.dsl.telesp.net.br 200-153-209-28.dsl.telesp.net.br 200-153-222-251.dsl.telesp.net.br 200-158-124-185.dsl.telesp.net.br 200-158-138-121.dsl.telesp.net.br 200-158-149-50.dsl.telesp.net.br 200-158-174-254.dsl.telesp.net.br 200-158-184-215.dsl.telesp.net.br 200-158-191-91.dsl.telesp.net.br 200-158-199-53.dsl.telesp.net.br 200-158-2-74.dsl.telesp.net.br 200-158-211-226.dsl.telesp.net.br 200-158-23-156.dsl.telesp.net.br 200-158-42-49.dsl.telesp.net.br 200-158-5-113.dsl.telesp.net.br 200-158-74-19.dsl.telesp.net.br 200-158-79-106.dsl.telesp.net.br 200-158-99-200.dsl.telesp.net.br 200-161-1-158.dsl.telesp.net.br 200-161-223-227.dsl.telesp.net.br 200-161-55-123.dsl.telesp.net.br 200-161-62-193.dsl.telesp.net.br 200-161-73-51.dsl.telesp.net.br 200-168-111-93.dsl.telesp.net.br 200-168-132-206.dsl.telesp.net.br 200-168-132-84.dsl.telesp.net.br 200-168-132-98.dsl.telesp.net.br 200-168-142-213.dsl.telesp.net.br 200-168-142-232.dsl.telesp.net.br 200-168-44-164.dsl.telesp.net.br 200-168-68-209.dsl.telesp.net.br 200-168-78-176.dsl.telesp.net.br 200-168-93-235.dsl.telesp.net.br 200-168-95-42.dsl.telesp.net.br 200-171-119-135.dsl.telesp.net.br 200-171-13-222.dsl.telesp.net.br 200-171-139-92.dsl.telesp.net.br 200-171-170-59.dsl.telesp.net.br 200-171-173-250.dsl.telesp.net.br 200-171-42-170.dsl.telesp.net.br 200-171-42-254.dsl.telesp.net.br 200-171-78-109.dsl.telesp.net.br 200-171-99-46.dsl.telesp.net.br 200-204-122-161.dsl.telesp.net.br 200-204-150-73.dsl.telesp.net.br 200-204-152-90.dsl.telesp.net.br 200-204-154-42.dsl.telesp.net.br 200-204-181-95.dsl.telesp.net.br 200-204-197-253.dsl.telesp.net.br 200-206-150-54.dsl.telesp.net.br 200-206-184-76.dsl.telesp.net.br 200-206-195-65.dsl.telesp.net.br 200-206-217-224.dsl.telesp.net.br 200-206-237-243.dsl.telesp.net.br 200-207-115-13.dsl.telesp.net.br 200-207-129-77.dsl.telesp.net.br 200-207-144-170.dsl.telesp.net.br 200-207-145-92.dsl.telesp.net.br 200-207-162-224.dsl.telesp.net.br 200-207-164-200.dsl.telesp.net.br 200-207-166-246.dsl.telesp.net.br 200-207-38-233.dsl.telesp.net.br 200-207-4-119.dsl.telesp.net.br 200-207-54-186.dsl.telesp.net.br 200-207-97-191.dsl.telesp.net.br Regexp-Assemble-0.38/examples/hostmatch/error.canonical0000644000175000017500000000000011022301342021371 0ustar ronronRegexp-Assemble-0.38/examples/hostmatch/source.in0000644000175000017500000004546311022301342020245 0ustar ronronmail.merlin.atlantis.co.ac smtp4.sms.ac smtp7.sms.ac m194-158-65-134.andorpac.ad m194-158-83-34.andorpac.ad de11929.alshamil.net.ae de21057.alshamil.net.ae de23208.alshamil.net.ae de2334.alshamil.net.ae de23392.alshamil.net.ae de24037.alshamil.net.ae de24435.alshamil.net.ae de25655.alshamil.net.ae domail1.emirates.net.ae 106-172-89-200.fibertel.com.ar 106-186-89-200.fibertel.com.ar 114-196-126-200.fibertel.com.ar 12-142-126-200.fibertel.com.ar 140-208-114-200.fibertel.com.ar 148-148-114-200.fibertel.com.ar 148-230-114-200.fibertel.com.ar 188-137-89-200.fibertel.com.ar 200-155-126-200.fibertel.com.ar 207-181-89-200.fibertel.com.ar 224-130-89-200.fibertel.com.ar 240-196-114-200.fibertel.com.ar 241-156-114-200.fibertel.com.ar 241-251-114-200.fibertel.com.ar 26-159-114-200.fibertel.com.ar 40-140-126-200.fibertel.com.ar 5-242-114-200.fibertel.com.ar 76-191-89-200.fibertel.com.ar avas-mr09.fibertel.com.ar avas-mr10.fibertel.com.ar ol126-12.fibertel.com.ar ol13-78.fibertel.com.ar ol134-243.fibertel.com.ar ol146-22.fibertel.com.ar ol159-75.fibertel.com.ar ol169-14.fibertel.com.ar ol191-125.fibertel.com.ar ol196-185.fibertel.com.ar ol199-183.fibertel.com.ar ol243-132.fibertel.com.ar ol249-11.fibertel.com.ar ol249-56.fibertel.com.ar ol3-37.fibertel.com.ar ol30-250.fibertel.com.ar ol55-13.fibertel.com.ar ol57-192.fibertel.com.ar ol65-51.fibertel.com.ar ol68-150.fibertel.com.ar host13.200.80.24.ifxnw.com.ar int-200-49-220-42.movi.com.ar int-200-49-223-245.movi.com.ar host-239.28.60.66-ta.adsl.netizen.com.ar cumeil9.prima.com.ar dsl-200-43-19-83.users.telpin.com.ar mail.tisa-sistemas.com.ar 200-112-152-211.bbt.net.ar 200-122-96-189.prima.net.ar 200-122-72-230.cab.prima.net.ar 200-122-72-242.cab.prima.net.ar 200-122-89-133.cab.prima.net.ar 200-122-89-187.cab.prima.net.ar 200-122-90-89.cab.prima.net.ar 200-42-86-250.cab.prima.net.ar 200-122-19-254.dsl.prima.net.ar 200-122-44-246.dsl.prima.net.ar 200-122-47-219.dsl.prima.net.ar 200-122-51-48.dsl.prima.net.ar 200-122-62-222.dsl.prima.net.ar 200-122-8-86.dsl.prima.net.ar 200-55-109-42.dsl.prima.net.ar 200-42-118-237.dup.prima.net.ar 200-42-27-86.dup.prima.net.ar 200-42-74-242.wll.prima.net.ar host3.200-117-255.telecom.net.ar host161.200-45-119.telecom.net.ar host9.200-45-119.telecom.net.ar host52.200-45-154.telecom.net.ar host10.200-45-234.telecom.net.ar host135.200-45-236.telecom.net.ar host53.201-252-211.telecom.net.ar host52.201-252-215.telecom.net.ar host23.201-252-89.telecom.net.ar cabel243b.bkf.at chello213047046194.1.sc-graz.chello.at chello080109200248.3.sc-graz.chello.at viefep11-int.chello.at viefep12-int.chello.at viefep15-int.chello.at viefep18-int.chello.at viefep19-int.chello.at 83-64-21-44.dynamic.home.xdsl-line.inode.at 81-223-84-107.paris-lodron.xdsl-line.inode.at static81-223-147-187.xdsl-line.inode.at 83-64-139-186.work.xdsl-line.inode.at h081217134143.dyn.cm.kabsi.at h062040180106.med.cm.kabsi.at h062040175110.moe.cm.kabsi.at cm101-198.liwest.at cm105-115.liwest.at cm127-80.liwest.at cm130-144.liwest.at cm133-85.liwest.at cm144-88.liwest.at cm152-253.liwest.at cm156-27.liwest.at cm176-247.liwest.at cm220-124.liwest.at cm238-223.liwest.at cm239-76.liwest.at cm240-25.liwest.at cm249-96.liwest.at cm62-144.liwest.at 217-25-113-249.pircher.at 195-70-102-67.dyn.salzburg-online.at 195-70-97-81.dyn.salzburg-online.at 213-153-47-21.dyn.salzburg-online.at 213-153-48-39.dyn.salzburg-online.at 82-194-133-193.dyn.salzburg-online.at 82-194-135-243.dyn.salzburg-online.at chello213047046108.1.graz.surfer.at chello080109197149.2.graz.surfer.at chello080109203248.4.graz.surfer.at chello080109219252.4.graz.surfer.at chello213047048050.4.graz.surfer.at chello084115129099.5.graz.surfer.at chello080109218197.6.graz.surfer.at chello212017123151.4.klafu.surfer.at chello080109132150.tirol.surfer.at chello080109140115.tirol.surfer.at chello080109143084.tirol.surfer.at chello080109164042.tirol.surfer.at chello062178035093.12.11.vie.surfer.at chello213047117026.13.11.vie.surfer.at chello062178052028.18.11.vie.surfer.at chello080108080045.18.11.vie.surfer.at chello212017114099.18.11.vie.surfer.at chello062178054043.19.11.vie.surfer.at chello212186109127.19.11.vie.surfer.at chello062178004217.2.11.vie.surfer.at chello062178059119.20.11.vie.surfer.at chello080108016046.20.11.vie.surfer.at chello080108053192.25.11.vie.surfer.at chello084112028116.25.11.vie.surfer.at chello062178080107.27.11.vie.surfer.at chello084112018017.27.11.vie.surfer.at chello080108036122.31.11.vie.surfer.at chello212186208124.32.11.vie.surfer.at chello212186123139.33.11.vie.surfer.at chello213047134251.33.11.vie.surfer.at chello212186162128.4.11.vie.surfer.at chello062178012122.5.11.vie.surfer.at chello212186105092.6.11.vie.surfer.at chello080108087243.7.11.vie.surfer.at chello080108100084.8.11.vie.surfer.at chello084112006132.8.11.vie.surfer.at chello062178185143.1.12.vie.surfer.at chello213047104145.1.12.vie.surfer.at chello062178230148.10.12.vie.surfer.at chello084113020081.2.12.vie.surfer.at chello080108137131.3.12.vie.surfer.at chello213047105222.3.12.vie.surfer.at chello080108151071.5.12.vie.surfer.at chello213047103203.6.12.vie.surfer.at chello080108168243.9.12.vie.surfer.at chello080108196048.1.13.vie.surfer.at chello080108198050.2.13.vie.surfer.at chello062178125241.3.13.vie.surfer.at chello080108220235.3.13.vie.surfer.at chello084113196053.1.14.vie.surfer.at chello062178164066.11.14.vie.surfer.at chello080109022046.11.14.vie.surfer.at chello213047087197.11.14.vie.surfer.at chello062178165114.12.14.vie.surfer.at chello084113002037.12.14.vie.surfer.at chello213047164075.13.14.vie.surfer.at chello080109053218.14.14.vie.surfer.at chello062178176224.15.14.vie.surfer.at chello062178179196.16.14.vie.surfer.at chello213047061057.2.14.vie.surfer.at chello212186068249.3.14.vie.surfer.at chello213047080068.4.14.vie.surfer.at chello080109092182.15.15.vie.surfer.at chello080109065078.17.15.vie.surfer.at chello062178190124.2.15.vie.surfer.at chello062178231059.3.15.vie.surfer.at chello080109074169.4.15.vie.surfer.at chello080109116237.4.15.vie.surfer.at chello213047128247.15.vie.surfer.at d213-102-130-44.cust.tele2.at m097p028.adsl.highway.telekom.at m1524p010.adsl.highway.telekom.at m1945p003.adsl.highway.telekom.at m2236p004.adsl.highway.telekom.at m369p019.adsl.highway.telekom.at m763p027.adsl.highway.telekom.at m898p012.adsl.highway.telekom.at n219p025.adsl.highway.telekom.at l1420p29.dipool.highway.telekom.at chello062178018161.7.11.univie.teleweb.at chello212017075138.2.15.univie.teleweb.at chello062178195142.4.15.univie.teleweb.at chello062178024246.9.11.wu-wien.teleweb.at cust170.120.nw.tplus.at dsl-linz7-17-24.utaonline.at mail1.acnielsen.com.au dialup-342.syd.ar.com.au dialup-246.152.220.203.acc01-ball-lis.comindico.com.au dialup-128.118.221.203.acc02-mcmi-dwn.comindico.com.au dsl-3.117.240.220.dsl.comindico.com.au mail.gtlaw.com.au 210-9-142-38.netspeed.com.au blaax10-a224.dialup.optusnet.com.au chtax3-069.dialup.optusnet.com.au lonax10-b172.dialup.optusnet.com.au rohax5-023.dialup.optusnet.com.au wayax5-131.dialup.optusnet.com.au winax22-179.dialup.optusnet.com.au wooax17-b154.dialup.optusnet.com.au d211-29-190-138.dsl.nsw.optusnet.com.au d211-31-90-216.dsl.nsw.optusnet.com.au d220-236-28-253.dsl.nsw.optusnet.com.au c211-28-155-233.eburwd2.vic.optusnet.com.au c210-49-192-205.lowrp1.vic.optusnet.com.au 81.fip-213.permisdn.ozemail.com.au 203-219-27-145-bri-ts4-2600.tpgi.com.au 220-245-134-144-vic-pppoe.tpgi.com.au 220-245-144-147.tpgi.com.au dar-56k-113.tpgi.com.au sou-ts1-2600-146.tpgi.com.au orcus.its.uow.edu.au ains-202-126-103-14.ains.net.au cpe-138-130-132-37.nsw.bigpond.net.au cpe-138-130-15-219.nsw.bigpond.net.au cpe-138-130-173-1.nsw.bigpond.net.au cpe-138-130-8-223.nsw.bigpond.net.au cpe-138-130-90-36.nsw.bigpond.net.au cpe-141-168-14-244.nsw.bigpond.net.au cpe-144-132-205-209.nsw.bigpond.net.au cpe-144-133-115-237.nsw.bigpond.net.au cpe-144-133-125-203.nsw.bigpond.net.au cpe-144-137-82-174.nsw.bigpond.net.au cpe-203-45-119-176.nsw.bigpond.net.au cpe-203-45-92-93.nsw.bigpond.net.au cpe-203-45-94-42.nsw.bigpond.net.au cpe-203-51-90-221.nsw.bigpond.net.au cpe-203-51-90-240.nsw.bigpond.net.au cpe-144-136-138-113.qld.bigpond.net.au cpe-203-45-161-116.qld.bigpond.net.au cpe-203-45-186-80.qld.bigpond.net.au cpe-203-45-247-34.qld.bigpond.net.au cpe-203-45-253-56.qld.bigpond.net.au cpe-144-137-206-28.sa.bigpond.net.au cpe-138-217-6-251.vic.bigpond.net.au cpe-144-132-31-148.vic.bigpond.net.au cpe-144-132-89-223.vic.bigpond.net.au cpe-144-136-39-116.vic.bigpond.net.au cpe-144-136-44-223.vic.bigpond.net.au cpe-147-10-4-128.vic.bigpond.net.au cpe-203-45-13-33.vic.bigpond.net.au cpe-203-45-13-59.vic.bigpond.net.au cpe-203-45-20-2.vic.bigpond.net.au cpe-203-45-26-141.vic.bigpond.net.au cpe-203-45-3-236.vic.bigpond.net.au cpe-203-45-52-250.vic.bigpond.net.au cpe-203-45-52-56.vic.bigpond.net.au cpe-203-45-54-26.vic.bigpond.net.au cpe-203-45-57-20.vic.bigpond.net.au cpe-141-168-117-123.wa.bigpond.net.au ppp-128.cust203-87-114.ghr.chariot.net.au adsl-172.cust203-87-58.qld.chariot.net.au 203-206-83-82.dyn.iinet.net.au 203-217-67-65.dyn.iinet.net.au smtprelay.intellicentre.net.au 118.a.002.mel.iprimus.net.au 201.c.002.mel.iprimus.net.au 192.a.004.mel.iprimus.net.au 132.a.005.mel.iprimus.net.au 078.b.003.pth.iprimus.net.au 191.a.002.sop.iprimus.net.au smtp02.syd.iprimus.net.au s089c.static.pacific.net.au r220-101-32-36.cpe.unwired.net.au r220-101-51-168.cpe.unwired.net.au webmail3.onatel.bf aktor1.adeli.biz ns1.cheznous.biz w7.creditland.biz ns1.gazduire.biz mail2.hitechpros.biz relay.link2biz.biz mx2.wendhlp.biz mx2.wowie.biz dial-200.58.187.180.cotas.com.bo 200191136244-dial-user-ecp.acessonet.com.br 200191137028-dial-user-ecp.acessonet.com.br 200-162-218-205.corp.ajato.com.br 200-162-236-62.corp.ajato.com.br 200.162.209.101.user.ajato.com.br 200.162.240.106.user.ajato.com.br 200.162.226.111.user.ajato.com.br 200.162.237.151.user.ajato.com.br 200.162.233.160.user.ajato.com.br 200.162.248.162.user.ajato.com.br 200.162.237.184.user.ajato.com.br 200.162.242.191.user.ajato.com.br 200-150-186-129.user.ajato.com.br 200-150-186-146.user.ajato.com.br 200-170-123-50.user.ajato.com.br 200.162.225.246.user.ajato.com.br cm-net-cwb-c8b0318f.brdterra.com.br cm-net-cwb-c8b032da.brdterra.com.br cm-net-poa-c8b012fd.brdterra.com.br cm-tvcidade-rec-c8b14b0c.brdterra.com.br cm-tvcidade-ssa-c8b1a7d2.brdterra.com.br cm-virtua-fln-c8b08fef.brdterra.com.br cm-virtua-poa-c8b0cf9a.brdterra.com.br mail2.comdominio.com.br net-69-014.cable.cpunet.com.br 233-134-094.xdsl-dinamico.ctbcnetsuper.com.br 233-160-025.xdsl-dinamico.ctbcnetsuper.com.br 233-162-060.xdsl-dinamico.ctbcnetsuper.com.br 233-162-219.xdsl-dinamico.ctbcnetsuper.com.br 225-238-082.xdsl-fixo.ctbcnetsuper.com.br dl-nas8-poa-c89a162f.dialterra.com.br 200-187-248-101.brt.dialuol.com.br 200-98-100-214.tlf.dialuol.com.br 200-98-104-13.tlf.dialuol.com.br 200-98-34-36.tlf.dialuol.com.br 200-98-42-24.tlf.dialuol.com.br 200-98-56-228.tlf.dialuol.com.br 200-98-90-231.tlf.dialuol.com.br 200-147-139-241.tlm.dialuol.com.br 200-147-139-90.tlm.dialuol.com.br 200-147-50-111.tlm.dialuol.com.br 200-147-56-34.tlm.dialuol.com.br 200-147-63-30.tlm.dialuol.com.br 200-146-180-37.rev.easyband.com.br pn41.neoline.com.br max-195-2-59.nwnet.com.br 200-208-226-202.papalegua.com.br adsl009c249.sercomtel.com.br adsl010c062.sercomtel.com.br adsl011c045.sercomtel.com.br adsl028c169.sercomtel.com.br adsl037c142.sercomtel.com.br adsl041c101.sercomtel.com.br sv6.srnet.com.br cacheflow.sul.com.br itajuba.terra.com.br itaparica.terra.com.br itapoa.terra.com.br smtpout3.uol.com.br smtpout6.uol.com.br web6.vanet.com.br 200141090077.user.veloxzone.com.br 200141118124.user.veloxzone.com.br 200141237250.user.veloxzone.com.br 200164026195.user.veloxzone.com.br 200164030128.user.veloxzone.com.br 200164051123.user.veloxzone.com.br 200164139135.user.veloxzone.com.br 200164244039.user.veloxzone.com.br 200165017149.user.veloxzone.com.br 200165020086.user.veloxzone.com.br 200165025091.user.veloxzone.com.br 200165085049.user.veloxzone.com.br 200165103194.user.veloxzone.com.br 200165181005.user.veloxzone.com.br 200165192141.user.veloxzone.com.br 200165203097.user.veloxzone.com.br 200165203183.user.veloxzone.com.br 200165207241.user.veloxzone.com.br 200165211136.user.veloxzone.com.br 200165225067.user.veloxzone.com.br 200165227253.user.veloxzone.com.br 200165237002.user.veloxzone.com.br 200216098185.user.veloxzone.com.br 200216122136.user.veloxzone.com.br 200216200048.user.veloxzone.com.br 201008022127.user.veloxzone.com.br 201008026250.user.veloxzone.com.br 201008028015.user.veloxzone.com.br 201008040176.user.veloxzone.com.br 201008052192.user.veloxzone.com.br 201008061141.user.veloxzone.com.br 201008093034.user.veloxzone.com.br 201008100159.user.veloxzone.com.br 201008142162.user.veloxzone.com.br 201008205051.user.veloxzone.com.br 201009017015.user.veloxzone.com.br 201009051176.user.veloxzone.com.br 201009073074.user.veloxzone.com.br 201009116225.user.veloxzone.com.br 201009120103.user.veloxzone.com.br 201009175111.user.veloxzone.com.br 201009175118.user.veloxzone.com.br 201009194232.user.veloxzone.com.br 201009197039.user.veloxzone.com.br 201009198135.user.veloxzone.com.br 201009253081.user.veloxzone.com.br 201009253186.user.veloxzone.com.br 201009255037.user.veloxzone.com.br 99156.virtua.com.br 233104.bhz.virtua.com.br 23370.bhz.virtua.com.br 235136.bhz.virtua.com.br 235205.bhz.virtua.com.br 2438.bhz.virtua.com.br 24513.bhz.virtua.com.br 2467.bhz.virtua.com.br 252168.bhz.virtua.com.br 254154.bhz.virtua.com.br c8a65a23.bhz.virtua.com.br c8a65c59.bhz.virtua.com.br c8a65cf6.bhz.virtua.com.br c8fbc841.bhz.virtua.com.br c9060d6a.virtua.com.br c906127a.virtua.com.br c9062391.virtua.com.br c90634c2.virtua.com.br c9063c5d.virtua.com.br c90654cd.virtua.com.br c9065cd8.virtua.com.br c9066a23.virtua.com.br c9067080.virtua.com.br c9068dd8.virtua.com.br c9069de4.virtua.com.br c906a41e.virtua.com.br c906c25f.virtua.com.br c906d21c.virtua.com.br c906dc27.virtua.com.br c906dfdf.virtua.com.br c906f4cd.virtua.com.br 16023099.rjo.virtua.com.br 179231105.rjo.virtua.com.br 179231167.rjo.virtua.com.br 179232179.rjo.virtua.com.br 179235162.rjo.virtua.com.br 179252126.rjo.virtua.com.br 179252135.rjo.virtua.com.br 22349.rjo.virtua.com.br c9111e57.rjo.virtua.com.br 44203.soc.virtua.com.br bhe045156.res-com.wayinternet.com.br bhe049142.res-com.wayinternet.com.br ricardo.adm.ita.cta.br 200-203-158-211.mganm202.dial.brasiltelecom.net.br 200-163-069-170.pmjce204.dial.brasiltelecom.net.br 200-163-222-060.pnisir201.dial.brasiltelecom.net.br 200-181-088-098.pvoce205.dial.brasiltelecom.net.br 200-181-088-219.pvoce205.dial.brasiltelecom.net.br 200-180-203-206.sance200.dial.brasiltelecom.net.br 201-002-217-163.bnut37002.dsl.brasiltelecom.net.br 200-180-079-061.bnut37003.dsl.brasiltelecom.net.br 200-102-026-056.bnut37004.dsl.brasiltelecom.net.br 200-101-243-090.bnut37008.dsl.brasiltelecom.net.br 201-003-254-192.bnut37008.dsl.brasiltelecom.net.br 201-003-062-073.bsace7031.dsl.brasiltelecom.net.br 200-103-116-169.bsace704.dsl.brasiltelecom.net.br 200-140-013-061.bsace705.dsl.brasiltelecom.net.br 200-140-039-065.cbabm7001.dsl.brasiltelecom.net.br 200-140-042-237.cbabm7003.dsl.brasiltelecom.net.br 200-103-007-133.cbabm7004.dsl.brasiltelecom.net.br 200-096-131-068.cpece7007.dsl.brasiltelecom.net.br 200-096-131-236.cpece7007.dsl.brasiltelecom.net.br 200-096-209-080.cpece7007.dsl.brasiltelecom.net.br 200-203-073-182.cslce7001.dsl.brasiltelecom.net.br 200-203-075-059.cslce7002.dsl.brasiltelecom.net.br 200-103-144-122.ctame7014.dsl.brasiltelecom.net.br 200-103-150-101.ctame7041.dsl.brasiltelecom.net.br 200-103-131-132.ctame7044.dsl.brasiltelecom.net.br 200-140-061-027.gnace7003.dsl.brasiltelecom.net.br 200-140-064-035.gnace7003.dsl.brasiltelecom.net.br 200-140-066-032.gnace7005.dsl.brasiltelecom.net.br 200-140-069-073.gnace7005.dsl.brasiltelecom.net.br 200-101-044-103.gnace7006.dsl.brasiltelecom.net.br 200-101-044-142.gnace7006.dsl.brasiltelecom.net.br 200-101-046-032.gnace7006.dsl.brasiltelecom.net.br 200-103-110-204.gnace7007.dsl.brasiltelecom.net.br 200-101-241-064.jvece7001.dsl.brasiltelecom.net.br 200-203-052-062.nhoce7003.dsl.brasiltelecom.net.br 200-180-161-096.paemt7001.dsl.brasiltelecom.net.br 200-203-056-030.pltce7001.dsl.brasiltelecom.net.br 200-101-093-159.pvoce7003.dsl.brasiltelecom.net.br 200-203-069-095.smace7003.dsl.brasiltelecom.net.br 200-203-110-185.smace7006.dsl.brasiltelecom.net.br 200-102-095-016.smace7002.e.brasiltelecom.net.br 200-161-30-58.dialdata.net.br 200-171-21-221.dialdata.net.br 200-171-5-12.dialdata.net.br 200.175.154.107.dialup.gvt.net.br 200.175.17.186.dialup.gvt.net.br 200.175.2.23.dialup.gvt.net.br 200.175.156.70.tbprof.gvt.net.br 200-171-228-241.customer.telesp.net.br 200-100-115-171.dial-up.telesp.net.br 200-148-37-93.dsl.telesp.net.br 200-148-40-152.dsl.telesp.net.br 200-148-64-206.dsl.telesp.net.br 200-148-7-107.dsl.telesp.net.br 200-148-9-39.dsl.telesp.net.br 200-153-131-175.dsl.telesp.net.br 200-153-145-232.dsl.telesp.net.br 200-153-156-145.dsl.telesp.net.br 200-153-192-1.dsl.telesp.net.br 200-153-192-78.dsl.telesp.net.br 200-153-209-28.dsl.telesp.net.br 200-153-222-251.dsl.telesp.net.br 200-158-124-185.dsl.telesp.net.br 200-158-138-121.dsl.telesp.net.br 200-158-149-50.dsl.telesp.net.br 200-158-174-254.dsl.telesp.net.br 200-158-184-215.dsl.telesp.net.br 200-158-191-91.dsl.telesp.net.br 200-158-199-53.dsl.telesp.net.br 200-158-2-74.dsl.telesp.net.br 200-158-211-226.dsl.telesp.net.br 200-158-23-156.dsl.telesp.net.br 200-158-42-49.dsl.telesp.net.br 200-158-5-113.dsl.telesp.net.br 200-158-74-19.dsl.telesp.net.br 200-158-79-106.dsl.telesp.net.br 200-158-99-200.dsl.telesp.net.br 200-161-1-158.dsl.telesp.net.br 200-161-223-227.dsl.telesp.net.br 200-161-55-123.dsl.telesp.net.br 200-161-62-193.dsl.telesp.net.br 200-161-73-51.dsl.telesp.net.br 200-168-111-93.dsl.telesp.net.br 200-168-132-206.dsl.telesp.net.br 200-168-132-84.dsl.telesp.net.br 200-168-132-98.dsl.telesp.net.br 200-168-142-213.dsl.telesp.net.br 200-168-142-232.dsl.telesp.net.br 200-168-44-164.dsl.telesp.net.br 200-168-68-209.dsl.telesp.net.br 200-168-78-176.dsl.telesp.net.br 200-168-93-235.dsl.telesp.net.br 200-168-95-42.dsl.telesp.net.br 200-171-119-135.dsl.telesp.net.br 200-171-13-222.dsl.telesp.net.br 200-171-139-92.dsl.telesp.net.br 200-171-170-59.dsl.telesp.net.br 200-171-173-250.dsl.telesp.net.br 200-171-42-170.dsl.telesp.net.br 200-171-42-254.dsl.telesp.net.br 200-171-78-109.dsl.telesp.net.br 200-171-99-46.dsl.telesp.net.br 200-204-122-161.dsl.telesp.net.br 200-204-150-73.dsl.telesp.net.br 200-204-152-90.dsl.telesp.net.br 200-204-154-42.dsl.telesp.net.br 200-204-181-95.dsl.telesp.net.br 200-204-197-253.dsl.telesp.net.br 200-206-150-54.dsl.telesp.net.br 200-206-184-76.dsl.telesp.net.br 200-206-195-65.dsl.telesp.net.br 200-206-217-224.dsl.telesp.net.br 200-206-237-243.dsl.telesp.net.br 200-207-115-13.dsl.telesp.net.br 200-207-129-77.dsl.telesp.net.br 200-207-144-170.dsl.telesp.net.br 200-207-145-92.dsl.telesp.net.br 200-207-162-224.dsl.telesp.net.br 200-207-164-200.dsl.telesp.net.br 200-207-166-246.dsl.telesp.net.br 200-207-38-233.dsl.telesp.net.br 200-207-4-119.dsl.telesp.net.br 200-207-54-186.dsl.telesp.net.br 200-207-97-191.dsl.telesp.net.br Regexp-Assemble-0.38/examples/failure.01.pl0000644000175000017500000000307312563777440016650 0ustar ronronuse v5.14; use strict; use warnings; use Regexp::Assemble; use Data::Dumper; my $re = Regexp::Assemble->new(flags => 'i')->track(1); foreach my $reg ( '(?^ux: Coneheads(?^ux: [^\\p{Alnum}] )(?^ux: [^\\p{Alnum}] )(?^ux: [^\\p{Alnum}] )Dan(?^ux: [^\\p{Alnum}] )Aykroyd(?^ux: [^\\p{Alnum}] )Comedy(?^ux: [^\\p{Alnum}] )Eng )|(?^ux: Coneheads(?:[+]|%20)-(?:[+]|%20)Dan(?:[+]|%20)Aykroyd(?:[+]|%20)Comedy(?:[+]|%20)Eng)', # 'Coneheads(?^ux: [^\\p{Alnum}] )(?^ux: [^\\p{Alnum}] )(?^ux: [^\\p{Alnum}] )Dan(?^ux: [^\\p{Alnum}] )Aykroyd(?^ux: [^\\p{Alnum}] )Comedy(?^ux: [^\\p{Alnum}] )Eng', # 'Coneheads(?:[+]|%20)-(?:[+]|%20)Dan(?:[+]|%20)Aykroyd(?:[+]|%20)Comedy(?:[+]|%20)Eng', '(?^u:Coneheads\\ 1993)', ) { $re->add( $reg ); } foreach my $string ( "Coneheads - Dan Aykroyd Comedy Eng", "Coneheads+-+Dan+Aykroyd+Comedy+Eng", "Coneheads%20-%20Dan%20Aykroyd%20Comedy%20Eng", "Coneheads 1993", ) { if( $string =~ /$re/ ) { say "matched $string"; if( my $matched = $re->matched() ) { say "matched with: $matched"; } if( my $matched = $re->source($^R) ) { say "\$^R: $^R"; say "match source: $matched"; } say "work around: ", get_source($re, $string); } else { say "no match on $string"; say "get_source returns: ", get_source($re, $string); } say "-" x 70; } print Dumper $re; sub get_source { my ($re, $string) = @_; foreach my $r ( @{$re->{mlist}} ) { if( $string =~ /$r/ ) { return $r; } } return; } Regexp-Assemble-0.38/examples/roman0000755000175000017500000000115311022301342015451 0ustar ronron#! /usr/local/bin/perl -w # # roman - generate a regular expression that matches the roman numerals # from 1 to 20. # # you can over-ride the upper bound (20) by specifying the value # on the command line. You can also specify an indent value to # pretty-print the resulting regexp. # # Copyright (C) David Landgren 2005 use strict; use Regexp::Assemble; my $max = shift || 20; my $indent = shift || 0; eval "use Math::Roman 'roman'"; $@ and die "You must install Math::Roman to run this example\n"; my $r = Regexp::Assemble->new; $r->add(roman($_)) for 1..$max; print $r->as_string( indent => $indent ), "\n"; Regexp-Assemble-0.38/examples/stress-test.pl0000755000175000017500000000537111022301342017255 0ustar ronron#! /usr/local/bin/perl -w use strict; use lib 'blib/lib'; use Regexp::Assemble; use Data::PowerSet; use Algorithm::Combinatorics 'combinations'; my $end = shift || 'e'; # generate the power set of the elements 'a' .. $end my $set = [sort {join('' => @$a) cmp join('' => @$b)} @{Data::PowerSet::powerset( {min=>1}, 'a'..$end )} ]; $| = 1; print "## size of powerset = ", scalar(@$set), "\n"; my $nr = 0; for my $sel (@ARGV) { my $p = combinations($set,$sel); while (defined(my $s = $p->next)) { ++$nr; my $short = Regexp::Assemble->new; $short->insert(@$_) for @$s; my $long = Regexp::Assemble->new; $long->insert('^', @$_, '$') for @$s; my $sh = $short->as_string; my $lg = $long->as_string; $s = [map {join '' => @$_} @$s]; printf "%9d %2d %s $lg\n", $nr, $sel, "@$s" unless $nr % 10000; my %expected = map{($_,$_)} @$s; if( "^$sh\$" ne $lg ) { $lg =~ s/^\^//; $lg =~ s/\$$//; for my $t ( @$s) { if( $expected{$t} ) { next if $t =~ /$long/; printf "%5d %-50s %s\n", $nr, $lg, "@$s"; print "l: $t should have been matched\n"; last; } else { next if $t !~ /$long/; printf "%5d %-50s %s\n", $nr, $lg, "@$s"; print "l: $t should not have been matched\n"; last; } } my $short_str = '^' . $sh . '$'; my $short_re = qr/$short_str/; for my $t ( @$s) { if( $expected{$t} ) { next if $t =~ /$short_re/; printf "%5d %-50s %s\n", $nr, $sh, "@$s"; print "s: $t should have been matched\n"; last; } else { next if $t !~ /$short_re/; printf "%5d %-50s %s\n", $nr, $sh, "@$s"; print "s: $t should not have been matched\n"; last; } } } else { for my $t ( @$s) { if( $expected{$t} ) { next if $t =~ /$long/; printf "%5d %-50s %s\n", $nr, $lg, "@$s"; print "$t should have been matched\n"; last; } else { next if $t !~ /$long/; printf "%5d %-50s %s\n", $nr, $sh, "@$s"; print "$t should not have been matched\n"; last; } } } } print "# $sel $nr\n"; } print "$nr combinations examined\n"; Regexp-Assemble-0.38/examples/file.40000644000175000017500000000002311022301342015406 0ustar ronroncat/dog/cow/pig/henRegexp-Assemble-0.38/examples/tld0000755000175000017500000000115111022301342015116 0ustar ronron#! /usr/local/bin/perl -w # # tld - generate a regular expression that matches the Internet # top level domains # # You can also specify an indent value to pretty-print the # resulting regexp. This example gives you a very good insight # as to how the alternations are sorted, busiest to least. # # Copyright (C) David Landgren 2005 use strict; use Regexp::Assemble; my $indent = shift || 0; eval "use Net::Domain::TLD"; $@ and die "You must install Net::Domain::TLD to run this example\n"; my $re = Regexp::Assemble->new->add( Net::Domain::TLD->new->All ); print $re->as_string(indent => $indent), "\n"; Regexp-Assemble-0.38/examples/file.30000644000175000017500000000002011022301342015402 0ustar ronronen es il is Regexp-Assemble-0.38/examples/ircwatcher0000755000175000017500000000223411022301342016471 0ustar ronron#! /usr/local/bin/perl -w # # ircwatcher - watch an IRC stream and do things when # interesting things occur # # This script demonstrates the use of dispatch table. One # regular expression matching everthing, and then handing # off the captured submatches to a callback. # # Try changing the read of STDIN to DATA for a quick demo. # # Acknowledgements to David "Sniper" Rigaudière for the # idea. # # Copyright (C) David Landgren 2005 use strict; use Regexp::Assemble; my %dispatch = ( '^\*\*\* (\S+) joined channel (\S+)$' => \&joined, '^\*\*\* (\S+) left channel (\S+) reason (.*)$' => \&left, '^q$' => sub { exit }, ); my $re = Regexp::Assemble->new ->track(1) ->add(keys %dispatch); sub joined { my ($who, $channel) = @_; print "$who joined $channel\n"; } sub left { my ($who, $channel, $reason) = @_; print "$who left $channel saying $reason\n"; } while( ) { chomp; if ($re->match($_)) { $dispatch{$re->matched}->($re->capture); } else { print "ignored <$_>\n"; } } __DATA__ *** david joined channel foo hello *** david left channel bar reason that's all folks q Regexp-Assemble-0.38/examples/assemble0000755000175000017500000001160511022544657016155 0ustar ronron#! /usr/bin/perl -w # # assemble - read lines from STDIN and assemble them into a pattern # # Copyright (C) David Landgren 2004-2008 use strict; use Getopt::Std; use Regexp::Assemble; use Time::HiRes 'time'; use vars '$VERSION'; $VERSION = '0.92'; getopts( 'abcd:f:i:nprsSt:TuUvw', \my %opt ); print "$VERSION\n" and exit if $opt{v}; $opt{d} |= 8 if $opt{T}; my $ra = Regexp::Assemble->new( chomp => 1, debug => $opt{d} || 0, fold_meta_pairs => exists $opt{f} ? 0 : 1, reduce => exists $opt{r} ? 0 : 1, dup_warn => exists $opt{u} ? 1 : 0, lookahead => exists $opt{a} ? 1 : 0, unroll_plus => exists $opt{U} ? 1 : 0, ); if( $opt{b} or $opt{c} ) { if( !$opt{b} ) { # filter comments $ra->pre_filter( sub { $_[0] =~ s/\s*#.*$//; 1 } ); } elsif( !$opt{c} ) { # filter blank lines $ra->pre_filter( sub { length(shift) } ); } else { # filter comments and blank lines. # (removing a comment may can cause a line to become blank $ra->pre_filter( sub { $_[0] =~ s/\s*#.*$//; length($_[0]) } ); } } $ra->add( <> ); # need to tickle reduction explicitly in the event of -S and -d8 $ra->_reduce() if $opt{S} and $opt{d} and ($opt{d} & 8); if( $opt{i} or $opt{p} or not ($opt{t} or $opt{S}) ) { print $ra->as_string( indent => $opt{i} || 0 ); print "\n" unless $opt{n}; } if( $opt{s} or $opt{S} ) { warn qq{# nr=@{[$ra->stats_add]} dup=@{[$ra->stats_dup]} raw=@{[$ra->stats_raw]} cooked=@{[$ra->stats_cooked]} len=@{[$ra->stats_length]}\n}; } if( $opt{t} ) { my $error = 0; my $file = $opt{t}; open IN, $file or die "Cannot open $file for input: $!\n"; print $ra->as_string, "\n"; while( ) { chomp; if( $opt{w} ) { next if $_ =~ /^$ra$/; } else { next if $_ =~ /$ra/; } print "FAIL <$_>\n"; ++$error; } close IN; exit $error ? 1 : 0; } =head1 NAME assemble - Assemble a list of regular expressions from a file =head1 SYNOPSIS assemble -abcdfinprsStTuUvw file [...] =head1 DESCRIPTION Assemble a list of regular expression either from standard input or a file, using the Regexp::Assemble module. =head1 OPTIONS =over 5 =item B<-a> look Ahead. Insert C<(?=...)> zero-width lookahead assertions in the pattern, where necessary. =item B<-b> Blank. Ignore blank lines. =item B<-c> Comment. Basic comment filtering. Strip off perl/shell comments (C<\s*#.*$/>). =item B<-d> Debug. Turns on debugging output. See L for suitable values. =item B<-i> Indent. Print the regular expression using and indent of n to display nesting. A.k.a pretty-printing. Implies -p. =item B<-n> No newline. Do not print a newline after the pattern. Useful when interpolating the output into a templating system or similar. =item B<-p> Print. Print the pattern. This is the default, however, it is required when the -t switch is enabled (because if you want to test patterns ordinarily you don't care what the the assembled pattern looks like). =item B<-r> Reduce. The default behaviour is to reduce the assembled pattern. Enabling this switch causes the reduction algorithm to be switched off. This can help you determine how much reduction is performed. assemble pattern.file | wc # versus assemble -r pattern.file | wc =item B<-s> Statistics. Print some statistics about the assembled pattern. The output is sent to STDERR (in order to allow the generated pattern to be redirected elsewhere). =item B<-S> Statistics only. Like B<-s>, except that the pattern itself is not output. Useful with B<-d 8> to see the time taken. =item B<-t> Test. Test the assembled expression against the contents of a file. Each line is read from the file and is matched against the pattern. Lines that fail to match are printed. In other words, no output is good output. In this mode of operation, error status is 1 in the case of a failure, 0 if all lines matched. =item B<-T> Time. Print statistics on the time taken to reduce and assemble the pattern. (This is merely a lazy person's synonym for C<-d 8>). =item B<-u> Unique. Carp if duplicate patterns are found. =item B<-U> Unroll. Transform C I into C (which may allow additional reductions). =item B<-v> Version. Print the version of the assemble script. =item B<-w> Word/Whole. When testing the contents of a file with C<-t>, bracket the expression with C<^> and C<$> in order to match the whole word or line from the file. =back =head1 DIAGNOSTICS Will print out a summary of the problem if an added pattern causes the assembly to fail. =head1 SEE ALSO L =head1 AUTHOR Copyright (C) 2004-2008 David Landgren. All rights reserved. =head1 LICENSE This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Regexp-Assemble-0.38/examples/track-5.100000755000175000017500000000050211022456775016044 0ustar ronron#! /usr/local/bin/perl5.9.5 use strict; use warnings; use lib 'blib/lib'; use Regexp::Assemble; my $r = Regexp::Assemble->new->track(1)->add(qw(foo? bar{2} [Rr]at)); for my $w (qw(this food is rather barren)) { if ($w =~ /$r/) { print "$w matched by ", $r->source($^R), $/; } else { print "$w no match\n"; } } Regexp-Assemble-0.38/examples/file.20000644000175000017500000000002511022301342015406 0ustar ronronbeat boat blot bleat Regexp-Assemble-0.38/TODO0000644000175000017500000000014512705017046013277 0ustar ronronFix Changes and Changelog.ini Andreas Konig => Andreas König David Rigaudiere => David Rigaudière Regexp-Assemble-0.38/MANIFEST.SKIP0000644000175000017500000000114413122054661014503 0ustar ronron# Avoid version control files. ,v$ \B\.cvsignore$ \B\.git\b \B\.gitignore\b \B\.svn\b \bCVS\b \bRCS\b # Avoid Makemaker generated and utility files. \bblib \bblibdirs$ \bpm_to_blib$ \bMakefile$ \bMakeMaker-\d # Avoid Module::Build generated and utility files. \b_build \bBuild$ \bBuild.bat$ # Avoid Devel::Cover generated files \bcover_db # Avoid temp and backup files. ~$ \#$ \.# \.bak$ \.old$ \.rej$ \.tmp$ # Avoid OS-specific files/dirs # Mac OSX metadata \B\.DS_Store # Mac OSX SMB mount metadata files \B\._ # Avoid UltraEdit files. \.prj$ \.pui$ ^MYMETA.yml$ ^MYMETA\.json$ ^Regexp-Assemble-.* Regexp-Assemble-0.38/README0000644000175000017500000003230211547334637013502 0ustar ronronThis file is the README for Regexp::Assemble version 0.35 INSTALLATION perl Makefile.PL make make test make install TESTING This module requires the following modules for thorough testing: Test::More Test::File::Contents Test::Pod Test::Pod::Coverage Test::Warn The test suite will make allowances for their eventual absence. It can also make use of Devel::Cover if available. UNINSTALLATION This is a pure-Perl module. The following one-liner should print out the canonical path of the file: perl -MRegexp::Assemble -le 'print $INC{"Regexp/Assemble.pm"}' Just delete this file. There is also the question of the man page. Finding that is left as an exercise to the reader. BASIC USAGE use Regexp::Assemble; my $ra = Regexp::Assemble->new; $ra->add( 'ab+c' ); $ra->add( 'ab+\\d*\\s+c' ); $ra->add( 'a\\w+\\d+' ); $ra->add( 'a\\d+' ); print $ra->re; # prints (?:a(?:b+(?:\d*\s+)?c|(?:\w+)?\d+)) or my $ra = Regexp::Assemble->new ->add( 'foo', 'bar', 'baz', 'foom' ); print "$_ matches\n" if /$ra/ for (qw/word more stuff food rabble bark/); or use Regexp::Assemble; my @word = qw/flip flop slip slop/; print Regexp::Assemble->new->add(@word)->as_string; # produces [fs]l[io]p print Regexp::Assemble->new->add(@word)->reduce(0)->as_string; # produces (?:fl(?:ip|op)|sl(?:ip|op)) See the ./eg directory for some example scripts. ADVANCED USAGE If you want to match things with exceptions, you can use a two stage process to build a pattern with negative lookbehind. Consider the following script: == example begin == use Regexp::Assemble; my $set = [ { accept => [qw[ .cnn.net .cnn.com ]], refuse => [qw[ ^media video ]], }, { accept => [qw[ .yahoo.com ]], }, ]; my $ra = Regexp::Assemble->new; for my $s( @$set ) { my $refuse = do { if( not exists $s->{refuse} ) { ''; } else { '(?new->add( @{$s->{refuse}} )->as_string . ')' } }; $ra->add( map { s/\./\\./g; "$refuse$_\$" } @{$s->{accept}} ); } my $re = $ra->re; print $ra->as_string, "\n"; while( <> ) { print; chomp; print "\t", (/$re/ ? 'yep' : 'nope'), "\n"; } == example end == and a datafile to run it on: == data begin == media.cnn.com more.video.cnn.net super.media.cnn.com video.cnn.net video.yahoo.com www.cnn.com www.cnn.net www.yahoo.com == data end == This lets us match arbitrary hosts within a domain, but at the same time excluding a subset of hosts that we wish to ignore. TRACKING REGULAR EXPRESSION MATCHES Regexp::Assemble can emit regular expressions that, when used correctly, can let you determine which original pattern gave rise to the match. This technique is known as tracking. == example begin == use strict; use Regexp::Assemble; my $dispatch = { 'a-(\\d+)' => sub { my $v = shift; print "speed $v->[1]\n"; }, 'a-(\\d+)-(\\d+)' => sub { my $v = shift; print "pressure $v->[1] over $v->[2]\n"; }, 'a-(\\w+)-(\\w+)' => sub { my $v = shift; print "message $v->[1] from $v->[2]\n"; }, }; my $re = Regexp::Assemble->new( track => 1 )->add( keys %$dispatch ); while( <> ) { chomp; if( $re->match($_) ) { $dispatch->{ $re->matched }( $re->mvar() ); } else { last if /q/; print "\tignored\n"; } } == example end == Run this and enter lines like a-234, a-654, a-345-345, a-dog-cat and so on. When the pattern matches a string, you can retrieve the pattern that caused the match to occur, and dispatch it to a routine that knows what to do about it. You can retrieve captured values too. In the above example, just remember that $v->[1] eq $1. $v->[0], a.k.a $re->mvar(0) happens to be the the same as the input parameter to match (although this is worked out from first principles, more or less, not simply by copying the parameter). I initially hoped that $^R would handle this sort of stuff for me, but there's a bug. Consider the following pattern: a(?{1}) (?: b(?{2}) )? (whitespace added for clarity). This pattern will match both the strings 'a' and 'ab', however, in both cases, $^R will be set to 1 aftewards. I would have hoped that after matching 'ab', that $^R would be set to 2. As of perl 5.9.5, this bug has been corrected in the regular expression engine, thanks to Yves Orton. Version 0.29 takes this into account, and as a result re 'eval' is no longer required in Perl 5.10. IMPLEMENTATION Consider a simple pattern 'costructive' we want to use to match against strings. This pattern is split into tokens, and is stored in a list: [c o n s t r u c t i v e] At this point, if we want to produce a regular expression, we only need to join it up again: my $pattern = join( '' => @path); my $re = qr/$pattern/; Consider a second pattern 'containment'. Split into a list gives: [c o n t a i n m e n t] We then have to merge this second path into the first path. At some point, the paths diverge. The first element path the point of divergence in the first path is replace by a node (a hash) and the two different paths carry on from there: [c o n |s => [s t r u c t i v e] \t => [t a i n m e n t] ] And then 'confinement': [c o n |s => [s t r u c t i v e] |t => [t a i n m e n t] \f => [f i n e m e n t] ] What happens if we add a path that runs out in the middle of a previous path? We add a node, and a "null-path" to indicate that the path can both continue on, and can also stop here: Add 'construct': [c o n |s => [s t r u c t | | '' => undef | \ i => [i v e] | ] |t => [t a i n m e n t] \f => [f i n e m e n t] ] It should be obvious to see how the contruct branch will produce the pattern /construct(?:ive)?/ . Or for a longer path 'constructively': [c o n |s => [s t r u c t | | '' => undef | \ i => [i v e | | '' => undef | \ l => [l y] | ] | ] |t => [t a i n m e n t] \f => [f i n e m e n t] ] This is the state of the internal structure before reduction. When traversed it will produce a valid regular expression. The trick is how to perform the reduction. The key insight is to note that for any part of the trunk where the sibling paths do not end in a node, it it possible to reverse them, and insert them into their own R::A object and see what comes out: [t a i n m e n t] => [t n e m n i a t] [f i n e m e n t] => [t n e m e n i f] Gives: [t n e m | n => [n i a t] \ e => [e n i f] ] When the algorithm visits the other path (s => [s t r u c t ...]), it behaves differently. When a null path is seen, no reduction is performed at that node level. The resulting path would otherwise begin to admit matches that are are not permitted by any of the initial patterns. For instance, with bat, cat, and catty, you can hardly try to merge 'bat' and 'cat' to produce [bc]at, otherwise the resulting pattern would become [bc]at(ty)?, and that would incorrectly match 'batty'. After having visited the s, t, and f paths, the result is that t and f were reduced, and s failed. We therefore unreverse everything, and signal that this node cannot participate in any more reduction (the failures percolate up the tree back to the root). Unreversing the t, f reduction gives: [ t => [t a i n] \ f => [f i n e] | m e n t ] When all is said and done, the final result gives [c o n |s => [s t r u c t | | '' => undef | \ i => [i v e | | '' => undef | \ l => [l y] | ] | ] [ t => [t a i n] f => [f i n e] m e n t ] ] When this data structure is traversed to build the pattern, it gives con(struct(ive(ly)?)?|(fine|tain)ment) NB: The capturing syntax is used here, instead of the grouping syntax for readability issues only. On the other hand, if the s path contained only [s t r u c t], then the reduction would have gone succeeded. We would have a common head [t], shared by all three paths. [t | c => [c u r t s] \ n => [n e m | n => [n i a t] \ e => [e n i f] ] ] And then consider that the path [c o u r t] had also been added to the object. We would then be able to reduce the t from the above reduction, and the t in [c o u r t] [c o | n => [n | | s => [s t r u c t] | | t => [t a i n m e n t] | \ f => [f i n e m e n t] | ] \ u => [u r t] ] gives [c o | n => [n | | s => [s t r u c] | \ f => [ | f => [f i n e] | t => [t a i n] | m e n | ] | ] \ u => [u r] t ] (Here ends my ASCII art talents). The above structure would give co(n(struc|(fine|tai)men)|ur)t In a nutshell, that's it. Seems like the code would be simple, huh? It turns out that no, there are lots of fiddly edge cases, especially sets of paths are the same as other sets of paths except for an optional sub-path. The canonical example that the test suite deals with is: showeriness, showerless, showiness, showless. The final pattern is show(er)?(in|l)ess If there are bugs to be found, it will be in cases that are even more pathological than this, e.g., something like: show(er)?(i(a|po)?n|l)ess (although the above actually *does* work, I tried it) TESTING STRATEGY USED The code has been heavily tested using an approach based on combinatoric lists known as power sets. For instance, the power set of (a,b,c,d) is (assuming a join() on the results): a ab abc abcd abd ac acd ad b bc bcd bd c cd d (along with the empty set). The power set of N elements contains 2**N elements. (or 2**N-1 of we exclude the empty set). The testing approach was then to take the power set of the above power set and produce regular expressions from each element. For instance, at some point, we would encounter the set abc ac bcd cd d From this we generate the pattern (?:(?:b?c)?d|ab?c). Once we have this pattern, we go back and check that it does in fact match the above 5 elements, and furthermore, that it does *not match* the remaining 10 elements of the power set not used in this iteration. And yes, that shook out a couple of bugs. As of this time, the following search space has been examined a b c - complete a b c d - complete a b c d e - runs of 1-11, 20-31 complete, 12-17 partial a b c d e f - runs of 1-5, 61-63 complete a b c d e f g - runs of 1-4, 125-127 complete The code for this is in the eg/stress-test script. Note: it can use months of CPU time if you're not careful. It requires the following modules: Algorithm::Combinatorics Data::PowerSet OTHER CONSIDERATIONS When tracking is in use, no reduction is performed. Pretty-printed (indented), and tracking is handled merely by calling different output routines. Each routine emits things in a different way, but the underlying structure remains the same. Which is one reason why you can't have pretty-printed tracked patterns (Well you can, but I haven't written the routine that would do so). Zero-width lookahead assertions can be added to the pattern. This may be a win, but it may also slow things down. DEBUGGING NOTES If you are curious, you can dump out the internal data struct with the following: use Data::Dumper; $Data::Dumper::Terse = 0; $Data::Dumper::Indent = 0; $Data::Dumper::Quotekeys = 0; $Data::Dumper::Pair = '=>'; print Dumper($r->_path); A more compact representation can be obtained with print $r->dump; All that said, I'm now reasonably confident that it deals correctly with pretty much anything you're likely to throw at it. Two recent bugs were easy to spot in the code, and the fix was a couple of lines. Adding lookahead assertion was pretty simple to, even if it did result in a certain amount of code factoring. So I think that in general the structure of the code is a good one. The eg/debugging script offers a good strategy for dealing with assemblies that give rise to uncompilable patterns. STATUS This module is under active development. The module is managed in a Subversion repository, and thus, the latest working copy is available at http://svnweb.mongueurs.net/Regexp-Assemble/trunk AUTHOR David Landgren I do appreciate getting e-mail, especially about Perl. Please keep in mind that I get a lot of spam, and take drastic measures to reduce the flow. One of the measures involves a gigantic regular expression that contains many thousands of patterns that match hostnames of dynamic dialup/residential/home IP addresses. That pattern is of course built with this module. It would be ironic if I rejected your mail coming from such an address. Please use your ISP's outbound MX, or pay what it takes to get your reverse DNS changed to something else. COPYRIGHT This module is copyright (C) David Landgren 2004-2008. All rights reserved. LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Regexp-Assemble-0.38/META.json0000644000175000017500000000247513122055201014225 0ustar ronron{ "abstract" : "Assemble multiple Regular Expressions into a single RE", "author" : [ "David Landgren" ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.22, CPAN::Meta::Converter version 2.150005", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Regexp-Assemble", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "constant" : "0", "strict" : "0", "vars" : "0", "warnings" : "0" } }, "test" : { "requires" : { "Test::More" : "1.001014" } } }, "release_status" : "stable", "resources" : { "repository" : { "type" : "git", "url" : "https://github.com/ronsavage/Regexp-Assemble.git", "web" : "https://github.com/ronsavage/Regexp-Assemble" } }, "version" : "0.38", "x_serialization_backend" : "JSON::PP version 2.27400" } Regexp-Assemble-0.38/Makefile.PL0000644000175000017500000000244613122052522014557 0ustar ronronuse strict; use warnings; use ExtUtils::MakeMaker; eval "use ExtUtils::MakeMaker::Coverage"; if ( $@ ) { print "Skipping testcover target, ExtUtils::MakeMaker::Coverage not found\n"; } else { print "Adding testcover target\n"; } my(%params) = ( AUTHOR => 'David Landgren', ABSTRACT => 'Assemble multiple Regular Expressions into a single RE', clean => { FILES => 'cover_db blib/* Makefile MANIFEST Regexp-Assemble-*' }, dist => { COMPRESS => 'gzip', SUFFIX => 'gz' }, DISTNAME => 'Regexp-Assemble', NAME => 'Regexp::Assemble', PREREQ_PM => { 'constant' => 0, 'strict' => 0, 'vars' => 0, 'warnings' => 0, }, TEST_REQUIRES => { 'Test::More' => 1.001014, }, VERSION_FROM => 'lib/Regexp/Assemble.pm', ); if ( ($ExtUtils::MakeMaker::VERSION =~ /^\d\.\d\d$/) && ($ExtUtils::MakeMaker::VERSION > 6.30) ) { $params{LICENSE} = 'perl'; } if ($ExtUtils::MakeMaker::VERSION ge '6.46') { $params{META_MERGE} = { 'meta-spec' => { 'version' => 2, }, resources => { 'bugtracker' => 'https://rt.cpan.org/Public/Dist/Display.html?Name=Regexp-Assemble', repository => { 'type' => 'git', 'url' => 'https://github.com/ronsavage/Regexp-Assemble.git', 'web' => 'https://github.com/ronsavage/Regexp-Assemble', }, }, }; } WriteMakefile(%params); Regexp-Assemble-0.38/lib/0000755000175000017500000000000013122055201013342 5ustar ronronRegexp-Assemble-0.38/lib/Regexp/0000755000175000017500000000000013122055201014574 5ustar ronronRegexp-Assemble-0.38/lib/Regexp/Assemble.pm0000644000175000017500000033756113122055177016720 0ustar ronron# Regexp::Assemple.pm # # Copyright (c) 2004-2011 David Landgren # All rights reserved package Regexp::Assemble; use strict; use warnings; use constant DEBUG_ADD => 1; use constant DEBUG_TAIL => 2; use constant DEBUG_LEX => 4; use constant DEBUG_TIME => 8; use vars qw/$have_Storable $Current_Lexer $Default_Lexer $Single_Char $Always_Fail/; # The following patterns were generated with examples/naive. $Default_Lexer = qr/(?![[(\\]).(?:[*+?]\??|\{\d+(?:,\d*)?\}\??)?|\\(?:[bABCEGLQUXZ]|[lu].|(?:[^\w]|[aefnrtdDwWsS]|c.|0\d{2}|x(?:[\da-fA-F]{2}|{[\da-fA-F]{4}})|N\{\w+\}|[Pp](?:\{\w+\}|.))(?:[*+?]\??|\{\d+(?:,\d*)?\}\??)?)|\[.*?(?_debug(DEBUG_TIME)) { $self->_init_time_func(); $self->{_begin_time} = $self->{_time_func}->(); } $self->{input_record_separator} = delete $self->{rs} if exists $self->{rs}; exists $self->{file} and $self->add_file($self->{file}); return $self; } sub _init_time_func { my $self = shift; return if exists $self->{_time_func}; # attempt to improve accuracy if (!defined($self->{_use_time_hires})) { eval {require Time::HiRes}; $self->{_use_time_hires} = $@; } $self->{_time_func} = length($self->{_use_time_hires}) > 0 ? sub { time } : \&Time::HiRes::time ; } sub clone { my $self = shift; my $clone; my @attr = grep {$_ ne 'path'} keys %$self; @{$clone}{@attr} = @{$self}{@attr}; $clone->{path} = _path_clone($self->_path); bless $clone, ref($self); } sub _fastlex { my $self = shift; my $record = shift; my $len = 0; my @path = (); my $case = ''; my $qm = ''; my $debug = $self->{debug} & DEBUG_LEX; my $unroll_plus = $self->{unroll_plus}; my $token; my $qualifier; $debug and print "# _lex <$record>\n"; my $modifier = q{(?:[*+?]\\??|\\{(?:\\d+(?:,\d*)?|,\d+)\\}\\??)?}; my $class_matcher = qr/\[(?:\[:[a-z]+:\]|\\?.)*?\]/; my $paren_matcher = qr/\(.*?(? <$qualifier>\n"; if ($qm) { $token = quotemeta($token); $token =~ s/^\\([^\w$()*+.?@\[\\\]^|{}\/])$/$1/; } else { $token =~ s{\A([][{}*+?@\\/])\Z}{\\$1}; } if ($unroll_plus and $qualifier =~ s/\A\+(\?)?\Z/*/) { $1 and $qualifier .= $1; $debug and print " unroll <$token><$token><$qualifier>\n"; $case and $token = $case eq 'L' ? lc($token) : uc($token); push @path, $token, "$token$qualifier"; } else { $debug and print " clean <$token>\n"; push @path, $case eq 'L' ? lc($token).$qualifier : $case eq 'U' ? uc($token).$qualifier : $token.$qualifier ; } redo; } elsif ($record =~ /\G\\/gc) { $debug and print "# backslash\n"; # backslash if ($record =~ /\G([sdwSDW])($modifier)/gc) { ($token, $qualifier) = ($1, $2); $debug and print "# meta <$token> <$qualifier>\n"; push @path, ($unroll_plus and $qualifier =~ s/\A\+(\?)?\Z/*/) ? ("\\$token", "\\$token$qualifier" . (defined $1 ? $1 : '')) : "\\$token$qualifier"; } elsif ($record =~ /\Gx([\da-fA-F]{2})($modifier)/gc) { $debug and print "# x $1\n"; $token = quotemeta(chr(hex($1))); $qualifier = $2; $debug and print "# cooked <$token>\n"; $token =~ s/^\\([^\w$()*+.?\[\\\]^|{\/])$/$1/; # } balance $debug and print "# giving <$token>\n"; push @path, ($unroll_plus and $qualifier =~ s/\A\+(\?)?\Z/*/) ? ($token, "$token$qualifier" . (defined $1 ? $1 : '')) : "$token$qualifier"; } elsif ($record =~ /\GQ/gc) { $debug and print "# Q\n"; $qm = 1; $matcher = $qm_matcher; } elsif ($record =~ /\G([LU])/gc) { $debug and print "# case $1\n"; $case = $1; } elsif ($record =~ /\GE/gc) { $debug and print "# E\n"; $case = $qm = ''; $matcher = $regular_matcher; } elsif ($record =~ /\G([lu])(.)/gc) { $debug and print "# case $1 to <$2>\n"; push @path, $1 eq 'l' ? lc($2) : uc($2); } elsif (my @arg = grep {defined} $record =~ /\G$misc_matcher/gc) { if ($] < 5.007) { my $len = 0; $len += length($_) for @arg; $debug and print "# pos ", pos($record), " fixup add $len\n"; pos($record) = pos($record) + $len; } my $directive = shift @arg; if ($directive eq 'c') { $debug and print "# ctrl <@arg>\n"; push @path, "\\c" . uc(shift @arg); } else { # elsif ($directive eq '0') { $debug and print "# octal <@arg>\n"; my $ascii = oct(shift @arg); push @path, ($ascii < 32) ? "\\c" . chr($ascii+64) : chr($ascii) ; } $path[-1] .= join( '', @arg ); # if @arg; redo; } elsif ($record =~ /\G(.)/gc) { $token = $1; $token =~ s{[AZabefnrtz\[\]{}()\\\$*+.?@|/^]}{\\$token}; $debug and print "# meta <$token>\n"; push @path, $token; } else { $debug and print "# ignore char at ", pos($record), " of <$record>\n"; } redo; } elsif ($record =~ /\G($class_matcher)($modifier)/gc) { # [class] followed by a modifer my $class = $1; my $qualifier = defined $2 ? $2 : ''; $debug and print "# class begin <$class> <$qualifier>\n"; if ($class =~ /\A\[\\?(.)]\Z/) { $class = quotemeta $1; $class =~ s{\A\\([!@%])\Z}{$1}; $debug and print "# class unwrap $class\n"; } $debug and print "# class end <$class> <$qualifier>\n"; push @path, ($unroll_plus and $qualifier =~ s/\A\+(\?)?\Z/*/) ? ($class, "$class$qualifier" . (defined $1 ? $1 : '')) : "$class$qualifier"; redo; } elsif ($record =~ /\G($paren_matcher)/gc) { $debug and print "# paren <$1>\n"; # (paren) followed by a modifer push @path, $1; redo; } } return \@path; } sub _lex { my $self = shift; my $record = shift; my $len = 0; my @path = (); my $case = ''; my $qm = ''; my $re = defined $self->{lex} ? $self->{lex} : defined $Current_Lexer ? $Current_Lexer : $Default_Lexer; my $debug = $self->{debug} & DEBUG_LEX; $debug and print "# _lex <$record>\n"; my ($token, $next_token, $diff, $token_len); while( $record =~ /($re)/g ) { $token = $1; $token_len = length($token); $debug and print "# lexed <$token> len=$token_len\n"; if( pos($record) - $len > $token_len ) { $next_token = $token; $token = substr( $record, $len, $diff = pos($record) - $len - $token_len ); $debug and print "# recover <", substr( $record, $len, $diff ), "> as <$token>, save <$next_token>\n"; $len += $diff; } $len += $token_len; TOKEN: { if( substr( $token, 0, 1 ) eq '\\' ) { if( $token =~ /^\\([ELQU])$/ ) { if( $1 eq 'E' ) { $qm and $re = defined $self->{lex} ? $self->{lex} : defined $Current_Lexer ? $Current_Lexer : $Default_Lexer; $case = $qm = ''; } elsif( $1 eq 'Q' ) { $qm = $1; # switch to a more precise lexer to quotemeta individual characters $re = qr/\\?./; } else { $case = $1; } $debug and print "# state change qm=<$qm> case=<$case>\n"; goto NEXT_TOKEN; } elsif( $token =~ /^\\([lu])(.)$/ ) { $debug and print "# apply case=<$1> to <$2>\n"; push @path, $1 eq 'l' ? lc($2) : uc($2); goto NEXT_TOKEN; } elsif( $token =~ /^\\x([\da-fA-F]{2})$/ ) { $token = quotemeta(chr(hex($1))); $debug and print "# cooked <$token>\n"; $token =~ s/^\\([^\w$()*+.?@\[\\\]^|{\/])$/$1/; # } balance $debug and print "# giving <$token>\n"; } else { $token =~ s/^\\([^\w$()*+.?@\[\\\]^|{\/])$/$1/; # } balance $debug and print "# backslashed <$token>\n"; } } else { $case and $token = $case eq 'U' ? uc($token) : lc($token); $qm and $token = quotemeta($token); $token = '\\/' if $token eq '/'; } # undo quotemeta's brute-force escapades $qm and $token =~ s/^\\([^\w$()*+.?@\[\\\]^|{}\/])$/$1/; $debug and print "# <$token> case=<$case> qm=<$qm>\n"; push @path, $token; NEXT_TOKEN: if( defined $next_token ) { $debug and print "# redo <$next_token>\n"; $token = $next_token; $next_token = undef; redo TOKEN; } } } if( $len < length($record) ) { # NB: the remainder only arises in the case of degenerate lexer, # and if \Q is operative, the lexer will have been switched to # /\\?./, which means there can never be a remainder, so we # don't have to bother about quotemeta. In other words: # $qm will never be true in this block. my $remain = substr($record,$len); $case and $remain = $case eq 'U' ? uc($remain) : lc($remain); $debug and print "# add remaining <$remain> case=<$case> qm=<$qm>\n"; push @path, $remain; } $debug and print "# _lex out <@path>\n"; return \@path; } sub add { my $self = shift; my $record; my $debug = $self->{debug} & DEBUG_LEX; while( defined( $record = shift @_ )) { CORE::chomp($record) if $self->{chomp}; next if $self->{pre_filter} and not $self->{pre_filter}->($record); $debug and print "# add <$record>\n"; $self->{stats_raw} += length $record; my $list = $record =~ /[+*?(\\\[{]/ # }]) restore equilibrium ? $self->{lex} ? $self->_lex($record) : $self->_fastlex($record) : [split //, $record] ; next if $self->{filter} and not $self->{filter}->(@$list); $self->_insertr( $list ); } return $self; } sub add_file { my $self = shift; my $rs; my @file; if (ref($_[0]) eq 'HASH') { my $arg = shift; $rs = $arg->{rs} || $arg->{input_record_separator} || $self->{input_record_separator} || $/; @file = ref($arg->{file}) eq 'ARRAY' ? @{$arg->{file}} : $arg->{file}; } else { $rs = $self->{input_record_separator} || $/; @file = @_; } local $/ = $rs; my $file; for $file (@file) { open my $fh, '<', $file or do { require Carp; Carp::croak("cannot open $file for input: $!"); }; while (defined (my $rec = <$fh>)) { $self->add($rec); } close $fh; } return $self; } sub insert { my $self = shift; return if $self->{filter} and not $self->{filter}->(@_); $self->_insertr( [@_] ); return $self; } sub _insertr { my $self = shift; my $dup = $self->{stats_dup} || 0; $self->{path} = $self->_insert_path( $self->_path, $self->_debug(DEBUG_ADD), $_[0] ); if( not defined $self->{stats_dup} or $dup == $self->{stats_dup} ) { ++$self->{stats_add}; $self->{stats_cooked} += defined($_) ? length($_) : 0 for @{$_[0]}; } elsif( $self->{dup_warn} ) { if( ref $self->{dup_warn} eq 'CODE' ) { $self->{dup_warn}->($self, $_[0]); } else { my $pattern = join( '', @{$_[0]} ); require Carp; Carp::carp("duplicate pattern added: /$pattern/"); } } $self->{str} = $self->{re} = undef; } sub lexstr { return shift->_lex(shift); } sub pre_filter { my $self = shift; my $pre_filter = shift; if( defined $pre_filter and ref($pre_filter) ne 'CODE' ) { require Carp; Carp::croak("pre_filter method not passed a coderef"); } $self->{pre_filter} = $pre_filter; return $self; } sub filter { my $self = shift; my $filter = shift; if( defined $filter and ref($filter) ne 'CODE' ) { require Carp; Carp::croak("filter method not passed a coderef"); } $self->{filter} = $filter; return $self; } sub as_string { my $self = shift; if( not defined $self->{str} ) { if( $self->{track} ) { $self->{m} = undef; $self->{mcount} = 0; $self->{mlist} = []; $self->{str} = _re_path_track($self, $self->_path, '', ''); } else { $self->_reduce unless ($self->{mutable} or not $self->{reduce}); my $arg = {@_}; $arg->{indent} = $self->{indent} if not exists $arg->{indent} and $self->{indent} > 0; if( exists $arg->{indent} and $arg->{indent} > 0 ) { $arg->{depth} = 0; $self->{str} = _re_path_pretty($self, $self->_path, $arg); } elsif( $self->{lookahead} ) { $self->{str} = _re_path_lookahead($self, $self->_path); } else { $self->{str} = _re_path($self, $self->_path); } } if (not length $self->{str}) { # explicitly fail to match anything if no pattern was generated $self->{str} = $Always_Fail; } else { my $begin = $self->{anchor_word_begin} ? '\\b' : $self->{anchor_line_begin} ? '^' : $self->{anchor_string_begin} ? '\A' : '' ; my $end = $self->{anchor_word_end} ? '\\b' : $self->{anchor_line_end} ? '$' : $self->{anchor_string_end} ? '\Z' : $self->{anchor_string_end_absolute} ? '\z' : '' ; $self->{str} = "$begin$self->{str}$end"; } $self->{path} = [] unless $self->{mutable}; } return $self->{str}; } sub re { my $self = shift; $self->_build_re($self->as_string(@_)) unless defined $self->{re}; return $self->{re}; } use overload '""' => sub { my $self = shift; return $self->{re} if $self->{re}; $self->_build_re($self->as_string()); return $self->{re}; }; sub _build_re { my $self = shift; my $str = shift; if( $self->{track} ) { use re 'eval'; $self->{re} = length $self->{flags} ? qr/(?$self->{flags}:$str)/ : qr/$str/ ; } else { # how could I not repeat myself? $self->{re} = length $self->{flags} ? qr/(?$self->{flags}:$str)/ : qr/$str/ ; } } sub match { my $self = shift; my $target = shift; $self->_build_re($self->as_string(@_)) unless defined $self->{re}; $self->{m} = undef; $self->{mvar} = []; if( not $target =~ /$self->{re}/ ) { $self->{mbegin} = []; $self->{mend} = []; return undef; } $self->{m} = $^R if $] >= 5.009005; $self->{mbegin} = _path_copy([@-]); $self->{mend} = _path_copy([@+]); my $n = 0; for( my $n = 0; $n < @-; ++$n ) { push @{$self->{mvar}}, substr($target, $-[$n], $+[$n] - $-[$n]) if defined $-[$n] and defined $+[$n]; } if( $self->{track} ) { return defined $self->{m} ? $self->{mlist}[$self->{m}] : 1; } else { return 1; } } sub source { my $self = shift; return unless $self->{track}; defined($_[0]) and return $self->{mlist}[$_[0]]; return unless defined $self->{m}; return $self->{mlist}[$self->{m}]; } sub mbegin { my $self = shift; return exists $self->{mbegin} ? $self->{mbegin} : []; } sub mend { my $self = shift; return exists $self->{mend} ? $self->{mend} : []; } sub mvar { my $self = shift; return undef unless exists $self->{mvar}; return defined($_[0]) ? $self->{mvar}[$_[0]] : $self->{mvar}; } sub capture { my $self = shift; if( $self->{mvar} ) { my @capture = @{$self->{mvar}}; shift @capture; return @capture; } return (); } sub matched { my $self = shift; return defined $self->{m} ? $self->{mlist}[$self->{m}] : undef; } sub stats_add { my $self = shift; return $self->{stats_add} || 0; } sub stats_dup { my $self = shift; return $self->{stats_dup} || 0; } sub stats_raw { my $self = shift; return $self->{stats_raw} || 0; } sub stats_cooked { my $self = shift; return $self->{stats_cooked} || 0; } sub stats_length { my $self = shift; return (defined $self->{str} and $self->{str} ne $Always_Fail) ? length $self->{str} : 0; } sub dup_warn { my $self = shift; $self->{dup_warn} = defined($_[0]) ? $_[0] : 1; return $self; } sub anchor_word_begin { my $self = shift; $self->{anchor_word_begin} = defined($_[0]) ? $_[0] : 1; return $self; } sub anchor_word_end { my $self = shift; $self->{anchor_word_end} = defined($_[0]) ? $_[0] : 1; return $self; } sub anchor_word { my $self = shift; my $state = shift; $self->anchor_word_begin($state)->anchor_word_end($state); return $self; } sub anchor_line_begin { my $self = shift; $self->{anchor_line_begin} = defined($_[0]) ? $_[0] : 1; return $self; } sub anchor_line_end { my $self = shift; $self->{anchor_line_end} = defined($_[0]) ? $_[0] : 1; return $self; } sub anchor_line { my $self = shift; my $state = shift; $self->anchor_line_begin($state)->anchor_line_end($state); return $self; } sub anchor_string_begin { my $self = shift; $self->{anchor_string_begin} = defined($_[0]) ? $_[0] : 1; return $self; } sub anchor_string_end { my $self = shift; $self->{anchor_string_end} = defined($_[0]) ? $_[0] : 1; return $self; } sub anchor_string_end_absolute { my $self = shift; $self->{anchor_string_end_absolute} = defined($_[0]) ? $_[0] : 1; return $self; } sub anchor_string { my $self = shift; my $state = defined($_[0]) ? $_[0] : 1; $self->anchor_string_begin($state)->anchor_string_end($state); return $self; } sub anchor_string_absolute { my $self = shift; my $state = defined($_[0]) ? $_[0] : 1; $self->anchor_string_begin($state)->anchor_string_end_absolute($state); return $self; } sub debug { my $self = shift; $self->{debug} = defined($_[0]) ? $_[0] : 0; if ($self->_debug(DEBUG_TIME)) { # hmm, debugging time was switched on after instantiation $self->_init_time_func; $self->{_begin_time} = $self->{_time_func}->(); } return $self; } sub dump { return _dump($_[0]->_path); } sub chomp { my $self = shift; $self->{chomp} = defined($_[0]) ? $_[0] : 1; return $self; } sub fold_meta_pairs { my $self = shift; $self->{fold_meta_pairs} = defined($_[0]) ? $_[0] : 1; return $self; } sub indent { my $self = shift; $self->{indent} = defined($_[0]) ? $_[0] : 0; return $self; } sub lookahead { my $self = shift; $self->{lookahead} = defined($_[0]) ? $_[0] : 1; return $self; } sub flags { my $self = shift; $self->{flags} = defined($_[0]) ? $_[0] : ''; return $self; } sub modifiers { my $self = shift; return $self->flags(@_); } sub track { my $self = shift; $self->{track} = defined($_[0]) ? $_[0] : 1; return $self; } sub unroll_plus { my $self = shift; $self->{unroll_plus} = defined($_[0]) ? $_[0] : 1; return $self; } sub lex { my $self = shift; $self->{lex} = qr($_[0]); return $self; } sub reduce { my $self = shift; $self->{reduce} = defined($_[0]) ? $_[0] : 1; return $self; } sub mutable { my $self = shift; $self->{mutable} = defined($_[0]) ? $_[0] : 1; return $self; } sub reset { # reinitialise the internal state of the object my $self = shift; $self->{path} = []; $self->{re} = undef; $self->{str} = undef; return $self; } sub Default_Lexer { if( $_[0] ) { if( my $refname = ref($_[0]) ) { require Carp; Carp::croak("Cannot pass a $refname to Default_Lexer"); } $Current_Lexer = $_[0]; } return defined $Current_Lexer ? $Current_Lexer : $Default_Lexer; } # --- no user serviceable parts below --- # -- debug helpers sub _debug { my $self = shift; return $self->{debug} & shift() ? 1 : 0; } # -- helpers sub _path { # access the path return $_[0]->{path}; } # -- the heart of the matter $have_Storable = do { eval { require Storable; import Storable 'dclone'; }; $@ ? 0 : 1; }; sub _path_clone { $have_Storable ? dclone($_[0]) : _path_copy($_[0]); } sub _path_copy { my $path = shift; my $new = []; for( my $p = 0; $p < @$path; ++$p ) { if( ref($path->[$p]) eq 'HASH' ) { push @$new, _node_copy($path->[$p]); } elsif( ref($path->[$p]) eq 'ARRAY' ) { push @$new, _path_copy($path->[$p]); } else { push @$new, $path->[$p]; } } return $new; } sub _node_copy { my $node = shift; my $new = {}; while( my( $k, $v ) = each %$node ) { $new->{$k} = defined($v) ? _path_copy($v) : undef ; } return $new; } sub _insert_path { my $self = shift; my $list = shift; my $debug = shift; my @in = @{shift()}; # create a new copy if( @$list == 0 ) { # special case the first time if( @in == 0 or (@in == 1 and (not defined $in[0] or $in[0] eq ''))) { return [{'' => undef}]; } else { return \@in; } } $debug and print "# _insert_path @{[_dump(\@in)]} into @{[_dump($list)]}\n"; my $path = $list; my $offset = 0; my $token; if( not @in ) { if( ref($list->[0]) ne 'HASH' ) { return [ { '' => undef, $list->[0] => $list } ]; } else { $list->[0]{''} = undef; return $list; } } while( defined( $token = shift @in )) { if( ref($token) eq 'HASH' ) { $debug and print "# p0=", _dump($path), "\n"; $path = $self->_insert_node( $path, $offset, $token, $debug, @in ); $debug and print "# p1=", _dump($path), "\n"; last; } if( ref($path->[$offset]) eq 'HASH' ) { $debug and print "# at (off=$offset len=@{[scalar @$path]}) ", _dump($path->[$offset]), "\n"; my $node = $path->[$offset]; if( exists( $node->{$token} )) { if ($offset < $#$path) { my $new = { $token => [$token, @in], _re_path($self, [$node]) => [@{$path}[$offset..$#$path]], }; splice @$path, $offset, @$path-$offset, $new; last; } else { $debug and print "# descend key=$token @{[_dump($node->{$token})]}\n"; $path = $node->{$token}; $offset = 0; redo; } } else { $debug and print "# add path ($token:@{[_dump(\@in)]}) into @{[_dump($path)]} at off=$offset to end=@{[scalar $#$path]}\n"; if( $offset == $#$path ) { $node->{$token} = [ $token, @in ]; } else { my $new = { _node_key($token) => [ $token, @in ], _node_key($node) => [@{$path}[$offset..$#{$path}]], }; splice( @$path, $offset, @$path - $offset, $new ); $debug and print "# fused node=@{[_dump($new)]} path=@{[_dump($path)]}\n"; } last; } } if( $debug ) { my $msg = ''; my $n; for( $n = 0; $n < @$path; ++$n ) { $msg .= ' ' if $n; my $atom = ref($path->[$n]) eq 'HASH' ? '{'.join( ' ', keys(%{$path->[$n]})).'}' : $path->[$n] ; $msg .= $n == $offset ? "<$atom>" : $atom; } print "# at path ($msg)\n"; } if( $offset >= @$path ) { push @$path, { $token => [ $token, @in ], '' => undef }; $debug and print "# added remaining @{[_dump($path)]}\n"; last; } elsif( $token ne $path->[$offset] ) { $debug and print "# token $token not present\n"; splice @$path, $offset, @$path-$offset, { length $token ? ( _node_key($token) => [$token, @in]) : ( '' => undef ) , $path->[$offset] => [@{$path}[$offset..$#{$path}]], }; $debug and print "# path=@{[_dump($path)]}\n"; last; } elsif( not @in ) { $debug and print "# last token to add\n"; if( defined( $path->[$offset+1] )) { ++$offset; if( ref($path->[$offset]) eq 'HASH' ) { $debug and print "# add sentinel to node\n"; $path->[$offset]{''} = undef; } else { $debug and print "# convert <$path->[$offset]> to node for sentinel\n"; splice @$path, $offset, @$path-$offset, { '' => undef, $path->[$offset] => [ @{$path}[$offset..$#{$path}] ], }; } } else { # already seen this pattern ++$self->{stats_dup}; } last; } # if we get here then @_ still contains a token ++$offset; } $list; } sub _insert_node { my $self = shift; my $path = shift; my $offset = shift; my $token = shift; my $debug = shift; my $path_end = [@{$path}[$offset..$#{$path}]]; # NB: $path->[$offset] and $[path_end->[0] are equivalent my $token_key = _re_path($self, [$token]); $debug and print "# insert node(@{[_dump($token)]}:@{[_dump(\@_)]}) (key=$token_key)", " at path=@{[_dump($path_end)]}\n"; if( ref($path_end->[0]) eq 'HASH' ) { if( exists($path_end->[0]{$token_key}) ) { if( @$path_end > 1 ) { my $path_key = _re_path($self, [$path_end->[0]]); my $new = { $path_key => [ @$path_end ], $token_key => [ $token, @_ ], }; $debug and print "# +bifurcate new=@{[_dump($new)]}\n"; splice( @$path, $offset, @$path_end, $new ); } else { my $old_path = $path_end->[0]{$token_key}; my $new_path = []; while( @$old_path and _node_eq( $old_path->[0], $token )) { $debug and print "# identical nodes in sub_path ", ref($token) ? _dump($token) : $token, "\n"; push @$new_path, shift(@$old_path); $token = shift @_; } if( @$new_path ) { my $new; my $token_key = $token; if( @_ ) { $new = { _re_path($self, $old_path) => $old_path, $token_key => [$token, @_], }; $debug and print "# insert_node(bifurc) n=@{[_dump([$new])]}\n"; } else { $debug and print "# insert $token into old path @{[_dump($old_path)]}\n"; if( @$old_path ) { $new = ($self->_insert_path( $old_path, $debug, [$token] ))->[0]; } else { $new = { '' => undef, $token => [$token] }; } } push @$new_path, $new; } $path_end->[0]{$token_key} = $new_path; $debug and print "# +_insert_node result=@{[_dump($path_end)]}\n"; splice( @$path, $offset, @$path_end, @$path_end ); } } elsif( not _node_eq( $path_end->[0], $token )) { if( @$path_end > 1 ) { my $path_key = _re_path($self, [$path_end->[0]]); my $new = { $path_key => [ @$path_end ], $token_key => [ $token, @_ ], }; $debug and print "# path->node1 at $path_key/$token_key @{[_dump($new)]}\n"; splice( @$path, $offset, @$path_end, $new ); } else { $debug and print "# next in path is node, trivial insert at $token_key\n"; $path_end->[0]{$token_key} = [$token, @_]; splice( @$path, $offset, @$path_end, @$path_end ); } } else { while( @$path_end and _node_eq( $path_end->[0], $token )) { $debug and print "# identical nodes @{[_dump([$token])]}\n"; shift @$path_end; $token = shift @_; ++$offset; } if( @$path_end ) { $debug and print "# insert at $offset $token:@{[_dump(\@_)]} into @{[_dump($path_end)]}\n"; $path_end = $self->_insert_path( $path_end, $debug, [$token, @_] ); $debug and print "# got off=$offset s=@{[scalar @_]} path_add=@{[_dump($path_end)]}\n"; splice( @$path, $offset, @$path - $offset, @$path_end ); $debug and print "# got final=@{[_dump($path)]}\n"; } else { $token_key = _node_key($token); my $new = { '' => undef, $token_key => [ $token, @_ ], }; $debug and print "# convert opt @{[_dump($new)]}\n"; push @$path, $new; } } } else { if( @$path_end ) { my $new = { $path_end->[0] => [ @$path_end ], $token_key => [ $token, @_ ], }; $debug and print "# atom->node @{[_dump($new)]}\n"; splice( @$path, $offset, @$path_end, $new ); $debug and print "# out=@{[_dump($path)]}\n"; } else { $debug and print "# add opt @{[_dump([$token,@_])]} via $token_key\n"; push @$path, { '' => undef, $token_key => [ $token, @_ ], }; } } $path; } sub _reduce { my $self = shift; my $context = { debug => $self->_debug(DEBUG_TAIL), depth => 0 }; if ($self->_debug(DEBUG_TIME)) { $self->_init_time_func; my $now = $self->{_time_func}->(); if (exists $self->{_begin_time}) { printf "# load=%0.6f\n", $now - $self->{_begin_time}; } else { printf "# load-epoch=%0.6f\n", $now; } $self->{_begin_time} = $self->{_time_func}->(); } my ($head, $tail) = _reduce_path( $self->_path, $context ); $context->{debug} and print "# final head=", _dump($head), ' tail=', _dump($tail), "\n"; if( !@$head ) { $self->{path} = $tail; } else { $self->{path} = [ @{_unrev_path( $tail, $context )}, @{_unrev_path( $head, $context )}, ]; } if ($self->_debug(DEBUG_TIME)) { my $now = $self->{_time_func}->(); if (exists $self->{_begin_time}) { printf "# reduce=%0.6f\n", $now - $self->{_begin_time}; } else { printf "# reduce-epoch=%0.6f\n", $now; } $self->{_begin_time} = $self->{_time_func}->(); } $context->{debug} and print "# final path=", _dump($self->{path}), "\n"; return $self; } sub _remove_optional { if( exists $_[0]->{''} ) { delete $_[0]->{''}; return 1; } return 0; } sub _reduce_path { my ($path, $ctx) = @_; my $indent = ' ' x $ctx->{depth}; my $debug = $ctx->{debug}; $debug and print "#$indent _reduce_path $ctx->{depth} ", _dump($path), "\n"; my $new; my $head = []; my $tail = []; while( defined( my $p = pop @$path )) { if( ref($p) eq 'HASH' ) { my ($node_head, $node_tail) = _reduce_node($p, _descend($ctx) ); $debug and print "#$indent| head=", _dump($node_head), " tail=", _dump($node_tail), "\n"; push @$head, @$node_head if scalar @$node_head; push @$tail, ref($node_tail) eq 'HASH' ? $node_tail : @$node_tail; } else { if( @$head ) { $debug and print "#$indent| push $p leaves @{[_dump($path)]}\n"; push @$tail, $p; } else { $debug and print "#$indent| unshift $p\n"; unshift @$tail, $p; } } } $debug and print "#$indent| tail nr=@{[scalar @$tail]} t0=", ref($tail->[0]), (ref($tail->[0]) eq 'HASH' ? " n=" . scalar(keys %{$tail->[0]}) : '' ), "\n"; if( @$tail > 1 and ref($tail->[0]) eq 'HASH' and keys %{$tail->[0]} == 2 ) { my $opt; my $fixed; while( my ($key, $path) = each %{$tail->[0]} ) { $debug and print "#$indent| scan k=$key p=@{[_dump($path)]}\n"; next unless $path; if (@$path == 1 and ref($path->[0]) eq 'HASH') { $opt = $path->[0]; } else { $fixed = $path; } } if( exists $tail->[0]{''} ) { my $path = [@{$tail}[1..$#{$tail}]]; $tail = $tail->[0]; ($head, $tail, $path) = _slide_tail( $head, $tail, $path, _descend($ctx) ); $tail = [$tail, @$path]; } } $debug and print "#$indent _reduce_path $ctx->{depth} out head=", _dump($head), ' tail=', _dump($tail), "\n"; return ($head, $tail); } sub _reduce_node { my ($node, $ctx) = @_; my $indent = ' ' x $ctx->{depth}; my $debug = $ctx->{debug}; my $optional = _remove_optional($node); $debug and print "#$indent _reduce_node $ctx->{depth} in @{[_dump($node)]} opt=$optional\n"; if( $optional and scalar keys %$node == 1 ) { my $path = (values %$node)[0]; if( not grep { ref($_) eq 'HASH' } @$path ) { # if we have removed an optional, and there is only one path # left then there is nothing left to compare. Because of the # optional it cannot participate in any further reductions. # (unless we test for equality among sub-trees). my $result = { '' => undef, $path->[0] => $path }; $debug and print "#$indent| fast fail @{[_dump($result)]}\n"; return [], $result; } } my( $fail, $reduce ) = _scan_node( $node, _descend($ctx) ); $debug and print "#$indent|_scan_node done opt=$optional reduce=@{[_dump($reduce)]} fail=@{[_dump($fail)]}\n"; # We now perform tail reduction on each of the nodes in the reduce # hash. If we have only one key, we know we will have a successful # reduction (since everything that was inserted into the node based # on the value of the last token of each path all mapped to the same # value). if( @$fail == 0 and keys %$reduce == 1 and not $optional) { # every path shares a common path my $path = (values %$reduce)[0]; my ($common, $tail) = _do_reduce( $path, _descend($ctx) ); $debug and print "#$indent|_reduce_node $ctx->{depth} common=@{[_dump($common)]} tail=", _dump($tail), "\n"; return( $common, $tail ); } # this node resulted in a list of paths, game over $ctx->{indent} = $indent; return _reduce_fail( $reduce, $fail, $optional, _descend($ctx) ); } sub _reduce_fail { my( $reduce, $fail, $optional, $ctx ) = @_; my( $debug, $depth, $indent ) = @{$ctx}{qw(debug depth indent)}; my %result; $result{''} = undef if $optional; my $p; for $p (keys %$reduce) { my $path = $reduce->{$p}; if( scalar @$path == 1 ) { $path = $path->[0]; $debug and print "#$indent| -simple opt=$optional unrev @{[_dump($path)]}\n"; $path = _unrev_path($path, _descend($ctx) ); $result{_node_key($path->[0])} = $path; } else { $debug and print "#$indent| _do_reduce(@{[_dump($path)]})\n"; my ($common, $tail) = _do_reduce( $path, _descend($ctx) ); $path = [ ( ref($tail) eq 'HASH' ? _unrev_node($tail, _descend($ctx) ) : _unrev_path($tail, _descend($ctx) ) ), @{_unrev_path($common, _descend($ctx) )} ]; $debug and print "#$indent| +reduced @{[_dump($path)]}\n"; $result{_node_key($path->[0])} = $path; } } my $f; for $f( @$fail ) { $debug and print "#$indent| +fail @{[_dump($f)]}\n"; $result{$f->[0]} = $f; } $debug and print "#$indent _reduce_fail $depth fail=@{[_dump(\%result)]}\n"; return ( [], \%result ); } sub _scan_node { my( $node, $ctx ) = @_; my $indent = ' ' x $ctx->{depth}; my $debug = $ctx->{debug}; # For all the paths in the node, reverse them. If the first token # of the path is a scalar, push it onto an array in a hash keyed by # the value of the scalar. # # If it is a node, call _reduce_node on this node beforehand. If we # get back a common head, all of the paths in the subnode shared a # common tail. We then store the common part and the remaining node # of paths (which is where the paths diverged from the end and install # this into the same hash. At this point both the common and the tail # are in reverse order, just as simple scalar paths are. # # On the other hand, if there were no common path returned then all # the paths of the sub-node diverge at the end character. In this # case the tail cannot participate in any further reductions and will # appear in forward order. # # certainly the hurgliest function in the whole file :( # $debug = 1 if $depth >= 8; my @fail; my %reduce; my $n; for $n( map { substr($_, index($_, '#')+1) } sort map { join( '|' => scalar(grep {ref($_) eq 'HASH'} @{$node->{$_}}), _node_offset($node->{$_}), scalar @{$node->{$_}}, ) . "#$_" } keys %$node ) { my( $end, @path ) = reverse @{$node->{$n}}; if( ref($end) ne 'HASH' ) { $debug and print "# $indent|_scan_node push reduce ($end:@{[_dump(\@path)]})\n"; push @{$reduce{$end}}, [ $end, @path ]; } else { $debug and print "# $indent|_scan_node head=", _dump(\@path), ' tail=', _dump($end), "\n"; my $new_path; # deal with sing, singing => s(?:ing)?ing if( keys %$end == 2 and exists $end->{''} ) { my ($key, $opt_path) = each %$end; ($key, $opt_path) = each %$end if $key eq ''; $opt_path = [reverse @{$opt_path}]; $debug and print "# $indent| check=", _dump($opt_path), "\n"; my $end = { '' => undef, $opt_path->[0] => [@$opt_path] }; my $head = []; my $path = [@path]; ($head, my $slide, $path) = _slide_tail( $head, $end, $path, $ctx ); if( @$head ) { $new_path = [ @$head, $slide, @$path ]; } } if( $new_path ) { $debug and print "# $indent|_scan_node slid=", _dump($new_path), "\n"; push @{$reduce{$new_path->[0]}}, $new_path; } else { my( $common, $tail ) = _reduce_node( $end, _descend($ctx) ); if( not @$common ) { $debug and print "# $indent| +failed $n\n"; push @fail, [reverse(@path), $tail]; } else { my $path = [@path]; $debug and print "# $indent|_scan_node ++recovered common=@{[_dump($common)]} tail=", _dump($tail), " path=@{[_dump($path)]}\n"; if( ref($tail) eq 'HASH' and keys %$tail == 2 ) { if( exists $tail->{''} ) { ($common, $tail, $path) = _slide_tail( $common, $tail, $path, $ctx ); } } push @{$reduce{$common->[0]}}, [ @$common, (ref($tail) eq 'HASH' ? $tail : @$tail ), @$path ]; } } } } $debug and print "# $indent|_scan_node counts: reduce=@{[scalar keys %reduce]} fail=@{[scalar @fail]}\n"; return( \@fail, \%reduce ); } sub _do_reduce { my ($path, $ctx) = @_; my $indent = ' ' x $ctx->{depth}; my $debug = $ctx->{debug}; my $ra = Regexp::Assemble->new(chomp=>0); $ra->debug($debug); $debug and print "# $indent| do @{[_dump($path)]}\n"; $ra->_insertr( $_ ) for # When nodes come into the picture, we have to be careful # about how we insert the paths into the assembly. # Paths with nodes first, then closest node to front # then shortest path. Merely because if we can control # order in which paths containing nodes get inserted, # then we can make a couple of assumptions that simplify # the code in _insert_node. sort { scalar(grep {ref($_) eq 'HASH'} @$a) <=> scalar(grep {ref($_) eq 'HASH'} @$b) || _node_offset($b) <=> _node_offset($a) || scalar @$a <=> scalar @$b } @$path ; $path = $ra->_path; my $common = []; push @$common, shift @$path while( ref($path->[0]) ne 'HASH' ); my $tail = scalar( @$path ) > 1 ? [@$path] : $path->[0]; $debug and print "# $indent| _do_reduce common=@{[_dump($common)]} tail=@{[_dump($tail)]}\n"; return ($common, $tail); } sub _node_offset { # return the offset that the first node is found, or -ve # optimised for speed my $nr = @{$_[0]}; my $atom = -1; ref($_[0]->[$atom]) eq 'HASH' and return $atom while ++$atom < $nr; return -1; } sub _slide_tail { my $head = shift; my $tail = shift; my $path = shift; my $ctx = shift; my $indent = ' ' x $ctx->{depth}; my $debug = $ctx->{debug}; $debug and print "# $indent| slide in h=", _dump($head), ' t=', _dump($tail), ' p=', _dump($path), "\n"; my $slide_path = (each %$tail)[-1]; $slide_path = (each %$tail)[-1] unless defined $slide_path; $debug and print "# $indent| slide potential ", _dump($slide_path), " over ", _dump($path), "\n"; while( defined $path->[0] and $path->[0] eq $slide_path->[0] ) { $debug and print "# $indent| slide=tail=$slide_path->[0]\n"; my $slide = shift @$path; shift @$slide_path; push @$slide_path, $slide; push @$head, $slide; } $debug and print "# $indent| slide path ", _dump($slide_path), "\n"; my $slide_node = { '' => undef, _node_key($slide_path->[0]) => $slide_path, }; $debug and print "# $indent| slide out h=", _dump($head), ' s=', _dump($slide_node), ' p=', _dump($path), "\n"; return ($head, $slide_node, $path); } sub _unrev_path { my ($path, $ctx) = @_; my $indent = ' ' x $ctx->{depth}; my $debug = $ctx->{debug}; my $new; if( not grep { ref($_) } @$path ) { $debug and print "# ${indent}_unrev path fast ", _dump($path); $new = [reverse @$path]; $debug and print "# -> ", _dump($new), "\n"; return $new; } $debug and print "# ${indent}unrev path in ", _dump($path), "\n"; while( defined( my $p = pop @$path )) { push @$new, ref($p) eq 'HASH' ? _unrev_node($p, _descend($ctx) ) : ref($p) eq 'ARRAY' ? _unrev_path($p, _descend($ctx) ) : $p ; } $debug and print "# ${indent}unrev path out ", _dump($new), "\n"; return $new; } sub _unrev_node { my ($node, $ctx ) = @_; my $indent = ' ' x $ctx->{depth}; my $debug = $ctx->{debug}; my $optional = _remove_optional($node); $debug and print "# ${indent}unrev node in ", _dump($node), " opt=$optional\n"; my $new; $new->{''} = undef if $optional; my $n; for $n( keys %$node ) { my $path = _unrev_path($node->{$n}, _descend($ctx) ); $new->{_node_key($path->[0])} = $path; } $debug and print "# ${indent}unrev node out ", _dump($new), "\n"; return $new; } sub _node_key { my $node = shift; return _node_key($node->[0]) if ref($node) eq 'ARRAY'; return $node unless ref($node) eq 'HASH'; my $key = ''; my $k; for $k( keys %$node ) { next if $k eq ''; $key = $k if $key eq '' or $key gt $k; } return $key; } sub _descend { # Take a context object, and increase the depth by one. # By creating a fresh hash each time, we don't have to # bother adding make-work code to decrease the depth # when we return from what we called. my $ctx = shift; return {%$ctx, depth => $ctx->{depth}+1}; } ##################################################################### sub _make_class { my $self = shift; my %set = map { ($_,1) } @_; delete $set{'\\d'} if exists $set{'\\w'}; delete $set{'\\D'} if exists $set{'\\W'}; return '.' if exists $set{'.'} or ($self->{fold_meta_pairs} and ( (exists $set{'\\d'} and exists $set{'\\D'}) or (exists $set{'\\s'} and exists $set{'\\S'}) or (exists $set{'\\w'} and exists $set{'\\W'}) )) ; for my $meta( q/\\d/, q/\\D/, q/\\s/, q/\\S/, q/\\w/, q/\\W/ ) { if( exists $set{$meta} ) { my $re = qr/$meta/; my @delete; $_ =~ /^$re$/ and push @delete, $_ for keys %set; delete @set{@delete} if @delete; } } return (keys %set)[0] if keys %set == 1; for my $meta( '.', '+', '*', '?', '(', ')', '^', '@', '$', '[', '/', ) { exists $set{"\\$meta"} and $set{$meta} = delete $set{"\\$meta"}; } my $dash = exists $set{'-'} ? do { delete($set{'-'}), '-' } : ''; my $caret = exists $set{'^'} ? do { delete($set{'^'}), '^' } : ''; my $class = join( '' => sort keys %set ); $class =~ s/0123456789/\\d/ and $class eq '\\d' and return $class; return "[$dash$class$caret]"; } sub _re_sort { return length $b <=> length $a || $a cmp $b } sub _combine { my $self = shift; my $type = shift; # print "c in = @{[_dump(\@_)]}\n"; # my $combine = return '(' . $type . do { my( @short, @long ); push @{ /^$Single_Char$/ ? \@short : \@long}, $_ for @_; if( @short == 1 ) { @long = sort _re_sort @long, @short; } elsif( @short > 1 ) { # yucky but true my @combine = (_make_class($self, @short), sort _re_sort @long); @long = @combine; } else { @long = sort _re_sort @long; } join( '|', @long ); } . ')'; # print "combine <$combine>\n"; # $combine; } sub _combine_new { my $self = shift; my( @short, @long ); push @{ /^$Single_Char$/ ? \@short : \@long}, $_ for @_; if( @short == 1 and @long == 0 ) { return $short[0]; } elsif( @short > 1 and @short == @_ ) { return _make_class($self, @short); } else { return '(?:' . join( '|' => @short > 1 ? ( _make_class($self, @short), sort _re_sort @long) : ( (sort _re_sort( @long )), @short ) ) . ')'; } } sub _re_path { my $self = shift; # in shorter assemblies, _re_path() is the second hottest # routine. after insert(), so make it fast. if ($self->{unroll_plus}) { # but we can't easily make this blockless my @arr = @{$_[0]}; my $str = ''; my $skip = 0; for my $i (0..$#arr) { if (ref($arr[$i]) eq 'ARRAY') { $str .= _re_path($self, $arr[$i]); } elsif (ref($arr[$i]) eq 'HASH') { $str .= exists $arr[$i]->{''} ? _combine_new( $self, map { _re_path( $self, $arr[$i]->{$_} ) } grep { $_ ne '' } keys %{$arr[$i]} ) . '?' : _combine_new($self, map { _re_path( $self, $arr[$i]->{$_} ) } keys %{$arr[$i]}) ; } elsif ($i < $#arr and $arr[$i+1] =~ /\A$arr[$i]\*(\??)\Z/) { $str .= "$arr[$i]+" . (defined $1 ? $1 : ''); ++$skip; } elsif ($skip) { $skip = 0; } else { $str .= $arr[$i]; } } return $str; } return join( '', @_ ) unless grep { length ref $_ } @_; my $p; return join '', map { ref($_) eq '' ? $_ : ref($_) eq 'HASH' ? do { # In the case of a node, see whether there's a '' which # indicates that the whole thing is optional and thus # requires a trailing ? # Unroll the two different paths to avoid the needless # grep when it isn't necessary. $p = $_; exists $_->{''} ? _combine_new( $self, map { _re_path( $self, $p->{$_} ) } grep { $_ ne '' } keys %$_ ) . '?' : _combine_new($self, map { _re_path( $self, $p->{$_} ) } keys %$_ ) } : _re_path($self, $_) # ref($_) eq 'ARRAY' } @{$_[0]} } sub _lookahead { my $in = shift; my %head; my $path; for $path( keys %$in ) { next unless defined $in->{$path}; # print "look $path: ", ref($in->{$path}[0]), ".\n"; if( ref($in->{$path}[0]) eq 'HASH' ) { my $next = 0; while( ref($in->{$path}[$next]) eq 'HASH' and @{$in->{$path}} > $next + 1 ) { if( exists $in->{$path}[$next]{''} ) { ++$head{$in->{$path}[$next+1]}; } ++$next; } my $inner = _lookahead( $in->{$path}[0] ); @head{ keys %$inner } = (values %$inner); } elsif( ref($in->{$path}[0]) eq 'ARRAY' ) { my $subpath = $in->{$path}[0]; for( my $sp = 0; $sp < @$subpath; ++$sp ) { if( ref($subpath->[$sp]) eq 'HASH' ) { my $follow = _lookahead( $subpath->[$sp] ); @head{ keys %$follow } = (values %$follow); last unless exists $subpath->[$sp]{''}; } else { ++$head{$subpath->[$sp]}; last; } } } else { ++$head{ $in->{$path}[0] }; } } # print "_lookahead ", _dump($in), '==>', _dump([keys %head]), "\n"; return \%head; } sub _re_path_lookahead { my $self = shift; my $in = shift; # print "_re_path_la in ", _dump($in), "\n"; my $out = ''; for( my $p = 0; $p < @$in; ++$p ) { if( ref($in->[$p]) eq '' ) { $out .= $in->[$p]; next; } elsif( ref($in->[$p]) eq 'ARRAY' ) { $out .= _re_path_lookahead($self, $in->[$p]); next; } # print "$p ", _dump($in->[$p]), "\n"; my $path = [ map { _re_path_lookahead($self, $in->[$p]{$_} ) } grep { $_ ne '' } keys %{$in->[$p]} ]; my $ahead = _lookahead($in->[$p]); my $more = 0; if( exists $in->[$p]{''} and $p + 1 < @$in ) { my $next = 1; while( $p + $next < @$in ) { if( ref( $in->[$p+$next] ) eq 'HASH' ) { my $follow = _lookahead( $in->[$p+$next] ); @{$ahead}{ keys %$follow } = (values %$follow); } else { ++$ahead->{$in->[$p+$next]}; last; } ++$next; } $more = 1; } my $nr_one = grep { /^$Single_Char$/ } @$path; my $nr = @$path; if( $nr_one > 1 and $nr_one == $nr ) { $out .= _make_class($self, @$path); $out .= '?' if exists $in->[$p]{''}; } else { my $zwla = keys(%$ahead) > 1 ? _combine($self, '?=', grep { s/\+$//; $_ } keys %$ahead ) : ''; my $patt = $nr > 1 ? _combine($self, '?:', @$path ) : $path->[0]; # print "have nr=$nr n1=$nr_one n=", _dump($in->[$p]), ' a=', _dump([keys %$ahead]), " zwla=$zwla patt=$patt @{[_dump($path)]}\n"; if( exists $in->[$p]{''} ) { $out .= $more ? "$zwla(?:$patt)?" : "(?:$zwla$patt)?"; } else { $out .= "$zwla$patt"; } } } return $out; } sub _re_path_track { my $self = shift; my $in = shift; my $normal = shift; my $augmented = shift; my $o; my $simple = ''; my $augment = ''; for( my $n = 0; $n < @$in; ++$n ) { if( ref($in->[$n]) eq '' ) { $o = $in->[$n]; $simple .= $o; $augment .= $o; if( ( $n < @$in - 1 and ref($in->[$n+1]) eq 'HASH' and exists $in->[$n+1]{''} ) or $n == @$in - 1 ) { push @{$self->{mlist}}, $normal . $simple ; $augment .= $] < 5.009005 ? "(?{\$self->{m}=$self->{mcount}})" : "(?{$self->{mcount}})" ; ++$self->{mcount}; } } else { my $path = [ map { $self->_re_path_track( $in->[$n]{$_}, $normal.$simple , $augmented.$augment ) } grep { $_ ne '' } keys %{$in->[$n]} ]; $o = '(?:' . join( '|' => sort _re_sort @$path ) . ')'; $o .= '?' if exists $in->[$n]{''}; $simple .= $o; $augment .= $o; } } return $augment; } sub _re_path_pretty { my $self = shift; my $in = shift; my $arg = shift; my $pre = ' ' x (($arg->{depth}+0) * $arg->{indent}); my $indent = ' ' x (($arg->{depth}+1) * $arg->{indent}); my $out = ''; $arg->{depth}++; my $prev_was_paren = 0; for( my $p = 0; $p < @$in; ++$p ) { if( ref($in->[$p]) eq '' ) { $out .= "\n$pre" if $prev_was_paren; $out .= $in->[$p]; $prev_was_paren = 0; } elsif( ref($in->[$p]) eq 'ARRAY' ) { $out .= _re_path($self, $in->[$p]); } else { my $path = [ map { _re_path_pretty($self, $in->[$p]{$_}, $arg ) } grep { $_ ne '' } keys %{$in->[$p]} ]; my $nr = @$path; my( @short, @long ); push @{/^$Single_Char$/ ? \@short : \@long}, $_ for @$path; if( @short == $nr ) { $out .= $nr == 1 ? $path->[0] : _make_class($self, @short); $out .= '?' if exists $in->[$p]{''}; } else { $out .= "\n" if length $out; $out .= $pre if $p; $out .= "(?:\n$indent"; if( @short < 2 ) { my $r = 0; $out .= join( "\n$indent|" => map { $r++ and $_ =~ s/^\(\?:/\n$indent(?:/; $_ } sort _re_sort @$path ); } else { $out .= join( "\n$indent|" => ( (sort _re_sort @long), _make_class($self, @short) )); } $out .= "\n$pre)"; if( exists $in->[$p]{''} ) { $out .= "\n$pre?"; $prev_was_paren = 0; } else { $prev_was_paren = 1; } } } } $arg->{depth}--; return $out; } sub _node_eq { return 0 if not defined $_[0] or not defined $_[1]; return 0 if ref $_[0] ne ref $_[1]; # Now that we have determined that the reference of each # argument are the same, we only have to test the first # one, which gives us a nice micro-optimisation. if( ref($_[0]) eq 'HASH' ) { keys %{$_[0]} == keys %{$_[1]} and # does this short-circuit to avoid _re_path() cost more than it saves? join( '|' => sort keys %{$_[0]}) eq join( '|' => sort keys %{$_[1]}) and _re_path(undef, [$_[0]] ) eq _re_path(undef, [$_[1]] ); } elsif( ref($_[0]) eq 'ARRAY' ) { scalar @{$_[0]} == scalar @{$_[1]} and _re_path(undef, $_[0]) eq _re_path(undef, $_[1]); } else { $_[0] eq $_[1]; } } sub _pretty_dump { return sprintf "\\x%02x", ord(shift); } sub _dump { my $path = shift; return _dump_node($path) if ref($path) eq 'HASH'; my $dump = '['; my $d; my $nr = 0; for $d( @$path ) { $dump .= ' ' if $nr++; if( ref($d) eq 'HASH' ) { $dump .= _dump_node($d); } elsif( ref($d) eq 'ARRAY' ) { $dump .= _dump($d); } elsif( defined $d ) { # D::C indicates the second test is redundant # $dump .= ( $d =~ /\s/ or not length $d ) $dump .= ( $d =~ /\s/ ? qq{'$d'} : $d =~ /^[\x00-\x1f]$/ ? _pretty_dump($d) : $d ); } else { $dump .= '*'; } } return $dump . ']'; } sub _dump_node { my $node = shift; my $dump = '{'; my $nr = 0; my $n; for $n (sort keys %$node) { $dump .= ' ' if $nr++; # Devel::Cover shows this to test to be redundant # $dump .= ( $n eq '' and not defined $node->{$n} ) $dump .= $n eq '' ? '*' : ($n =~ /^[\x00-\x1f]$/ ? _pretty_dump($n) : $n) . "=>" . _dump($node->{$n}) ; } return $dump . '}'; } =pod =head1 NAME Regexp::Assemble - Assemble multiple Regular Expressions into a single RE =head1 SYNOPSIS use Regexp::Assemble; my $ra = Regexp::Assemble->new; $ra->add( 'ab+c' ); $ra->add( 'ab+-' ); $ra->add( 'a\w\d+' ); $ra->add( 'a\d+' ); print $ra->re; # prints a(?:\w?\d+|b+[-c]) =head1 DESCRIPTION Regexp::Assemble takes an arbitrary number of regular expressions and assembles them into a single regular expression (or RE) that matches all that the individual REs match. As a result, instead of having a large list of expressions to loop over, a target string only needs to be tested against one expression. This is interesting when you have several thousand patterns to deal with. Serious effort is made to produce the smallest pattern possible. It is also possible to track the original patterns, so that you can determine which, among the source patterns that form the assembled pattern, was the one that caused the match to occur. You should realise that large numbers of alternations are processed in perl's regular expression engine in O(n) time, not O(1). If you are still having performance problems, you should look at using a trie. Note that Perl's own regular expression engine will implement trie optimisations in perl 5.10 (they are already available in perl 5.9.3 if you want to try them out). C will do the right thing when it knows it's running on a trie'd perl. (At least in some version after this one). Some more examples of usage appear in the accompanying README. If that file is not easy to access locally, you can find it on a web repository such as L or L. See also L. =head1 Methods =head2 add(LIST) Takes a string, breaks it apart into a set of tokens (respecting meta characters) and inserts the resulting list into the C object. It uses a naive regular expression to lex the string that may be fooled complex expressions (specifically, it will fail to lex nested parenthetical expressions such as C correctly). If this is the case, the end of the string will not be tokenised correctly and returned as one long string. On the one hand, this may indicate that the patterns you are trying to feed the C object are too complex. Simpler patterns might allow the algorithm to work more effectively and perform more reductions in the resulting pattern. On the other hand, you can supply your own pattern to perform the lexing if you need. The test suite contains an example of a lexer pattern that will match one level of nested parentheses. Note that there is an internal optimisation that will bypass a much of the lexing process. If a string contains no C<\> (backslash), C<[> (open square bracket), C<(> (open paren), C (question mark), C<+> (plus), C<*> (star) or C<{> (open curly), a character split will be performed directly. A list of strings may be supplied, thus you can pass it a file handle of a file opened for reading: $re->add( '\d+-\d+-\d+-\d+\.example\.com' ); $re->add( ); If the file is very large, it may be more efficient to use a C loop, to read the file line-by-line: $re->add($_) while ; The C method will chomp the lines automatically. If you do not want this to occur (you want to keep the record separator), then disable Cing. $re->chomp(0); $re->add($_) while ; This method is chainable. =head2 add_file(FILENAME [...]) Takes a list of file names. Each file is opened and read line by line. Each line is added to the assembly. $r->add_file( 'file.1', 'file.2' ); If a file cannot be opened, the method will croak. If you cannot afford to let this happen then you should wrap the call in a C block. Chomping happens automatically unless you the C method to disable it. By default, input lines are read according to the value of the C attribute (if defined), and will otherwise fall back to the current setting of the system C<$/> variable. The record separator may also be specified on each call to C. Internally, the routine Cises the value of C<$/> to whatever is required, for the duration of the call. An alternate calling mechanism using a hash reference is available. The recognised keys are: =over 4 =item file Reference to a list of file names, or the name of a single file. $r->add_file({file => ['file.1', 'file.2', 'file.3']}); $r->add_file({file => 'file.n'}); =item input_record_separator If present, indicates what constitutes a line $r->add_file({file => 'data.txt', input_record_separator => ':' }); =item rs An alias for input_record_separator (mnemonic: same as the English variable names). =back $r->add_file( { file => [ 'pattern.txt', 'more.txt' ], input_record_separator => "\r\n", }); =head2 clone() Clones the contents of a Regexp::Assemble object and creates a new object (in other words it performs a deep copy). If the Storable module is installed, its dclone method will be used, otherwise the cloning will be performed using a pure perl approach. You can use this method to take a snapshot of the patterns that have been added so far to an object, and generate an assembly from the clone. Additional patterns may to be added to the original object afterwards. my $re = $main->clone->re(); $main->add( 'another-pattern-\\d+' ); =head2 insert(LIST) Takes a list of tokens representing a regular expression and stores them in the object. Note: you should not pass it a bare regular expression, such as C. You must pass it as a list of tokens, I C<('a', 'b+', 'c?', 'd*', 'e')>. This method is chainable, I: my $ra = Regexp::Assemble->new ->insert( qw[ a b+ c? d* e ] ) ->insert( qw[ a c+ d+ e* f ] ); Lexing complex patterns with metacharacters and so on can consume a significant proportion of the overall time to build an assembly. If you have the information available in a tokenised form, calling C directly can be a big win. =head2 lexstr Use the C method if you are curious to see how a pattern gets tokenised. It takes a scalar on input, representing a pattern, and returns a reference to an array, containing the tokenised pattern. You can recover the original pattern by performing a C: my @token = $re->lexstr($pattern); my $new_pattern = join( '', @token ); If the original pattern contains unnecessary backslashes, or C<\x4b> escapes, or quotemeta escapes (C<\Q>...C<\E>) the resulting pattern may not be identical. Call C does not add the pattern to the object, it is merely for exploratory purposes. It will, however, update various statistical counters. =head2 pre_filter(CODE) Allows you to install a callback to check that the pattern being loaded contains valid input. It receives the pattern as a whole to be added, before it been tokenised by the lexer. It may to return 0 or C to indicate that the pattern should not be added, any true value indicates that the contents are fine. A filter to strip out trailing comments (marked by #): $re->pre_filter( sub { $_[0] =~ s/\s*#.*$//; 1 } ); A filter to ignore blank lines: $re->pre_filter( sub { length(shift) } ); If you want to remove the filter, pass C as a parameter. $ra->pre_filter(undef); This method is chainable. =head2 filter(CODE) Allows you to install a callback to check that the pattern being loaded contains valid input. It receives a list on input, after it has been tokenised by the lexer. It may to return 0 or undef to indicate that the pattern should not be added, any true value indicates that the contents are fine. If you know that all patterns you expect to assemble contain a restricted set of of tokens (e.g. no spaces), you could do the following: $ra->filter(sub { not grep { / / } @_ }); or sub only_spaces_and_digits { not grep { ![\d ] } @_ } $ra->filter( \&only_spaces_and_digits ); These two examples will silently ignore faulty patterns, If you want the user to be made aware of the problem you should raise an error (via C or C), log an error message, whatever is best. If you want to remove a filter, pass C as a parameter. $ra->filter(undef); This method is chainable. =head2 as_string Assemble the expression and return it as a string. You may want to do this if you are writing the pattern to a file. The following arguments can be passed to control the aspect of the resulting pattern: B, the number of spaces used to indent nested grouping of a pattern. Use this to produce a pretty-printed pattern (for some definition of "pretty"). The resulting output is rather verbose. The reason is to ensure that the metacharacters C<(?:> and C<)> always occur on otherwise empty lines. This allows you grep the result for an even more synthetic view of the pattern: egrep -v '^ *[()]' The result of the above is quite readable. Remember to backslash the spaces appearing in your own patterns if you wish to use an indented pattern in an C construct. Indenting is ignored if tracking is enabled. The B argument takes precedence over the C method/attribute of the object. Calling this method will drain the internal data structure. Large numbers of patterns can eat a significant amount of memory, and this lets perl recover the memory used for other purposes. If you want to reduce the pattern I continue to add new patterns, clone the object and reduce the clone, leaving the original object intact. =head2 re Assembles the pattern and return it as a compiled RE, using the C operator. As with C, calling this method will reset the internal data structures to free the memory used in assembling the RE. The B attribute, documented in the C method, can be used here (it will be ignored if tracking is enabled). With method chaining, it is possible to produce a RE without having a temporary C object lying around, I: my $re = Regexp::Assemble->new ->add( q[ab+cd+e] ) ->add( q[ac\\d+e] ) ->add( q[c\\d+e] ) ->re; The C<$re> variable now contains a Regexp object that can be used directly: while( <> ) { /$re/ and print "Something in [$_] matched\n"; ) The C method is called when the object is used in string context (hence, within an C operator), so by and large you do not even need to save the RE in a separate variable. The following will work as expected: my $re = Regexp::Assemble->new->add( qw[ fee fie foe fum ] ); while( ) { if( /($re)/ ) { print "Here be giants: $1\n"; } } This approach does not work with tracked patterns. The C and C methods must be used instead, see below. =head2 match(SCALAR) The following information applies to Perl 5.8 and below. See the section that follows for information on Perl 5.10. If pattern tracking is in use, you must C in order to make things work correctly. At a minimum, this will make your code look like this: my $did_match = do { use re 'eval'; $target =~ /$ra/ } if( $did_match ) { print "matched ", $ra->matched, "\n"; } (The main reason is that the C<$^R> variable is currently broken and an ugly workaround that runs some Perl code during the match is required, in order to simulate what C<$^R> should be doing. See Perl bug #32840 for more information if you are curious. The README also contains more information). This bug has been fixed in 5.10. The important thing to note is that with C, THERE ARE SECURITY IMPLICATIONS WHICH YOU IGNORE AT YOUR PERIL. The problem is this: if you do not have strict control over the patterns being fed to C when tracking is enabled, and someone slips you a pattern such as C and you attempt to match a string against the resulting pattern, you will know Fear and Loathing. What is more, the C<$^R> workaround means that that tracking does not work if you perform a bare C pattern match as shown above. You have to instead call the C method, in order to supply the necessary context to take care of the tracking housekeeping details. if( defined( my $match = $ra->match($_)) ) { print " $_ matched by $match\n"; } In the case of a successful match, the original matched pattern is returned directly. The matched pattern will also be available through the C method. (Except that the above is not true for 5.6.0: the C method returns true or undef, and the C method always returns undef). If you are capturing parts of the pattern I C you will want to get at the captures. See the C, C, C and C methods. If you are not using captures then you may safely ignore this section. In 5.10, since the bug concerning C<$^R> has been resolved, there is no need to use C and the assembled pattern does not require any Perl code to be executed during the match. =head2 new() Creates a new C object. The following optional key/value parameters may be employed. All keys have a corresponding method that can be used to change the behaviour later on. As a general rule, especially if you're just starting out, you don't have to bother with any of these. B, a family of optional attributes that allow anchors (C<^>, C<\b>, C<\Z>...) to be added to the resulting pattern. B, sets the C flags to add to the assembled regular expression. Warning: no error checking is done, you should ensure that the flags you pass are understood by the version of Perl you are using. B exists as an alias, for users familiar with L. B, controls whether the pattern should be chomped before being lexed. Handy if you are reading patterns from a file. By default, Cing is performed (this behaviour changed as of version 0.24, prior versions did not chomp automatically). See also the C attribute and the C method. B, slurp the contents of the specified file and add them to the assembly. Multiple files may be processed by using a list. my $r = Regexp::Assemble->new(file => 're.list'); my $r = Regexp::Assemble->new(file => ['re.1', 're.2']); If you really don't want chomping to occur, you will have to set the C attribute to 0 (zero). You may also want to look at the C attribute, as well. B, controls what constitutes a record separator when using the C attribute or the C method. May be abbreviated to B. See the C<$/> variable in L. B, controls whether the pattern should contain zero-width lookahead assertions (For instance: (?=[abc])(?:bob|alice|charles). This is not activated by default, because in many circumstances the cost of processing the assertion itself outweighs the benefit of its faculty for short-circuiting a match that will fail. This is sensitive to the probability of a match succeeding, so if you're worried about performance you'll have to benchmark a sample population of targets to see which way the benefits lie. B, controls whether you want know which of the initial patterns was the one that matched. See the C method for more details. Note for version 5.8 of Perl and below, in this mode of operation YOU SHOULD BE AWARE OF THE SECURITY IMPLICATIONS that this entails. Perl 5.10 does not suffer from any such restriction. B, the number of spaces used to indent nested grouping of a pattern. Use this to produce a pretty-printed pattern. See the C method for a more detailed explanation. B, allows you to add a callback to enable sanity checks on the pattern being loaded. This callback is triggered before the pattern is split apart by the lexer. In other words, it operates on the entire pattern. If you are loading patterns from a file, this would be an appropriate place to remove comments. B, allows you to add a callback to enable sanity checks on the pattern being loaded. This callback is triggered after the pattern has been split apart by the lexer. B, controls whether to unroll, for example, C into C, C, which may allow additional reductions in the resulting assembled pattern. B, controls whether tail reduction occurs or not. If set, patterns like C will be reduced to C. That is, the end of the pattern in each part of the b... and d... alternations is identical, and hence is hoisted out of the alternation and placed after it. On by default. Turn it off if you're really pressed for short assembly times. B, specifies the pattern used to lex the input lines into tokens. You could replace the default pattern by a more sophisticated version that matches arbitrarily nested parentheses, for example. B, controls whether copious amounts of output is produced during the loading stage or the reducing stage of assembly. my $ra = Regexp::Assemble->new; my $rb = Regexp::Assemble->new( chomp => 1, debug => 3 ); B, controls whether new patterns can be added to the object after the assembled pattern is generated. DEPRECATED. This method/attribute will be removed in a future release. It doesn't really serve any purpose, and may be more effectively replaced by cloning an existing C object and spinning out a pattern from that instead. =head2 source() When using tracked mode, after a successful match is made, returns the original source pattern that caused the match. In Perl 5.10, the C<$^R> variable can be used to as an index to fetch the correct pattern from the object. If no successful match has been performed, or the object is not in tracked mode, this method returns C. my $r = Regexp::Assemble->new->track(1)->add(qw(foo? bar{2} [Rr]at)); for my $w (qw(this food is rather barren)) { if ($w =~ /$r/) { print "$w matched by ", $r->source($^R), $/; } else { print "$w no match\n"; } } =head2 mbegin() This method returns a copy of C<@-> at the moment of the last match. You should ordinarily not need to bother with this, C should be able to supply all your needs. =head2 mend() This method returns a copy of C<@+> at the moment of the last match. =head2 mvar(NUMBER) The C method returns the captures of the last match. C corresponds to $1, C to $2, and so on. C happens to return the target string matched, as a byproduct of walking down the C<@-> and C<@+> arrays after the match. If called without a parameter, C will return a reference to an array containing all captures. =head2 capture The C method returns the the captures of the last match as an array. Unlink C, this method does not include the matched string. It is equivalent to getting an array back that contains C<$1, $2, $3, ...>. If no captures were found in the match, an empty array is returned, rather than C. You are therefore guaranteed to be able to use C<< for my $c ($re->capture) { ... >> without have to check whether anything was captured. =head2 matched() If pattern tracking has been set, via the C attribute, or through the C method, this method will return the original pattern of the last successful match. Returns undef match has yet been performed, or tracking has not been enabled. See below in the NOTES section for additional subtleties of which you should be aware of when tracking patterns. Note that this method is not available in 5.6.0, due to limitations in the implementation of C<(?{...})> at the time. =head2 Statistics/Reporting routines =head2 stats_add Returns the number of patterns added to the assembly (whether by C or C). Duplicate patterns are not included in this total. =head2 stats_dup Returns the number of duplicate patterns added to the assembly. If non-zero, this may be a sign that something is wrong with your data (or at the least, some needless redundancy). This may occur when you have two patterns (for instance, C and C) which map to the same result. =head2 stats_raw() Returns the raw number of bytes in the patterns added to the assembly. This includes both original and duplicate patterns. For instance, adding the two patterns C and C will count as 4 bytes. =head2 stats_cooked() Return the true number of bytes added to the assembly. This will not include duplicate patterns. Furthermore, it may differ from the raw bytes due to quotemeta treatment. For instance, C will count as 7 (not 8) bytes, because C<\,> will be stored as C<,>. Also, C<\Qa.b\E> is 7 bytes long, however, after the quotemeta directives are processed, C will be stored, for a total of 4 bytes. =head2 stats_length() Returns the length of the resulting assembled expression. Until C or C have been called, the length will be 0 (since the assembly will have not yet been performed). The length includes only the pattern, not the additional (C<(?-xism...>) fluff added by the compilation. =head2 dup_warn(NUMBER|CODEREF) Turns warnings about duplicate patterns on or off. By default, no warnings are emitted. If the method is called with no parameters, or a true parameter, the object will carp about patterns it has already seen. To turn off the warnings, use 0 as a parameter. $r->dup_warn(); The method may also be passed a code block. In this case the code will be executed and it will receive a reference to the object in question, and the lexed pattern. $r->dup_warn( sub { my $self = shift; print $self->stats_add, " patterns added at line $.\n", join( '', @_ ), " added previously\n"; } ) =head2 Anchor routines Suppose you wish to assemble a series of patterns that all begin with C<^> and end with C<$> (anchor pattern to the beginning and end of line). Rather than add the anchors to each and every pattern (and possibly forget to do so when a new entry is added), you may specify the anchors in the object, and they will appear in the resulting pattern, and you no longer need to (or should) put them in your source patterns. For example, the two following snippets will produce identical patterns: $r->add(qw(^this ^that ^them))->as_string; $r->add(qw(this that them))->anchor_line_begin->as_string; # both techniques will produce ^th(?:at|em|is) All anchors are possible word (C<\b>) boundaries, line boundaries (C<^> and C<$>) and string boundaries (C<\A> and C<\Z> (or C<\z> if you absolutely need it)). The shortcut C> implies both C_begin> C_end> is also available. If different anchors are specified the most specific anchor wins. For instance, if both C and C are specified, C takes precedence. All the anchor methods are chainable. =head2 anchor_word_begin The resulting pattern will be prefixed with a C<\b> word boundary assertion when the value is true. Set to 0 to disable. $r->add('pre')->anchor_word_begin->as_string; # produces '\bpre' =head2 anchor_word_end The resulting pattern will be suffixed with a C<\b> word boundary assertion when the value is true. Set to 0 to disable. $r->add(qw(ing tion)) ->anchor_word_end ->as_string; # produces '(?:tion|ing)\b' =head2 anchor_word The resulting pattern will be have C<\b> word boundary assertions at the beginning and end of the pattern when the value is true. Set to 0 to disable. $r->add(qw(cat carrot) ->anchor_word(1) ->as_string; # produces '\bca(?:rro)t\b' =head2 anchor_line_begin The resulting pattern will be prefixed with a C<^> line boundary assertion when the value is true. Set to 0 to disable. $r->anchor_line_begin; # or $r->anchor_line_begin(1); =head2 anchor_line_end The resulting pattern will be suffixed with a C<$> line boundary assertion when the value is true. Set to 0 to disable. # turn it off $r->anchor_line_end(0); =head2 anchor_line The resulting pattern will be have the C<^> and C<$> line boundary assertions at the beginning and end of the pattern, respectively, when the value is true. Set to 0 to disable. $r->add(qw(cat carrot) ->anchor_line ->as_string; # produces '^ca(?:rro)t$' =head2 anchor_string_begin The resulting pattern will be prefixed with a C<\A> string boundary assertion when the value is true. Set to 0 to disable. $r->anchor_string_begin(1); =head2 anchor_string_end The resulting pattern will be suffixed with a C<\Z> string boundary assertion when the value is true. Set to 0 to disable. # disable the string boundary end anchor $r->anchor_string_end(0); =head2 anchor_string_end_absolute The resulting pattern will be suffixed with a C<\z> string boundary assertion when the value is true. Set to 0 to disable. # disable the string boundary absolute end anchor $r->anchor_string_end_absolute(0); If you don't understand the difference between C<\Z> and C<\z>, the former will probably do what you want. =head2 anchor_string The resulting pattern will be have the C<\A> and C<\Z> string boundary assertions at the beginning and end of the pattern, respectively, when the value is true. Set to 0 to disable. $r->add(qw(cat carrot) ->anchor_string ->as_string; # produces '\Aca(?:rro)t\Z' =head2 anchor_string_absolute The resulting pattern will be have the C<\A> and C<\z> string boundary assertions at the beginning and end of the pattern, respectively, when the value is true. Set to 0 to disable. $r->add(qw(cat carrot) ->anchor_string_absolute ->as_string; # produces '\Aca(?:rro)t\z' =head2 debug(NUMBER) Turns debugging on or off. Statements are printed to the currently selected file handle (STDOUT by default). If you are already using this handle, you will have to arrange to select an output handle to a file of your own choosing, before call the C, C or C) functions, otherwise it will scribble all over your carefully formatted output. =over 4 =item * 0 Off. Turns off all debugging output. =item * 1 Add. Trace the addition of patterns. =item * 2 Reduce. Trace the process of reduction and assembly. =item * 4 Lex. Trace the lexing of the input patterns into its constituent tokens. =item * 8 Time. Print to STDOUT the time taken to load all the patterns. This is nothing more than the difference between the time the object was instantiated and the time reduction was initiated. # load= Any lengthy computation performed in the client code will be reflected in this value. Another line will be printed after reduction is complete. # reduce= The above output lines will be changed to C and C if the internal state of the object is corrupted and the initial timestamp is lost. The code attempts to load L in order to report fractional seconds. If this is not successful, the elapsed time is displayed in whole seconds. =back Values can be added (or or'ed together) to trace everything $r->debug(7)->add( '\\d+abc' ); Calling C with no arguments turns debugging off. =head2 dump() Produces a synthetic view of the internal data structure. How to interpret the results is left as an exercise to the reader. print $r->dump; =head2 chomp(0|1) Turns chomping on or off. IMPORTANT: As of version 0.24, chomping is now on by default as it makes C Just Work. The only time you may run into trouble is with C. So don't do that, or else explicitly turn off chomping. To avoid incorporating (spurious) record separators (such as "\n" on Unix) when reading from a file, C Cs its input. If you don't want this to happen, call C with a false value. $re->chomp(0); # really want the record separators $re->add(); =head2 fold_meta_pairs(NUMBER) Determines whether C<\s>, C<\S> and C<\w>, C<\W> and C<\d>, C<\D> are folded into a C<.> (dot). Folding happens by default (for reasons of backwards compatibility, even though it is wrong when the C expression modifier is active). Call this method with a false value to prevent this behaviour (which is only a problem when dealing with C<\n> if the C expression modifier is also set). $re->add( '\\w', '\\W' ); my $clone = $re->clone; $clone->fold_meta_pairs(0); print $clone->as_string; # prints '.' print $re->as_string; # print '[\W\w]' =head2 indent(NUMBER) Sets the level of indent for pretty-printing nested groups within a pattern. See the C method for more details. When called without a parameter, no indenting is performed. $re->indent( 4 ); print $re->as_string; =head2 lookahead(0|1) Turns on zero-width lookahead assertions. This is usually beneficial when you expect that the pattern will usually fail. If you expect that the pattern will usually match you will probably be worse off. =head2 flags(STRING) Sets the flags that govern how the pattern behaves (for versions of Perl up to 5.9 or so, these are C). By default no flags are enabled. =head2 modifiers(STRING) An alias of the C method, for users familiar with C. =head2 track(0|1) Turns tracking on or off. When this attribute is enabled, additional housekeeping information is inserted into the assembled expression using C<({...}> embedded code constructs. This provides the necessary information to determine which, of the original patterns added, was the one that caused the match. $re->track( 1 ); if( $target =~ /$re/ ) { print "$target matched by ", $re->matched, "\n"; } Note that when this functionality is enabled, no reduction is performed and no character classes are generated. In other words, C is not reduced down to C<(?:br|t)ag> and C is not reduced to C. =head2 unroll_plus(0|1) Turns the unrolling of plus metacharacters on or off. When a pattern is broken up, C becomes C, C (and C becomes C, C. This may allow the freed C to assemble with other patterns. Not enabled by default. =head2 lex(SCALAR) Change the pattern used to break a string apart into tokens. You can examine the C script as a starting point. =head2 reduce(0|1) Turns pattern reduction on or off. A reduced pattern may be considerably shorter than an unreduced pattern. Consider C I C. An unreduced pattern will be very similar to those produced by C. Reduction is on by default. Turning it off speeds assembly (but assembly is pretty fast -- it's the breaking up of the initial patterns in the lexing stage that can consume a non-negligible amount of time). =head2 mutable(0|1) This method has been marked as DEPRECATED. It will be removed in a future release. See the C method for a technique to replace its functionality. =head2 reset() Empties out the patterns that have been Ced or C-ed into the object. Does not modify the state of controller attributes such as C, C, C and the like. =head2 Default_Lexer B the C function is a class method, not an object method. It is a fatal error to call it as an object method. The C method lets you replace the default pattern used for all subsequently created C objects. It will not have any effect on existing objects. (It is also possible to override the lexer pattern used on a per-object basis). The parameter should be an ordinary scalar, not a compiled pattern. If the pattern fails to match all parts of the string, the missing parts will be returned as single chunks. Therefore the following pattern is legal (albeit rather cork-brained): Regexp::Assemble::Default_Lexer( '\\d' ); The above pattern will split up input strings digit by digit, and all non-digit characters as single chunks. =head1 DIAGNOSTICS "Cannot pass a C to Default_Lexer" You tried to replace the default lexer pattern with an object instead of a scalar. Solution: You probably tried to call C<< $obj->Default_Lexer >>. Call the qualified class method instead C. "filter method not passed a coderef" "pre_filter method not passed a coderef" A reference to a subroutine (anonymous or otherwise) was expected. Solution: read the documentation for the C method. "duplicate pattern added: /.../" The C attribute is active, and a duplicate pattern was added (well duh!). Solution: clean your data. "cannot open [file] for input: [reason]" The C method was unable to open the specified file for whatever reason. Solution: make sure the file exists and the script has the required privileges to read it. =head1 NOTES This module has been tested successfully with a range of versions of perl, from 5.005_03 to 5.9.3. Use of 5.6.0 is not recommended. The expressions produced by this module can be used with the PCRE library. Remember to "double up" your backslashes if the patterns are hard-coded as constants in your program. That is, you should literally C rather than C. It usually will work either way, but it's good practice to do so. Where possible, supply the simplest tokens possible. Don't add C when C will do. The reason is that if you also add C the resulting assembly changes dramatically: C I C. Since R::A doesn't perform enough analysis, it won't "unroll" the C<{2}> quantifier, and will fail to notice the divergence after the first C<-d\d+>. Furthermore, when the string 'X-123000P' is matched against the first assembly, the regexp engine will have to backtrack over each alternation (the one that ends in Y B the one that ends in Z) before determining that there is no match. No such backtracking occurs in the second pattern: as soon as the engine encounters the 'P' in the target string, neither of the alternations at that point (C<-\d+Y> or C) could succeed and so the match fails. C does, however, know how to build character classes. Given C, C and C, it will assemble these into C. When C<-> (dash) appears as a candidate for a character class it will be the first character in the class. When C<^> (circumflex) appears as a candidate for a character class it will be the last character in the class. It also knows about meta-characters than can "absorb" regular characters. For instance, given C and C, it knows that C<5> can be represented by C<\d> and so the assembly is just C. The "absorbent" meta-characters it deals with are C<.>, C<\d>, C<\s> and C<\W> and their complements. It will replace C<\d>/C<\D>, C<\s>/C<\S> and C<\w>/C<\W> by C<.> (dot), and it will drop C<\d> if C<\w> is also present (as will C<\D> in the presence of C<\W>). C deals correctly with C's propensity to backslash many characters that have no need to be. Backslashes on non-metacharacters will be removed. Similarly, in character classes, a number of characters lose their magic and so no longer need to be backslashed within a character class. Two common examples are C<.> (dot) and C<$>. Such characters will lose their backslash. At the same time, it will also process C<\Q...\E> sequences. When such a sequence is encountered, the inner section is extracted and C is applied to the section. The resulting quoted text is then used in place of the original unquoted text, and the C<\Q> and C<\E> metacharacters are thrown away. Similar processing occurs with the C<\U...\E> and C<\L...\E> sequences. This may have surprising effects when using a dispatch table. In this case, you will need to know exactly what the module makes of your input. Use the C method to find out what's going on: $pattern = join( '', @{$re->lexstr($pattern)} ); If all the digits 0..9 appear in a character class, C will replace them by C<\d>. I'd do it for letters as well, but thinking about accented characters and other glyphs hurts my head. In an alternation, the longest paths are chosen first (for example, C). When two paths have the same length, the path with the most subpaths will appear first. This aims to put the "busiest" paths to the front of the alternation. For example, the list C, C, C, C and C will produce the pattern C<(?:f(?:ew|ig|un)|b(?:ad|it))>. See F for a real-world example of how alternations are sorted. Once you have looked at that, everything should be crystal clear. When tracking is in use, no reduction is performed. nor are character classes formed. The reason is that it is too difficult to determine the original pattern afterwards. Consider the two patterns C and C. These should be reduced to C. The final character matches one of two possibilities. To resolve whether it matched an C<'e'> or C<'m'> would require keeping track of the fact that the pattern finished up in a character class, which would the require a whole lot more work to figure out which character of the class matched. Without character classes it becomes much easier. Instead, C is produced, which lets us find out more simply where we ended up. Similarly, C and C should form C<(?:dog|sea)food>. When the pattern is being assembled, the tracking decision needs to be made at the end of the grouping, but the tail of the pattern has not yet been visited. Deferring things to make this work correctly is a vast hassle. In this case, the pattern becomes merely C<(?:dogfood|seafood>. Tracked patterns will therefore be bulkier than simple patterns. There is an open bug on this issue: L If this bug is ever resolved, tracking would become much easier to deal with (none of the C hassle would be required - you could just match like a regular RE and it would Just Work). =head1 SEE ALSO =over 4 =item L General information about Perl's regular expressions. =item L Specific information about C. =item Regex::PreSuf C takes a string and chops it itself into tokens of length 1. Since it can't deal with tokens of more than one character, it can't deal with meta-characters and thus no regular expressions. Which is the main reason why I wrote this module. =item Regexp::Optimizer C produces regular expressions that are similar to those produced by R::A with reductions switched off. It's biggest drawback is that it is exponentially slower than Regexp::Assemble on very large sets of patterns. =item Regexp::Parser Fine grained analysis of regular expressions. =item Regexp::Trie Funnily enough, this was my working name for C during its development. I changed the name because I thought it was too obscure. Anyway, C does much the same as C and C except that it runs much faster (according to the author). It does not recognise meta characters (that is, 'a+b' is interpreted as 'a\+b'). =item Text::Trie C is well worth investigating. Tries can outperform very bushy (read: many alternations) patterns. =item Tree::Trie C is another module that builds tries. The algorithm that C uses appears to be quite similar to the algorithm described therein, except that C solves its end-marker problem without having to rewrite the leaves. =back =head1 See Also For alternatives to this module, consider one of: =over 4 =item o L =item o L =item o L =back =head1 LIMITATIONS Some mildly complex cases are not handled well. See examples/failure.01.pl and L. See also L for a discussion of some of the issues arising with the use of a huge number of alterations. Thanx to Slaven Rezic for the details of trie 'v' non-trie operations within Perl which influence regexp handling of alternations. does not attempt to find common substrings. For instance, it will not collapse C down to C. If there's a module out there that performs this sort of string analysis I'd like to know about it. But keep in mind that the algorithms that do this are very expensive: quadratic or worse. C does not interpret meta-character modifiers. For instance, if the following two patterns are given: C and C, it will not determine that C<\d> can be matched by C<\d+>. Instead, it will produce C. Along a similar line of reasoning, it will not determine that C and C is equivalent to C (It will produce C instead). You cannot remove a pattern that has been added to an object. You'll just have to start over again. Adding a pattern is difficult enough, I'd need a solid argument to convince me to add a C method. If you need to do this you should read the documentation for the C method. C does not (yet)? employ the C<(?E...)> construct. The module does not produce POSIX-style regular expressions. This would be quite easy to add, if there was a demand for it. =head1 BUGS Patterns that generate look-ahead assertions sometimes produce incorrect patterns in certain obscure corner cases. If you suspect that this is occurring in your pattern, disable lookaheads. Tracking doesn't really work at all with 5.6.0. It works better in subsequent 5.6 releases. For maximum reliability, the use of a 5.8 release is strongly recommended. Tracking barely works with 5.005_04. Of note, using C<\d>-style meta-characters invariably causes panics. Tracking really comes into its own in Perl 5.10. If you feed C patterns with nested parentheses, there is a chance that the resulting pattern will be uncompilable due to mismatched parentheses (not enough closing parentheses). This is normal, so long as the default lexer pattern is used. If you want to find out which pattern among a list of 3000 patterns are to blame (speaking from experience here), the F script offers a strategy for pinpointing the pattern at fault. While you may not be able to use the script directly, the general approach is easy to implement. The algorithm used to assemble the regular expressions makes extensive use of mutually-recursive functions (that is, A calls B, B calls A, ...) For deeply similar expressions, it may be possible to provoke "Deep recursion" warnings. The module has been tested extensively, and has an extensive test suite (that achieves close to 100% statement coverage), but you never know... A bug may manifest itself in two ways: creating a pattern that cannot be compiled, such as C, or a pattern that compiles correctly but that either matches things it shouldn't, or doesn't match things it should. It is assumed that Such problems will occur when the reduction algorithm encounters some sort of edge case. A temporary work-around is to disable reductions: my $pattern = $assembler->reduce(0)->re; A discussion about implementation details and where bugs might lurk appears in the README file. If this file is not available locally, you should be able to find a copy on the Web at your nearest CPAN mirror. Seriously, though, a number of people have been using this module to create expressions anywhere from 140Kb to 600Kb in size, and it seems to be working according to spec. Thus, I don't think there are any serious bugs remaining. If you are feeling brave, extensive debugging traces are available to figure out where assembly goes wrong. Please report all bugs at L Make sure you include the output from the following two commands: perl -MRegexp::Assemble -le 'print $Regexp::Assemble::VERSION' perl -V There is a mailing list for the discussion of C. Subscription details are available at L. =head1 ACKNOWLEDGEMENTS This module grew out of work I did building access maps for Postfix, a modern SMTP mail transfer agent. See L for more information. I used Perl to build large regular expressions for blocking dynamic/residential IP addresses to cut down on spam and viruses. Once I had the code running for this, it was easy to start adding stuff to block really blatant spam subject lines, bogus HELO strings, spammer mailer-ids and more... I presented the work at the French Perl Workshop in 2004, and the thing most people asked was whether the underlying mechanism for assembling the REs was available as a module. At that time it was nothing more that a twisty maze of scripts, all different. The interest shown indicated that a module was called for. I'd like to thank the people who showed interest. Hey, it's going to make I messy scripts smaller, in any case. Thomas Drugeon was a valuable sounding board for trying out early ideas. Jean Forget and Philippe Blayo looked over an early version. H.Merijn Brandt stopped over in Paris one evening, and discussed things over a few beers. Nicholas Clark pointed out that while what this module does (?:c|sh)ould be done in perl's core, as per the 2004 TODO, he encouraged me to continue with the development of this module. In any event, this module allows one to gauge the difficulty of undertaking the endeavour in C. I'd rather gouge my eyes out with a blunt pencil. Paul Johnson settled the question as to whether this module should live in the Regex:: namespace, or Regexp:: namespace. If you're not convinced, try running the following one-liner: perl -le 'print ref qr//' Philippe Bruhat found a couple of corner cases where this module could produce incorrect results. Such feedback is invaluable, and only improves the module's quality. =head1 Machine-Readable Change Log The file Changes was converted into Changelog.ini by L. =head1 AUTHOR David Landgren Copyright (C) 2004-2011. All rights reserved. http://www.landgren.net/perl/ If you use this module, I'd love to hear about what you're using it for. If you want to be informed of updates, send me a note. Ron Savage is co-maint of the module, starting with V 0.36. =head1 Repository L =head1 TODO 1. Tree equivalencies. Currently, /contend/ /content/ /resend/ /resent/ produces (?:conten[dt]|resend[dt]) but it is possible to produce (?:cont|res)en[dt] if one can spot the common tail nodes (and walk back the equivalent paths). Or be by me my => /[bm][ey]/ in the simplest case. To do this requires a certain amount of restructuring of the code. Currently, the algorithm uses a two-phase approach. In the first phase, the trie is traversed and reductions are performed. In the second phase, the reduced trie is traversed and the pattern is emitted. What has to occur is that the reduction and emission have to occur together. As a node is completed, it is replaced by its string representation. This then allows child nodes to be compared for equality with a simple 'eq'. Since there is only a single traversal, the overall generation time might drop, even though the context baggage required to delve through the tree will be more expensive to carry along (a hash rather than a couple of scalars). Actually, a simpler approach is to take on a secret sentinel atom at the end of every pattern, which gives the reduction algorithm sufficient traction to create a perfect trie. I'm rewriting the reduction code using this technique. 2. Investigate how (?>foo) works. Can it be applied? 5. How can a tracked pattern be serialised? (Add freeze and thaw methods). 6. Store callbacks per tracked pattern. 12. utf-8... hmmmm... 14. Adding qr//'ed patterns. For example, consider $r->add ( qr/^abc/i ) ->add( qr/^abd/ ) ->add( qr/^ab e/x ); this should admit abc abC aBc aBC abd abe as matches 16. Allow a fast, unsafe tracking mode, that can be used if a(?bc)? can't happen. (Possibly carp if it does appear during traversal)? 17. given a-\d+-\d+-\d+-\d+-b, produce a(?:-\d+){4}-b. Something along the lines of (.{4))(\1+) would let the regexp engine itself be brought to bear on the matter, which is a rather appealing idea. Consider while(/(?!\+)(\S{2,}?)(\1+)/g) { ... $1, $2 ... } as a starting point. 19. The reduction code has become unbelievably baroque. Adding code to handle (sting,singing,sing) => s(?:(?:ing)?|t)ing was far too difficult. Adding more stuff just breaks existing behaviour. And fixing the ^abcd$ ... bug broke stuff all over again. Now that the corner cases are more clearly identified, a full rewrite of the reduction code is needed. And would admit the possibility of implementing items 1 and 17. 20. Handle debug unrev with a separate bit 23. Japhy's http://www.perlmonks.org/index.pl?node_id=90876 list2range regexp 24. Lookahead assertions contain serious bugs (as shown by assembling powersets. Need to save more context during reduction, which in turn will simplify the preparation of the lookahead classes. See also 19. 26. _lex() swamps the overall run-time. It stems from the decision to use a single regexp to pull apart any pattern. A suite of simpler regexp to pick of parens, char classes, quantifiers and bare tokens may be faster. (This has been implemented as _fastlex(), but it's only marginally faster. Perhaps split-by- char and lex a la C? 27. We don't, as yet, unroll_plus a paren e.g. (abc)+? 28. We don't reroll unrolled a a* to a+ in indented or tracked output 29. Use (*MARK n) in blead for tracked patterns, and use (*FAIL) for the unmatchable pattern. =head1 LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut # Return a +ve value to tell Perl the module is ready to go. 'The Lusty Decadent Delights of Imperial Pompeii'; Regexp-Assemble-0.38/Changelog.ini0000644000175000017500000004634413122055177015213 0ustar ronron[Module] Name=Regexp::Assemble Changelog.Creator=Module::Metadata::Changes V 2.12 Changelog.Parser=Config::IniFiles V 2.94 [V 0.38] Date=2017-06-20T08:51:00 Comments= < /a/ 0.27 2006-11-01 23:43:35 UTC - rewrote the lexing of patterns in _fastlex(). Unfortunately this doesn't speed things up as much as I had hoped. - eg/assemble now recognises -T to dump timing statistics. - file parameter in add_file() may accept a single scalar (or a list, as before). - rs parameter in new() was not recognised as an alias for input_record_separator, - anchor_string_absolute as a parameter to new() would not have worked correctly. - a couple of anchor_() methods would not have worked correctly. - Added MANIFEST.SKIP, now that the module is under version control. - Broke out the debug tests into a separate file (t/09_debug.t). - cmp_ok() tests that tested equality were replaced by is(). - tests in t/03_str.t transformed to a data-driven approach, in order to slim down the size of the distribution tarball. - Typo spotted in the documentation by Stephan (bug #20425). 0.26 2006-07-12 09:27:51 UTC - Incorporated a patch to the test suite from barbie, to work around a problem encountered on Win32 (bug #17507). - The "match nothing" pattern was incorrect (but so obscure as to be reasonably safe). - Removed the unguarded tests in t/06_general.t that the Test::More workaround in 0.24 skips. - Newer versions of Sub::Uplevel no longer need to be guarded against in t/07_warning.t. EOT [V 0.25] Date=2006-04-20T18:04:49 Comments= <add( 'a\.b' )->add( 'a-b' )->as_string(indent=>2) ... would produce a(?:\.|-b) instead of a[-.]b. - Fixed bug ($ and ^ not treated correctly). See RT ticket of (?:^|m)a - Statistics! See the stats_* methods. - eg/assemble now has an -s switch to display these statistics - Minor tweak to t/02_reduce.t to get it to play nicely with Devel::Cover. - t/02_reduce.t had an unnecessary use Data::Dumper. 0.19 2005-11-02 15:16:16 UTC - Change croaking diagnostic concerning Default_Lexer. Bug spotted by barbie in ticket #15044. - Pointer to C in the documentation. - Excised Test::Deep probe in 00_basic.t, since the module is no longer used. - Detabbed eg/* 0.18 2005-10-08 20:37:53 UTC - Fixed '\Q[' to be as treated as '\[' instead of '['. What's more, the tests had this as the Right Thing. What was I thinking? Wound up rewriting _lex_stateful in a much less hairier way, even though it now uses gotos. - Introduced a context hash for dragging around the bits and pieces required by the descent into _reduce_path. It doesn't really help much right now, but is vital for solving the qw(be by my me) => /[bm][ey]/ problem. See TODO for more notes. - Fixed the debug output to play nicely with the test harness (by prefixing everything with a #). It had never been a problem, but you never know. - Added a script named 'debugging' to help people figure out why assembled patterns go wonky (which is invariably due to nested parentheses). - Added a script 'tld', that produces a regexp for matching internet Top Level Domain names. This happens to be an ideal example of showing how the alternations are sorted. - Added a script 'roman', that produces a regexp for matching Roman numerals. Just for fun. - Removed the 'assemble-check' script, whose functionality is adequately dealt with via 'assemble -t'. - Tightened up the explanation of why tracked patterns are bulkier - ISOfied the dates in this file. 0.17 2005-09-10 16:41:22 UTC - Add capture() method. - Restructure _insert_path(). - Factor out duplicated code introduced in 0.16 into _build_re(). - Ensure that the test suite exercises the fallback code path for when Storable is missing, even if Storable is available. - Added test_pod_coverage, merely to earn a free Kwalitee point. 0.16 2005-08-22 23:04:02 UTC - Tracked patterns silently ignored imsx flags. Spotted by Bart Lateur. 0.15 2005-04-27 06:50:31 UTC - Oops. Detabbed all the files and did not rerun the tests. t/03_str.t explicitly performs a test on a literal TAB character, and so it failed. Always, always, *ALWAYS* run the test suite as the last task before uploading. Grrr. 0.14 2005-04-27 00:32:43 UTC - Performance tuning release. Played around significantly with _insertr and lex but major improvement will only come about by writing the lexing routine in C. - Reordered $Default_Lexer to bring the most common cases to the front of the pattern. - Inline the effects of \U, \L, \c, \x. This is handled by _lex_stateful (which offloads some of the worst case lexing costs into a separate routine and thus makes the more usual cases run faster). Handling of \Q in the previous release was incorrect. (Sigh). - Backslash slashes. - Passed arrays around by reference between _lex and a newly introduced _insertr routine. - Silenced warning in _slide_tail (ran/reran) - Fixed bug in _slide_tail (didn't handle '0' as a token). One section of the code used to do its own sliding, now it uses _slide_tail. - Fixed bug in _node_eq revealed by 5.6.1 (implicit ordering of hash keys). - Optimized node_offset() - replace ok() in tests by better things (is, like, ...) - removed use of Test::Differences, since it doesn't work on complex structures. 0.13 2005-04-11 21:59:26 UTC - Deal with \Q...\E patterns. - $Default_Lexer pattern fails on 5.6.x: it would lex '\-' as '\', '-'. - Tests to prove that the global $_ is not clobbered by the module. - Used cmp_ok rather than ok where it makes sense. - Added a (belated) DEBUG_LEX debugging mode 0.12 2005-04-11 23:49:16 UTC - Forgot to guard against the possibility of Test::Differences not being available. This would cause erroneous failures in the test suite if it was not installed. - Quotemeta was still giving troubles. Exhaustive testing also turned up the fact that a bare add('0') would be ignored (and thus the null-match pattern would be returned. - More tweaks to the documentation. 0.11 Sat Apr 9 19:44:19 2005 UTC - Performed coverage testing with Devel::Cover Numerous tests added as a result. Borderline bugs fixed (bizarre copy of ARRAY in leave under D::C - fixed in 0.10). - Finalised the interface to using zero-width lookahead assertions. Depending on the match/failure ratio of the pattern to targets, the pattern execution may be slower with ZWLAs than without. Benchmark it. - Made _dump call _dump_node if passed a reference to a hash. This simplifies the code a bit, since one no longer has to worry about whether the thing we are looking at is a node or a path. All in all a minor patch, just to tidy up some loose ends before moving to heftier optimisations. - The fix in 0.10 for quotemeta didn't go far enough. Hopefully this version gets it right. - A number of minor tweaks based on information discovered during coverage testing. - Added documentation about the mailing list. Sundry documentation tweaks. 0.10 2005-03-29 09:01:49 UTC - Correct Default_Lexer$ pattern to deal with the excessively backslashed tokens that C likes to produce. Bug spotted by Walter Roberson. - Added a fix to an obscure bug that Devel::Cover uncovered. The next release will fold in similar improvements found by using Devel::Cover. 0.09 2005-01-22 9:28:21 UTC - Added lookahead assertions at nodes. (This concept is shamelessly pinched from Dan Kogai's Regexp::Optimizer). The code is currently commented out, because in all my benchmarks the resulting regexps are slower with them. Look for calls to _combine if you want to play around with this. - $Default_Lexer and $Single_Char regexps updated to fix a bug where backslashed characters were broken apart between the backslash and the character, resulting in uncompilable regexps. - Character classes are now sorted to the left of a list of alternations. - Corrected license info in META.yml - Started to switch from ok() to cmp_ok() in the test suite to produce human-readable test failures. 0.08 2005-01-03 11:23:50 UTC - Bug in insert_node fixed: did not deal with the following correctly: qw/bcktx bckx bdix bdktx bdkx/ (The assymetry introduced by 'bdix' threw things off, or something like that). - Bug in reduced regexp generation (reinstated code that had been excised from _re_path() et al). - Rewrote the tests to eliminate the need for Test::Deep. Test::More::is_deeply is sufficient. 0.07 2004-12-17 19:31:18 UTC - It would have been nice to have remembered to update the release date in the POD, and the version in the README. 0.06 2004-12-17 17:38:41 UTC - Can now track regular expressions. Given a match, it is possible to determine which original pattern gave rise to the match. - Improved character class generation: . (anychar) was not special-cased, which would have lead to a.b axb giving a[.x]b Also takes into account single-char width metachars like \t \e et al. Filters out digits if \d appears, and for similar metachars (\D, \s, \W...) - Added a pre_filter method, to perform input filtering prior to the pattern being lexed. - Added a flags method, to allow for (?imsx) pattern modifiers. - enhanced the assemble script: added -b, -c, -d, -v; documented -r - Additions to the README - Added Test::Simple and Test::More as prerequisites. 0.05 2004-12-10 11:52:13 UTC - Bug fix in tests. The skip test in version 0.04 did not deal correctly with non-5.6.0 perls that do not have Test::Deep installed. 0.04 2004-12-09 22:29:56 UTC - In 5.6.0, the backlashes in a quoted word list, qw[ \\d ], will have their backslashes doubled up. In this case, don't run the tests. (Reading from a file or getting input from some other source other than qw[] operators works just fine). 0.03 2004-12-08 21:55:27 UTC - Bug fix: Leading 0s could be omitted from paths because of the difference between while($p) versus while(defined($p)). - An assembled pattern can be generated with whitespace. This can be used in conjunction with the /x modifier, and also for debugging. - Code profiled: dead code paths removed, hotspots rewritten to run more quickly. - Documentation typos and wordos. - assemble script now accepts a number of command line switches to control its behaviour. - More tests. Now with Test::Pod. 0.02 2004-11-19 11:16:33 UTC - An R::A object that has had nothing added to it now produces a pattern that explicitly matches nothing (the original behaviour would match anything). - An object can now chomp its own input. Useful for slurping files. It can also filter the input tokens and discard patterns that don't adhere to what's expected (sanity checking e.g.: don't want spaces). - Documented and added functions to allow for the lexer pattern to be manipulated. - The reset() method was commented out (and the test suite didn't catch the fact). - Detabbed the Assemble.pm, eg/* and t/* files (I like interpreting tabs as four spaces, but this produces horrible indentation on www.cpan.org). - t/00_basic.t test counts were wrong. This showed up if Test::Deep was not installed. - t/02_reduce.t does not need to 'use Data::Dumper'. - Tweaked eg/hostmatch/hostmatch; added eg/assemble, eg/assemble-check - Typos, corrections and addtions to the documentation. 0.01 2004-07-09 21:05:18 UTC - original version; created by h2xs 1.19 (seriously!) EOT Regexp-Assemble-0.38/t/0000755000175000017500000000000013122055201013037 5ustar ronronRegexp-Assemble-0.38/t/06_general.t0000644000175000017500000003167211022504665015171 0ustar ronron# 06_general.t # # Test suite for Regexp::Assemble # Check out the general functionality, now that all the subsystems have been exercised # # copyright (C) 2004-2007 David Landgren use strict; use Regexp::Assemble; eval qq{use Test::More tests => 142 }; if( $@ ) { warn "# Test::More not available, no tests performed\n"; print "1..1\nok 1\n"; exit 0; } use constant NR_GOOD => 45; use constant NR_BAD => 529; use constant NR_ERROR => 0; my $fixed = 'The scalar remains the same'; $_ = $fixed; my $target; my $ra = Regexp::Assemble->new->add( qw/foo bar rat/ ); for $target( qw/unfooled disembark vibration/ ) { like( $target, qr/$ra/, "match ok $target" ) } ok( !defined($ra->source()), 'source() undefined' ); for $target( qw/unfooled disembark vibration/ ) { unlike( $target, qr/^$ra/, "anchored match not ok $target" ) } $ra->reset; for $target( qw/unfooled disembark vibration/ ) { unlike( $target, qr/$ra/, "fail after reset $target" ) } $ra->add( qw/who what where why when/ ); for $target( qw/unfooled disembark vibration/ ) { unlike( $target, qr/$ra/, "fail ok $target" ) } for $target( qw/snowhouse somewhat nowhereness whyever nowhence/ ) { like( $target, qr/$ra/, "new match ok $target" ) } $ra->reset->mutable(1); unlike( 'nothing', qr/$ra/, "match nothing after reset" ); $ra->add( '^foo\\d+' ); like( 'foo12', qr/$ra/, "match 1 ok foo12" ); unlike( 'nfoo12', qr/$ra/, "match 1 nok nfoo12" ); unlike( 'bar6', qr/$ra/, "match 1 nok bar6" ); ok( !defined($ra->mvar()), 'mvar() undefined' ); $ra->add( 'bar\\d+' ); like( 'foo12', qr/$ra/, "match 2 ok foo12" ); unlike( 'nfoo12', qr/$ra/, "match 2 nok nfoo12" ); like( 'bar6', qr/$ra/, "match 2 ok bar6" ); $ra->reset->filter( sub { not grep { $_ !~ /[\d ]/ } @_ } ); $ra->add( '1 2 4' ); $ra->insert( '1', '2', '8*' ); unlike( '3 4 1 2', qr/$ra/, 'filter nok 3 4 1 2' ); like( '3 1 2 4', qr/$ra/, 'filter ok 3 1 2 4' ); unlike( '5 2 3 4', qr/$ra/, 'filter ok 5 2 3 4' ); $ra->add( '2 3 a+' ); $ra->insert( '2', ' ', '3', ' ', 'a+' ); unlike( '5 2 3 4', qr/$ra/, 'filter ok 5 2 3 4 (2)' ); unlike( '5 2 3 aaa', qr/$ra/, 'filter nok 5 2 3 a+' ); $ra->reset->filter( undef ); $ra->add( '1 2 a+' ); like( '5 1 2 aaaa', qr/$ra/, 'filter now ok 5 1 2 a+' ); $ra->reset->pre_filter( sub { $_[0] !~ /^#/ } ); $ra->add( '#de' ); $ra->add( 'abc' ); unlike( '#de', qr/^$ra$/, '#de not matched by comment-filtered assembly' ); like( 'abc', qr/^$ra$/, 'abc matched by comment-filtered assembly' ); SKIP: { skip( "is_deeply is broken in this version of Test::More (v$Test::More::VERSION)", 5 ) unless $Test::More::VERSION > 0.47; { my $orig = Regexp::Assemble->new; my $clone = $orig->clone; is_deeply( $orig, $clone, 'clone empty' ); } { my $orig = Regexp::Assemble->new->add( qw/ dig dug dog / ); my $clone = $orig->clone; is_deeply( $orig, $clone, 'clone path' ); } { my $orig = Regexp::Assemble->new->add( qw/ dig dug dog / ); my $clone = $orig->clone; $orig->add( 'digger' ); $clone->add( 'digger' ); is_deeply( $orig, $clone, 'clone then add' ); } { my $orig = Regexp::Assemble->new ->add( qw/ bird cat dog elephant fox/ ); my $clone = $orig->clone; is_deeply( $orig, $clone, 'clone node' ); } { my $orig = Regexp::Assemble->new ->add( qw/ after alter amber cheer steer / ); my $clone = $orig->clone; is_deeply( $orig, $clone, 'clone more' ); } } SKIP: { # If the Storable module is available, we will have used # that above, however, we will not have tested the pure-Perl # fallback routines. skip( 'Pure-Perl clone() already tested', 5 ) unless $Regexp::Assemble::have_Storable; skip( "is_deeply is broken in this version of Test::More (v$Test::More::VERSION)", 5 ) unless $Test::More::VERSION > 0.47; local $Regexp::Assemble::have_Storable = 0; { my $orig = Regexp::Assemble->new; my $clone = $orig->clone; is_deeply( $orig, $clone, 'clone empty' ); } { my $orig = Regexp::Assemble->new->add( qw/ dig dug dog / ); my $clone = $orig->clone; is_deeply( $orig, $clone, 'clone path' ); } { my $orig = Regexp::Assemble->new->add( qw/ dig dug dog / ); my $clone = $orig->clone; $orig->add( 'digger' ); $clone->add( 'digger' ); is_deeply( $orig, $clone, 'clone then add' ); } { my $orig = Regexp::Assemble->new ->add( qw/ bird cat dog elephant fox/ ); my $clone = $orig->clone; is_deeply( $orig, $clone, 'clone node' ); } { my $orig = Regexp::Assemble->new ->add( qw/ after alter amber cheer steer / ); my $clone = $orig->clone; is_deeply( $orig, $clone, 'clone more' ); } } { my $r = Regexp::Assemble->new ->add( qw/ dig dug / ); cmp_ok( $r->dump, 'eq', '[d {i=>[i g] u=>[u g]}]', 'dump path' ); } { my $r = Regexp::Assemble->new ->add( 'a b' ); cmp_ok( $r->dump, 'eq', q<[a ' ' b]>, 'dump path with space' ); $r->insert( 'a', ' ', 'b', 'c', 'd' ); cmp_ok( $r->dump, 'eq', q([a ' ' b {* c=>[c d]}]), 'dump path with space 2' ); } { my $r = Regexp::Assemble->new ->add( qw/ dog cat / ); cmp_ok( $r->dump, 'eq', '[{c=>[c a t] d=>[d o g]}]', 'dump node' ); } { my $r = Regexp::Assemble->new->add( qw/ house home / ); $r->insert(); cmp_ok( $r->dump, 'eq', '[{* h=>[h o {m=>[m e] u=>[u s e]}]}]', 'add opt to path' ); } { my $r = Regexp::Assemble->new->add( qw/ dog cat / ); $r->insert(); cmp_ok( $r->dump, 'eq', '[{* c=>[c a t] d=>[d o g]}]', 'add opt to node' ); } { my $slide = Regexp::Assemble->new; cmp_ok( $slide->add( qw/schoolkids acids acidoids/ )->as_string, 'eq', '(?:ac(?:ido)?|schoolk)ids', 'schoolkids acids acidoids' ); cmp_ok( $slide->add( qw/schoolkids acidoids/ )->as_string, 'eq', '(?:schoolk|acido)ids', 'schoolkids acidoids' ); cmp_ok( $slide->add( qw/nonschoolkids nonacidoids/ )->as_string, 'eq', 'non(?:schoolk|acido)ids', 'nonschoolkids nonacidoids' ); } { cmp_ok( Regexp::Assemble->new ->add( qw( sing singing )) ->as_string, 'eq', 'sing(?:ing)?', 'super slide sing singing' # no sliding done ); cmp_ok( Regexp::Assemble->new ->add( qw( sing singing sling)) ->as_string, 'eq', 's(?:(?:ing)?|l)ing', 'super slide sing singing sling' ); cmp_ok( Regexp::Assemble->new ->add( qw( sing singing sling slinging)) ->as_string, 'eq', 'sl?(?:ing)?ing', 'super slide sing singing sling slinging' ); cmp_ok( Regexp::Assemble->new ->add( qw( sing singing sling slinging sting stinging )) ->as_string, 'eq', 's[lt]?(?:ing)?ing', 'super slide sing singing sling slinging sting stinging' ); cmp_ok( Regexp::Assemble->new ->add( qw( sing singing sling slinging sting stinging string stringing swing swinging )) ->as_string, 'eq', 's(?:[lw]|tr?)?(?:ing)?ing', 'super slide sing singing sling slinging sting stinging string stringing swing swinging' ); } { my $re = Regexp::Assemble->new( flags => 'i' )->add( qw/ ^ab ^are de / ); like( 'able', qr/$re/, '{^ab ^are de} /i matches able' ); like( 'About', qr/$re/, '{^ab ^are de} /i matches About' ); unlike( 'bare', qr/$re/, '{^ab ^are de} /i fails bare' ); like( 'death', qr/$re/, '{^ab ^are de} /i matches death' ); like( 'DEEP', qr/$re/, '{^ab ^are de} /i matches DEEP' ); } { my $re = Regexp::Assemble->new->add( qw/abc def ghi/ ); cmp_ok( $re->{stats_add}, '==', 3, "stats add 3x3" ); cmp_ok( $re->{stats_raw}, '==', 9, "stats raw 3x3" ); cmp_ok( $re->{stats_cooked}, '==', 9, "stats cooked 3x3" ); ok( !defined($re->{stats_dup}), "stats dup 3x3" ); $re->add( 'de' ); cmp_ok( $re->{stats_add}, '==', 4, "stats add 3x3 +1" ); cmp_ok( $re->{stats_raw}, '==', 11, "stats raw 3x3 +1" ); cmp_ok( $re->{stats_cooked}, '==', 11, "stats cooked 3x3 +1" ); } { my $re = Regexp::Assemble->new->add( '\\Qabc.def.ghi\\E' ); cmp_ok( $re->{stats_add}, '==', 1, "stats add qm" ); cmp_ok( $re->{stats_raw}, '==', 15, "stats raw qm" ); cmp_ok( $re->{stats_cooked}, '==', 13, "stats cooked qm" ); ok( !defined($re->{stats_dup}), "stats dup qm" ); } { my $re = Regexp::Assemble->new->add( 'abc\\,def', 'abc\\,def' ); cmp_ok( $re->{stats_add}, '==', 1, "stats add unqm dup" ); cmp_ok( $re->{stats_raw}, '==', 16, "stats raw unqm dup" ); cmp_ok( $re->{stats_cooked}, '==', 7, "stats cooked unqm dup" ); cmp_ok( $re->{stats_dup}, '==', 1, "stats dup unqm dup" ); cmp_ok( $re->stats_length, '==', 0, "stats_length unqm dup" ); my $str = $re->as_string; cmp_ok( $str, 'eq', 'abc,def', "stats str unqm dup" ); cmp_ok( $re->stats_length, '==', 7, "stats len unqm dup" ); } { my $re = Regexp::Assemble->new->add( '' ); cmp_ok( $re->{stats_add}, '==', 1, "stats add empty" ); cmp_ok( $re->{stats_raw}, '==', 0, "stats raw empty" ); ok( !defined($re->{stats_cooked}), "stats cooked empty" ); ok( !defined($re->{stats_dup}), "stats dup empty" ); } { my $re = Regexp::Assemble->new; cmp_ok( $re->stats_add, '==', 0, "stats_add empty" ); cmp_ok( $re->stats_raw, '==', 0, "stats_raw empty" ); cmp_ok( $re->stats_cooked, '==', 0, "stats_cooked empty" ); cmp_ok( $re->stats_dup, '==', 0, "stats_dup empty" ); cmp_ok( $re->stats_length, '==', 0, "stats_length empty" ); my $str = $re->as_string; cmp_ok( $str, 'eq', $Regexp::Assemble::Always_Fail, "stats str empty" ); # tricky! cmp_ok( $re->stats_length, '==', 0, "stats len empty" ); } { my $re = Regexp::Assemble->new->add( '\\Q.+\\E', '\\Q.+\\E', '\\Q.*\\E' ); cmp_ok( $re->stats_add, '==', 2, "stats_add 2" ); cmp_ok( $re->stats_raw, '==', 18, "stats_raw 2" ); cmp_ok( $re->stats_cooked, '==', 8, "stats_cooked 2" ); cmp_ok( $re->stats_dup, '==', 1, "stats_dup 2" ); cmp_ok( $re->stats_length, '==', 0, "stats_length 2" ); my $str = $re->as_string; cmp_ok( $str, 'eq', '\\.[*+]', "stats str 2" ); cmp_ok( $re->stats_length, '==', 6, "stats len 2 <$str>" ); } { # CPAN bug #24171 # given a list of strings my @str = ( 'a b', 'awb', 'a1b', 'bar', "a\nb" ); for my $meta (qw( s w d )) { # given a list of patterns my @re = ( "a\\${meta}b", "a\\@{[uc$meta]}b" ); # produce an assembled pattern my $re = Regexp::Assemble->new()->add(@re)->re(); my $re_fold = Regexp::Assemble->new()->fold_meta_pairs(0)->add(@re)->re(); # test it against the strings for my $str (@str) { # any match? my $ok = 0; $str =~ $_ && ( $ok = 1 ) for @re; # does the assemble regexp match as well? my $ptr = $str; $ptr =~ s/\\/\\\\/; $ptr =~ s/\n/\\n/; my $bug_success = ($str =~ /\n/) ? 0 : 1; my $bug_fail = 1 - $bug_success; is( ($str =~ $re) ? $bug_success : $bug_fail, $ok, "Folded meta pairs behave as list for \\$meta ($ptr,ok=$ok/$bug_success/$bug_fail)" ); is( ($str =~ $re_fold) ? 1 : 0, $ok, "Unfolded meta pairs behave as list for \\$meta ($ptr,ok=$ok)" ); } } } { my $u = Regexp::Assemble->new(unroll_plus => 1); my $str; $u->add( "a+b", 'ac' ); $str = $u->as_string; is( $str, 'a(?:a*b|c)', 'unroll plus a+b ac' ); $u->add( "\\LA+B", "ac" ); $str = $u->as_string; is( $str, 'a(?:a*b|c)', 'unroll plus \\LA+B ac' ); $u->add( '\\Ua+?b', "AC" ); $str = $u->as_string; is( $str, 'A(?:A*?B|C)', 'unroll plus \\Ua+?b AC' ); $u->add( qw(\\d+d \\de \\w+?x \\wy )); $str = $u->as_string; is( $str, '(?:\\w(?:\\w*?x|y)|\\d(?:\d*d|e))', 'unroll plus \\d and \\w' ); $u->add( qw( \\xab+f \\xabg \\xcd+?h \\xcdi )); $str = $u->as_string; is( $str, "(?:\xcd(?:\xcd*?h|i)|\xab(?:\xab*f|g))", 'unroll plus meta x' ); $u->add( qw([a-e]+h [a-e]i [f-j]+?k [f-j]m )); $str = $u->as_string; is( $str, "(?:[f-j](?:[f-j]*?k|m)|[a-e](?:[a-e]*h|i))", 'unroll plus class' ); $u->add( "a+b" ); $str = $u->as_string; is( $str, "a+b", 'reroll a+b' ); $u->add( "a+b", "a+" ); $str = $u->as_string; is( $str, "a+b?", 'reroll a+b?' ); $u->add( "a+?b", "a+?" ); $str = $u->as_string; is( $str, "a+?b?", 'reroll a+?b?' ); $u->unroll_plus(0)->add( qw(1+2 13) ); $str = $u->as_string; is( $str, "(?:1+2|13)", 'no unrolling' ); $u->unroll_plus()->add( qw(1+2 13) ); $str = $u->as_string; is( $str, "1(?:1*2|3)", 'unrolling again via implicit' ); $u->add(qw(d+ldrt d+ndrt d+ldt d+ndt d+x)); $str = $u->as_string; is( $str, 'd+(?:[ln]dr?t|x)', 'visit ARRAY codepath' ); } cmp_ok( $_, 'eq', $fixed, '$_ has not been altered' ); Regexp-Assemble-0.38/t/04_match.t0000644000175000017500000001343611022512220014626 0ustar ronron# 04_match.t # # Test suite for Regexp::Assemble # Tests to see than an assembled regexp matches all that it is supposed to # # copyright (C) 2004-2006 David Landgren use strict; eval qq{ use Test::More tests => 1381; }; if( $@ ) { warn "# Test::More not available, no tests performed\n"; print "1..1\nok 1\n"; exit 0; } use Regexp::Assemble; my $fixed = 'The scalar remains the same'; $_ = $fixed; # Bug #17507 as noted by barbie # # There appears to be a problem with the substitute key on Windows, for # at least Perl 5.6.1, which causes this test script to terminate # immediately on encountering the character. my $subchr = 0x1a; my $win32_56x = ($^O eq 'MSWin32' && $] < 5.008) ? 1 : 0; diag("enabling defensive workaround for $] on $^O") if $win32_56x; { for my $outer ( 0 .. 15 ) { my $re = Regexp::Assemble->new->anchor_string->chomp(0); for my $inner ( 0 .. 15 ) { next if $win32_56x and $subchr == ($outer*16 + $inner); $re->add( quotemeta( chr( $outer*16 + $inner ))); } for my $inner ( 0 .. 15 ) { if( $win32_56x and $subchr == ($outer*16 + $inner)) { ok( 1, "faking $subchr for 5.6 on Win32" ); } else { my $ch = chr($outer*16 + $inner); like( $ch, qr/$re/, "run $ch ($outer:$inner) $re" ); } } } } for( 0 .. 255 ) { if( $win32_56x and $subchr == $_) { pass("Fake a single for 5.6 on Win32"); next; } my $ch = chr($_); my $qm = Regexp::Assemble->new(chomp=>0)->anchor_string->add(quotemeta($ch)); like( $ch, qr/$qm/, "quotemeta(chr($_))" ); } for( 0 .. 127 ) { if( $win32_56x and $subchr == $_) { pass( "Fake a hi for 5.6 on Win32"); pass( "Fake a lo for 5.6 on Win32"); next; } my $lo = chr($_); my $hi = chr($_+128); my $qm = Regexp::Assemble->new(chomp => 0, anchor_string => 1)->add( quotemeta($lo), quotemeta($hi), ); like( $lo, qr/$qm/, "$_: quotemeta($lo) lo" ); like( $hi, qr/$qm/, "$_: quotemeta($hi) hi" ); } sub match { my $re = Regexp::Assemble->new; my $rela = Regexp::Assemble->new->lookahead(1); my $tag = shift; $re->add(@_); $rela->add(@_); my $reind = $re->clone; $reind = $re->clone->flags('x')->re(indent => 3); my $rered = $re->clone->reduce(0); my $str; for $str (@_) { like( $str, qr/^$re$/, "-- $tag: $str" ) or diag( " fail $str\n# match by $re\n" ); like( $str, qr/^$rela$/, "LA $tag: $str" ) or diag( " fail $str\n# match by lookahead $rela\n" ); like( $str, qr/^$reind$/x, "IN $tag: $str" ) or diag( " fail $str\n# match by indented $reind\n" ); like( $str, qr/^$rered$/, "RD $tag: $str" ) or diag( " fail $str\n# match by non-reduced $rered\n" ); } } sub match_list { my $tag = shift; my $patt = shift; my $test = shift; my $re = Regexp::Assemble->new->add(@$patt); my $rela = Regexp::Assemble->new->lookahead(1)->add(@$patt); my $str; for $str (@$test) { ok( $str =~ /^$re$/, "re $tag: $str" ) or diag( "fail re $str\n# in $re\n" ); ok( $str =~ /^$rela$/, "rela $tag: $str" ) or diag( "fail rela $str\n# in $rela\n" ); } } { my $re = Regexp::Assemble->new( flags => 'i' ) ->add( '^fg' ) ->re; like( 'fgx', qr/$re/, 'fgx/i' ); like( 'Fgx', qr/$re/, 'Fgx/i' ); like( 'FGx', qr/$re/, 'FGx/i' ); like( 'fGx', qr/$re/, 'fGx/i' ); unlike( 'F', qr/$re/, 'F/i' ); } { my $re = Regexp::Assemble->new( flags => 'x' ) ->add( '^fish' ) ->add( '^flash' ) ->add( '^fetish' ) ->add( '^foolish' ) ->re( indent => 2 ); like( 'fish', qr/$re/, 'fish/x' ); like( 'flash', qr/$re/, 'flash/x' ); like( 'fetish', qr/$re/, 'fetish/x' ); like( 'foolish', qr/$re/, 'foolish/x' ); unlike( 'fetch', qr/$re/, 'fetch/x' ); } match_list( 'lookahead car.*', [qw[caret caress careful careless caring carion carry carried]], [qw[caret caress careful careless caring carion carry carried]], ); match_list( 'a.x', [qw[ abx adx a.x ]] , [qw[ aax abx acx azx a4x a%x a+x a?x ]] ); match_list( 'POSIX', [qw[ X[0[:alpha:]%] Y[1-4[:punct:]a-c] ]] , [qw(X0 X% Xa Xf Y1 Y; Y! yc)] ); match_list( 'c.z', [qw[ c^z c-z c5z cmz ]] , [qw[ c^z c-z c5z cmz ]] ); match_list( '\d, \D', [ 'b\\d', 'b\\D' ] , [qw[ b4 bX b% b. b? ]] ); match_list( 'abcd', [qw[ abc abcd ac acd b bc bcd bd]], [qw[ abc abcd ac acd b bc bcd bd]], ); match( 'foo', qw[ foo bar rat quux ]); match( '.[ar]it 1', qw[ bait brit frit gait grit tait wait writ ]); match( '.[ar]it 2', qw[ bait brit gait grit ]); match( '.[ar]it 3', qw[ bit bait brit gait grit ]); match( '.[ar]it 4', qw[ barit bait brit gait grit ]); match( 't.*ough', qw[ tough though trough through thorough ]); match( 'g.*it', qw[ gait git grapefruit grassquit grit guitguit ]); match( 'show.*ess', qw[ showeriness showerless showiness showless ]); match( 'd*', qw[ den-at dot-at den-pt dot-pt dx ]); match( 'd*', qw[ den-at dot-at den-pt dot-pt d-at d-pt dx ]); match( 'un*ed', qw[ unimped unimpeded unimpelled ]); match( '(un)?*(ing)?ing', qw[ sing swing sting sling singing swinging stinging slinging unsing unswing unsting unsling unsinging unswinging unstinging unslinging ]); match( 's.*at 1', qw[ sat sweat sailbat ]); match( 'm[eant]+', qw[ ma mae man mana manatee mane manent manna mannan mant manta mat mate matta matte me mean meant meat meet meeten men met meta metate mete ]); match( 'ti[aeinost]+', qw[ tiao tie tien tin tine tinea tinean tineine tininess tinnet tinniness tinosa tinstone tint tinta tintie tintiness tintist tisane tit titanate titania titanite titano tite titi titian titien tittie ]); is( $_, $fixed, '$_ has not been altered' ); Regexp-Assemble-0.38/t/01_insert.t0000644000175000017500000003373511022301341015037 0ustar ronron# 01_insert.t # # Test suite for Regexp::Assemble # # When a series of paths are inserted in an R::A object, they are # stored into tree structure using a crafty blend of arrays and hashes. # # These tests verify that the tokens that are added to the # Regexp::Assemble object are stored correctly. # # The tests here verify to a much greater extent that the tree/hash structure # built up from repeated add() calls produce a structure that the # subsequent coalescing and reduction routines can operate upon correctly. # # copyright (C) 2004-2006 David Landgren use strict; use Regexp::Assemble; use constant permute_testcount => 120 * 5; # permute() has 120 (5!) variants eval qq{use Test::More tests => 50 + permute_testcount}; if( $@ ) { warn "# Test::More not available, no tests performed\n"; print "1..1\nok 1\n"; exit 0; } my $fixed = 'The scalar remains the same'; $_ = $fixed; { my $ra = Regexp::Assemble->new; $ra->insert( '' ); my $r = ($ra->_path)->[0]; is( ref($r), 'HASH', q{insert('') => first element is a HASH} ); is( scalar(keys %$r), 1, q{...and contains one key} ); ok( exists $r->{''}, q{...which is an empty string} ); ok( !defined($r->{''}), q{...and points to undef} ); } { my $ra = Regexp::Assemble->new; $ra->insert( 'a' ); my $r = $ra->_path; is( scalar @$r, 1, q{'a' => path of length 1} ); is( $r->[0], 'a', q{'a' => ...and is an 'a'} ); } { my $r = Regexp::Assemble->new; $r->insert(); $r->insert('a'); is_deeply( $r->_path, [{'' => undef, 'a' => ['a']}], q{insert(), insert('a')} ); } { my $ra = Regexp::Assemble->new; $ra->insert( 'a', 'b' ); my $r = $ra->_path; is( scalar @$r, 2, q{'ab' => path of length 2} ); is( join( '' => @$r ), 'ab', q{'ab' => ...and is 'a', 'b'} ); is( $ra->dump, '[a b]', 'dump([a b])' ); } { my $ra = Regexp::Assemble->new; $ra->insert( 'a', 'b' ); $ra->insert( 'a', 'c' ); is( $ra->dump, '[a {b=>[b] c=>[c]}]', 'dump([a {b c}])' ); my $r = $ra->_path; is( scalar @$r, 2, q{'ab,ac' => path of length 2} ); is( $r->[0], 'a', q{'ab,ac' => ...and first atom is 'a'} ); is( ref($r->[1]), 'HASH', q{'ab,ac' => ...and second is a node} ); $r = $r->[1]; is( scalar(keys %$r), 2, q{'ab,ac' => ...node has two keys} ); is( join( '' => sort keys %$r ), 'bc', q{'ab,ac' => ...keys are 'b','c'} ); ok( exists $r->{b}, q{'ab,ac' => ... key 'b' exists} ); is( ref($r->{b}), 'ARRAY', q{'ab,ac' => ... and points to a path} ); ok( exists $r->{c}, q{'ab,ac' => ... key 'c' exists} ); is( ref($r->{c}), 'ARRAY', q{'ab,ac' => ... and points to a path} ); } { my $ra = Regexp::Assemble->new; $ra->insert( undef ); is_deeply( $ra->_path, [{'' => undef}], 'insert(undef)' ); } { my $ra = Regexp::Assemble->new; $ra->insert( '' ); is_deeply( $ra->_path, [{'' => undef}], q{insert('')} ); } { my $r = Regexp::Assemble->new; $r->insert(); is_deeply( $r->_path, [{'' => undef}], 'insert()' ); } { my $ra = Regexp::Assemble->new; $ra->insert( '0' ); is_deeply( $ra->_path, [0], q{/0/}, ); } { my $ra = Regexp::Assemble->new; $ra->insert( qw/d/ ); is_deeply( $ra->_path, ['d'], '/d/', ); } { my $r = Regexp::Assemble->new->lex( '\([^(]*(?:\([^)]*\))?[^)]*\)|.' ); $r->reset->add( 'ab(cd)ef' ); is_deeply( $r->_path, [ 'a', 'b', '(cd)', 'e', 'f' ], 'ab(cd)ef (with parenthetical lexer)' ); $r->reset->add( 'ab(cd(ef)gh)ij' ); is_deeply( $r->_path, [ 'a', 'b', '(cd(ef)gh)', 'i', 'j' ], 'ab(cd(ef)gh)ij (with parenthetical lexer)' ); $r->reset->add( 'ab((ef)gh)ij' ); is_deeply( $r->_path, [ 'a', 'b', '((ef)gh)', 'i', 'j' ], 'ab((ef)gh)ij (with parenthetical lexer)' ); $r->reset->add( 'ab(cd(ef))ij' ); is_deeply( $r->_path, [ 'a', 'b', '(cd(ef))', 'i', 'j' ], 'ab(cd(ef))ij (with parenthetical lexer)' ); $r->reset->add( 'ab((ef))ij' ); is_deeply( $r->_path, [ 'a', 'b', '((ef))', 'i', 'j' ], 'ab((ef))ij (with parenthetical lexer)' ); } { my $r = Regexp::Assemble->new(lex => '\\d'); is_deeply( $r->add( '0\Q0C,+' )->_path, [ '0', '0', 'C', ',', '\\+' ], '0\\Q0C,+ with \\d lexer', ); } { my $ra = Regexp::Assemble->new; $ra->insert( qw/d a b/ ); is_deeply( $ra->_path, [qw/d a b/], '/dab/', ); } { my $ra = Regexp::Assemble->new; $ra->insert( qw/0 1/ ); $ra->insert( qw/0 2/ ); is_deeply( $ra->_path, [ '0', { '1' => ['1'], '2' => ['2'], }, ], '/01/ /02/', ); } { my $ra = Regexp::Assemble->new; $ra->insert( qw/0/ ); $ra->insert( qw/0 1/ ); $ra->insert( qw/0 2/ ); is_deeply( $ra->_path, [ '0', { '1' => ['1'], '2' => ['2'], '' => undef, }, ], '/0/ /01/ /02/', ); } { my $ra = Regexp::Assemble->new; $ra->insert( qw/d a m/ ); $ra->insert( qw/d a m/ ); is_deeply( $ra->_path, [ 'd', 'a', 'm', ], '/dam/ x 2', ); } { my $ra = Regexp::Assemble->new; $ra->insert( qw/d a y/ ); $ra->insert( qw/d a/ ); $ra->insert( qw/d a/ ); is_deeply( $ra->_path, [ 'd', 'a', { 'y' => ['y'], '' => undef, }, ], '/day/, /da/ x 2', ); } { my $ra = Regexp::Assemble->new; $ra->insert( qw/d o t/ ); $ra->insert( qw/d o/ ); $ra->insert( qw/d/ ); is_deeply( $ra->_path, [ 'd', { 'o' => [ 'o', { 't' => ['t'], '' => undef, }, ], '' => undef, }, ], '/dot/ /do/ /d/', ); } { my $ra = Regexp::Assemble->new; $ra->insert( qw/b i g/ ); $ra->insert( qw/b i d/ ); is_deeply( $ra->_path, [ 'b', 'i', { 'd' => ['d'], 'g' => ['g'], }, ], '/big/ /bid/', ); } { my $ra = Regexp::Assemble->new; $ra->insert( qw/d a r t/ ); $ra->insert( qw/d a m p/ ); is_deeply( $ra->_path, [ 'd', 'a', { 'r' => ['r', 't'], 'm' => ['m', 'p'], }, ], '/dart/ /damp/', ); } { my $ra = Regexp::Assemble->new; $ra->insert( qw/a m b l e/ ); $ra->insert( qw/i d l e/ ); is_deeply( $ra->_path, [ { 'a' => ['a', 'm', 'b', 'l', 'e'], 'i' => ['i', 'd', 'l', 'e'], }, ], '/amble/ /idle/', ); } { my $ra = Regexp::Assemble->new; $ra->insert( qw/a m b l e/ ); $ra->insert( qw/a m p l e/ ); $ra->insert( qw/i d l e/ ); is_deeply( $ra->_path, [ { 'a' => [ 'a', 'm', { 'b' => [ 'b', 'l', 'e' ], 'p' => [ 'p', 'l', 'e' ], }, ], 'i' => ['i', 'd', 'l', 'e'], }, ], '/amble/ /ample/ /idle/', ); } { my $ra = Regexp::Assemble->new; $ra->insert( qw/d a m/ ); $ra->insert( qw/d a r e/ ); is_deeply( $ra->_path, [ 'd', 'a', { 'm' => ['m'], 'r' => ['r', 'e'], , }, ], '/dam/ /dare/', ); } { my $ra = Regexp::Assemble->new ->insert(qw/d a/) ->insert(qw/d b/) ->insert(qw/d c/) ; is_deeply( $ra->_path, [ 'd', { 'a' => ['a'], 'b' => ['b'], 'c' => ['c'], }, ], '/da/ /db/ /dc/', ); } { my $ra = Regexp::Assemble->new ->insert(qw/d a/) ->insert(qw/d b c d/) ->insert(qw/d c/) ; is_deeply( $ra->_path, [ 'd', { 'a' => ['a'], 'b' => ['b', 'c', 'd'], 'c' => ['c'], }, ], '/da/ /dbcd/ /dc/', ); } sub permute { my $target = shift; my $path = shift; my( $x1, $x2, $x3, $x4, $x5 ); for $x1( 0..4 ) { for $x2( 0..4 ) { next if $x2 == $x1; for $x3( 0..4 ) { next if grep { $_ == $x3 } ($x1, $x2); for $x4( 0..4 ) { next if grep { $_ == $x4 } ($x1, $x2, $x3); for $x5( 0..4 ) { next if grep { $_ == $x5 } ($x1, $x2, $x3, $x4); my $ra = Regexp::Assemble->new ->insert( @{$path->[$x1]} ) ->insert( @{$path->[$x2]} ) ->insert( @{$path->[$x3]} ) ->insert( @{$path->[$x4]} ) ->insert( @{$path->[$x5]} ) ; is_deeply( $ra->_path, $target, '/' . join( '/ /', join( '' => @{$path->[$x1]}), join( '' => @{$path->[$x2]}), join( '' => @{$path->[$x3]}), join( '' => @{$path->[$x4]}), join( '' => @{$path->[$x5]}), ) . '/' ) or diag( $ra->dump(), ' versus ', Regexp::Assemble->_dump($target), "\n", ); } } } } } } permute( [ 'a', { '' => undef, 'b' => [ 'b', { '' => undef, 'c' => [ 'c', { '' => undef, 'd' => [ 'd', { '' => undef, 'e' => [ 'e', ], }, ], }, ], }, ], }, ], [ [ 'a', ], [ 'a', 'b' ], [ 'a', 'b', 'c' ], [ 'a', 'b', 'c', 'd' ], [ 'a', 'b', 'c', 'd', 'e' ], ] ); permute( [ { '' => undef, 'a' => [ 'a', { '' => undef, 'b' => [ 'b', { '' => undef, 'c' => [ 'c', { '' => undef, 'd' => [ 'd', ], }, ], }, ], }, ], }, ], [ [ '', ], [ 'a', ], [ 'a', 'b' ], [ 'a', 'b', 'c' ], [ 'a', 'b', 'c', 'd' ], ] ); permute( [ 'd', 'o', { 'n' => [ 'n', 'a', 't', { 'e' => ['e'], 'i' => ['i', 'o', 'n'], }, ] , 't' => [ 't', { 'a' => ['a', 't', 'e'], 'i' => ['i', 'n', 'g'], }, ], , '' => undef, }], [ [ split //, 'do' ], [ split //, 'donate' ], [ split //, 'donation' ], [ split //, 'dotate' ], [ split //, 'doting' ], ] ); permute( [ 'o', { '' => undef, 'n' => [ 'n', { '' => undef, 'l' => ['l', 'y'], 'e' => [ 'e', { '' => undef, 'r' => ['r'], } ], }, ], }, ], [ [ split //, 'o' ], [ split //, 'on' ], [ split //, 'one' ], [ split //, 'only' ], [ split //, 'oner' ], ], ); permute( [ 'a', 'm', { 'a' => [ 'a', { 's' => ['s', 's'], 'z' => ['z', 'e'], }, ], 'u' => [ 'u', { 'c' => ['c', 'k'], 's' => ['s', 'e'], } ], 'b' => [ 'b', 'l', 'e' ], }, ], [ [ split //, 'amass' ], [ split //, 'amaze' ], [ split //, 'amble' ], [ split //, 'amuck' ], [ split //, 'amuse' ], ], ); Regexp::Assemble::Default_Lexer( '\([^(]*(?:\([^)]*\))?[^)]*\)|.' ); { my $r = Regexp::Assemble->new; $r->reset->add( 'ab(cd)ef' ); is_deeply( $r->_path, [ 'a', 'b', '(cd)', 'e', 'f' ], 'ab(cd)ef (with Default parenthetical lexer)' ) or diag("lex = $r->{lex}"); $r->reset->add( 'ab((ef)gh)ij' ); is_deeply( $r->_path, [ 'a', 'b', '((ef)gh)', 'i', 'j' ], 'ab((ef)gh)ij (with Default parenthetical lexer)' ); $r->reset->add( 'ab(ef(gh))ij' ); is_deeply( $r->_path, [ 'a', 'b', '(ef(gh))', 'i', 'j' ], 'ab(ef(gh))ij (with Default parenthetical lexer)' ); eval { $r->filter('choke') }; ok( $@, 'die on non-CODE filter' ); eval { $r->pre_filter('choke') }; ok( $@, 'die on non-CODE pre_filter' ); } is( $_, $fixed, '$_ has not been altered' ); Regexp-Assemble-0.38/t/02_reduce.t0000644000175000017500000010553111022301341014775 0ustar ronron# 02_reduce.t # # Test suite for Regexp::Assemble # # Test the various tail reductions, e.g. /dab/ /cab/ => /[cd]ab/ # # copyright (C) 2004-2006 David Landgren use strict; use Regexp::Assemble; eval qq{ use Test::More tests => 61 }; if( $@ ) { warn "# Test::More not available, no tests performed\n"; print "1..1\nok 1\n"; exit 0; } my $fixed = 'The scalar remains the same'; $_ = $fixed; my $context = { debug => 0, depth => 0 }; { # ran, reran my $path = ['r']; my $tail = { '' => undef, 'r' => [ 'r', 'e' ] }; my $head = ['n', 'a']; ($head, my $slide, $path) = Regexp::Assemble::_slide_tail( $head, $tail, $path, $context ); is_deeply( $head, ['n', 'a', 'r'], '_slide_tail ran/reran head' ); is_deeply( $slide, { '' => undef, 'e' => ['e', 'r'] }, '_slide_tail ran/reran slide' ); is_deeply( $path, [], '_slide_tail ran/reran path' ); } { # lit, limit my $path = ['i', 'l']; my $tail = { '' => undef, 'i' => [ 'i', 'm' ] }; my $head = ['t']; ($head, my $slide, $path) = Regexp::Assemble::_slide_tail( $head, $tail, $path, $context ); is_deeply( $head, ['t', 'i'], '_slide_tail lit/limit head' ); is_deeply( $slide, { '' => undef, 'm' => ['m', 'i'] }, '_slide_tail lit/limit slide' ); is_deeply( $path, ['l'], '_slide_tail lit/limit path' ); } { # acids/acidoids my $path = ['d', 'i', 'c', 'a']; my $tail = { '' => undef, 'd' => [ 'd', 'i', 'o' ] }; my $head = ['s']; ($head, my $slide, $path) = Regexp::Assemble::_slide_tail( $head, $tail, $path, $context ); is_deeply( $head, ['s', 'd', 'i'], '_slide_tail acids/acidoids head' ); is_deeply( $slide, { '' => undef, 'o' => ['o', 'd', 'i'] }, '_slide_tail acids/acidoids slide' ); is_deeply( $path, ['c', 'a'], '_slide_tail acids/acidoids path' ); } { # 007/00607 my $path = ['0', '0']; my $tail = { '' => undef, '0' => [ '0', '6' ] }; my $head = ['7']; ($head, my $slide, $path) = Regexp::Assemble::_slide_tail( $head, $tail, $path, $context ); is_deeply( $head, ['7', '0'], '_slide_tail 007/00607 head' ); is_deeply( $slide, { '' => undef, '6' => ['6', '0'] }, '_slide_tail 007/00607 slide' ); is_deeply( $path, ['0'], '_slide_tail 007/00607 path' ); } { my $ra = Regexp::Assemble->new; $ra->insert($_) for 0..2; $ra->_reduce; is_deeply( $ra->_path, [ { '0' => ['0'], '1' => ['1'], '2' => ['2'], }, ], '/0/ /1/ /2/', ); } { my $ra = Regexp::Assemble->new ->insert( split //, 'cat' ) ->insert( split //, 'dog' ) ->insert( split //, 'bird' ) ->insert( split //, 'worm' ) ->_reduce; is_deeply( $ra->_path, [ { 'b' => ['b','i','r','d'], 'c' => ['c','a','t'], 'd' => ['d','o','g'], 'w' => ['w','o','r','m'], }, ], '/cat/ /dog/ /bird/ /worm/', ); } { my $ra = Regexp::Assemble->new ->insert( split //, 'proamendment' ) ->insert( split //, 'proappropriation' ) ->insert( split //, 'proapproval' ) ->_reduce ; is_deeply( $ra->_path, [ 'p', 'r', 'o', 'a', { 'm' => ['m','e','n','d','m','e','n','t'], 'p' => ['p','p','r','o', { 'p' => ['p','r','i','a','t','i','o','n'], 'v' => ['v','a','l'], }, ], }, ], '/proamendment/ /proappropriation/ /proapproval/', ); } { my $ra = Regexp::Assemble->new; $ra->insert( 0 ) ->insert( 1 ) ->insert( split //, 10 ) ->insert( split //, 100 ) ->_reduce; is_deeply( $ra->_path, [ { '0' => ['0'], '1' => [ '1', { '' => undef, '0' => [ { '' => undef, '0' => ['0'], }, 0, ], } ], }, ], '/0/ /1/ /10/ /100/', ); } { my $ra = Regexp::Assemble->new ->insert( 'c', 'a', 'b' ) ->insert( 'd', 'a', 'b' ) ->_reduce ; is_deeply( $ra->_path, [ { 'c' => ['c'], 'd' => ['d'], }, 'a', 'b', ], '/cab/ /dab/' ); } { my $ra = Regexp::Assemble->new ->insert( 'c', 'r', 'a', 'b' ) ->insert( 'd', 'a', 'b' ) ->_reduce ; is_deeply( $ra->_path, [ { 'c' => ['c', 'r'], 'd' => ['d'], }, 'a', 'b', ], '/crab/ /dab/' ); } { my $ra = Regexp::Assemble->new ->insert( 'd', 'a', 'b' ) ->insert( 'd', 'a', 'y' ) ->insert( 'd', 'a', 'i', 'l', 'y' ) ->_reduce ; is_deeply( $ra->_path, [ 'd', 'a', { 'b' => ['b'], 'i' => [ { '' => undef, 'i' => ['i', 'l'], }, 'y' ], }, ], '/dab/ /day /daily/' ); } { my $ra = Regexp::Assemble->new ->insert( 'c', 'r', 'a', 'b' ) ->insert( 'd', 'a', 'b' ) ->insert( 'l', 'o', 'b' ) ->_reduce ; is_deeply( $ra->_path, [ { 'c' => [ { 'c' => ['c', 'r'], 'd' => ['d'], }, 'a', ], 'l' => ['l', 'o'], }, 'b', ], '/crab/ /dab/ /lob/' ); } { my $ra = Regexp::Assemble->new ->insert( split //, 'hat' ) ->insert( split //, 'that' ) ->_reduce ; is_deeply( $ra->_path, [ { '' => undef, 't' => ['t'], }, 'h', 'a', 't', ], '/hat/ /that/' ); } { my $ra = Regexp::Assemble->new ->insert( split //, 'treat' ) ->insert( split //, 'threat' ) ->_reduce ; is_deeply( $ra->_path, [ 't', { '' => undef, 'h' => ['h'], }, 'r', 'e', 'a', 't' ], '/treat/ /threat/' ); } { my $ra = Regexp::Assemble->new ->insert( split //, 'treat' ) ->insert( split //, 'threat' ) ->insert( split //, 'eat' ) ->_reduce ; is_deeply( $ra->_path, [ { '' => undef, 't' => [ 't', { '' => undef, 'h' => ['h'], }, 'r', ], }, 'e', 'a', 't' ], '/eat/ /treat/ /threat/' ); } { my $ra = Regexp::Assemble->new ->insert( split //, 'treat' ) ->insert( split //, 'threat' ) ->insert( split //, 'teat' ) ->_reduce ; is_deeply( $ra->_path, [ 't', { '' => undef, 'h' => [ { 'h' => ['h'], '' => undef, }, 'r' ], }, 'e', 'a', 't' ], '/teat/ /treat/ /threat/' ); } { my $ra = Regexp::Assemble->new ->insert( split //, 'grit' ) ->insert( split //, 'lit' ) ->insert( split //, 'limit' ) ->_reduce ; is_deeply( $ra->_path, [ { 'g' => [ 'g', 'r' ], 'l' => [ 'l', { '' => undef, 'i' => ['i', 'm'], }, ], }, 'i', 't' ], '/grit/ /lit/ /limit/', ); } { my $ra = Regexp::Assemble->new ->insert( split //, 'in' ) ->insert( split //, 'ban' ) ->insert( split //, 'ten' ) ->insert( split //, 'tent' ) ->_reduce ; is_deeply( $ra->_path, [ { 'b' => [ { 'i' => ['i'], 'b' => ['b', 'a'], }, 'n', ], 't' => ['t', 'e', 'n', { '' => undef, 't' => ['t'], } ] } ], '/in/ /ban/ /ten/ /tent/', ); } { my $ra = Regexp::Assemble->new ->insert( '' ) ->insert( split //, 'do' ) ->insert( split //, 'don' ) ->_reduce ; is_deeply( $ra->_path, [ { '' => undef, 'd' => [ 'd', 'o', { '' => undef, 'n' => ['n'], }, ], } ], '// /do/ /don/', ); } { my $ra = Regexp::Assemble->new ->insert( split //, 'bf' ) ->insert( split //, 'cdf' ) ->insert( split //, 'cgf' ) ->insert( split //, 'cez' ) ->insert( split //, 'daf' ) ->insert( split //, 'dbf' ) ->insert( split //, 'dcf' ) ->_reduce ; is_deeply( $ra->_path, [ { 'b' => [ { 'b' => ['b'], 'd' => ['d', { 'a'=>['a'], 'b'=>['b'], 'c'=>['c'], }, ], }, 'f', ], 'c' => [ 'c', { 'd' => [ { 'd' => ['d'], 'g' => ['g'], }, 'f', ], 'e' => ['e', 'z'], } ], } ], '/bf/ /cdf/ /cgf/ /cez/ /daf/ /dbf/ /dcf/', ); } { my $ra = Regexp::Assemble->new ->insert( split //, 'kids' ) ->insert( split //, 'acids' ) ->insert( split //, 'acidoids' ) ->_reduce ; is_deeply( $ra->_path, [ { 'k' => [ 'k' ], 'a' => [ 'a', 'c', { '' => undef, 'i' => ['i', 'd', 'o'], }, ], }, 'i', 'd', 's', ], '/kids/ /acids/ /acidoids/', ); } { my $ra = Regexp::Assemble->new ->insert( split //, 'schoolkids' ) ->insert( split //, 'acids' ) ->insert( split //, 'acidoids' ) ->_reduce ; is_deeply( $ra->_path, [ { 's' => [ 's', 'c', 'h', 'o', 'o', 'l', 'k' ], 'a' => [ 'a', 'c', { '' => undef, 'i' => ['i', 'd', 'o'], }, ], }, 'i', 'd', 's', ], '/schoolkids/ /acids/ /acidoids/', ); } { my $ra = Regexp::Assemble->new ->insert( split //, 'skids' ) ->insert( split //, 'kids' ) ->insert( split //, 'acids' ) ->insert( split //, 'acidoids' ) ->_reduce ; is_deeply( $ra->_path, [ { 's' => [ { '' => undef, 's' => ['s'], }, 'k', ], 'a' => [ 'a', 'c', { '' => undef, 'i' => ['i', 'd', 'o'], }, ], }, 'i', 'd', 's', ], '/skids/ /kids/ /acids/ /acidoids/', ); } { my $ra = Regexp::Assemble->new ->insert( split //, 'skids' ) ->insert( split //, 'kids' ) ->insert( split //, 'acids' ) ->insert( split //, 'acidoids' ) ->insert( split //, 'schoolkids' ) ->_reduce ; is_deeply( $ra->_path, [ { 's' => [ { '' => undef, 's' => ['s', { '' => undef, 'c' => ['c', 'h', 'o', 'o', 'l'], } ], }, 'k', ], 'a' => [ 'a', 'c', { '' => undef, 'i' => ['i', 'd', 'o'], }, ], }, 'i', 'd', 's', ], '/skids/ /kids/ /acids/ /acidoids/ /schoolkids/', ); } { my $ra = Regexp::Assemble->new ->insert( split //, 'showeriness' ) ->insert( split //, 'showerless' ) ->insert( split //, 'showiness' ) ->insert( split //, 'showless' ) ->_reduce ; is_deeply( $ra->_path, [ 's', 'h', 'o', 'w', { '' => undef, 'e' => ['e', 'r'], }, { 'i' => ['i', 'n'], 'l' => ['l'], }, 'e', 's', 's' ], '/showeriness/ /showerless/ /showiness/ /showless/', ); } { my $ra = Regexp::Assemble->new ->insert( split //, 'gait' ) ->insert( split //, 'grit' ) ->insert( split //, 'blaze' ) ->_reduce ; is_deeply( $ra->_path, [ { 'b' => ['b', 'l', 'a', 'z', 'e'], 'g' => ['g', { 'a' => ['a'], 'r' => ['r'], }, 'i', 't', ], }, ], '/gait/ /grit/ /blaze/', ); } { my $ra = Regexp::Assemble->new ->insert( split //, 'gait' ) ->insert( split //, 'grit' ) ->insert( split //, 'glaze' ) ->_reduce ; is_deeply( $ra->_path, [ 'g', { 'l' => ['l', 'a', 'z', 'e'], 'a' => [ { 'a' => ['a'], 'r' => ['r'], }, 'i', 't', ], }, ], '/gait/ /grit/ /glaze/', ); } { my $ra = Regexp::Assemble->new ->insert( split //, 'gait' ) ->insert( split //, 'grit' ) ->insert( split //, 'graze' ) ->_reduce ; is_deeply( $ra->_path, [ 'g', { 'r' => ['r', { 'a' => ['a', 'z', 'e'], 'i' => ['i', 't'], }, ], 'a' => ['a', 'i', 't'], }, ], '/gait/ /grit/ /graze/', ); } { my $ra = Regexp::Assemble->new; $ra->{path} = [ 't', { 'a' => ['a'], 'i' => ['i'], }, 'b', ]; my $path = [ 't', { 'a' => ['a'], 'i' => ['i'], }, 's', ]; my $res = $ra->_insert_path( $ra->{path}, 0, $path ); is_deeply( $res, [ 't', { 'a' => ['a'], 'i' => ['i'], }, { 'b' => ['b'], 's' => ['s'], }, ], '_insert_path sit/sat -> bit/bat', ); } { my $ra = Regexp::Assemble->new; $ra->{path} = [ 't', { 'a' => ['a'], 'i' => ['i'], }, { 'b' => ['b'], 's' => ['s'], } ]; my $path = [ 't', { 'a' => ['a'], 'i' => ['i'], }, 'f', ]; my $res = $ra->_insert_path( $ra->{path}, 0, $path ); is_deeply( $res, [ 't', { 'a' => ['a'], 'i' => ['i'], }, { 'b' => ['b'], 'f' => ['f'], 's' => ['s'], }, ], '_insert_path fit/fat -> sit/sat, bit/bat', ); } { my $ra = Regexp::Assemble->new; $ra->{path} = [ 't', { '' => undef, 'a' => ['a'], }, 'e', 'b', ]; my $path = [ 't', { '' => undef, 'a' => ['a'], }, 'e', 's', ]; my $res = $ra->_insert_path( $ra->{path}, 0, $path ); is_deeply( $res, [ 't', { '' => undef, 'a' => ['a'], }, 'e', { 'b' => ['b'], 's' => ['s'], }, ], '_insert_path seat/set -> beat/bet', ); } { my $ra = Regexp::Assemble->new; $ra->{path} = [ 'd', 'i', { '' => undef, 'o' => ['o'], }, 't', 'y', 'd', ]; my $path = [ 'd', 'i', { '' => undef, 'o' => ['o'], }, 't', 'a', 'b', ]; my $res = $ra->_insert_path( $ra->{path}, 0, $path ); is_deeply( $res, [ 'd', 'i', { '' => undef, 'o' => ['o'], }, 't', { 'a' => ['a', 'b'], 'y' => ['y', 'd'], }, ], '_insert_path dio?tyd -> dio?tab', ); } { my $ra = Regexp::Assemble->new; $ra->{path} = [ 'd', 'i', { '' => undef, 'o' => ['o'], }, 't', { 'a' => ['a', 'b'], 'y' => ['y', 'd'], }, ]; my $path = [ 'd', 'i', { '' => undef, 'o' => ['o'], }, 't', 'm', 'x', ]; my $res = $ra->_insert_path( $ra->{path}, 0, $path ); is_deeply( $res, [ 'd', 'i', { '' => undef, 'o' => ['o'], }, 't', { 'a' => ['a', 'b'], 'm' => ['m', 'x'], 'y' => ['y', 'd'], }, ], '_insert_path dio?tmx -> dio?t(ab|yd)', ); } { my $ra = Regexp::Assemble->new; $ra->{path} = [ 'd', 'i', { '' => undef, 'o' => ['o'], }, 't', { 'a' => ['a', 'b'], 'y' => ['y', 'd'], }, ]; my $path = [ 'd', 'i', { '' => undef, 'o' => ['o'], }, 't', 'a', 'x', ]; my $res = $ra->_insert_path( $ra->{path}, 0, $path ); is_deeply( $res, [ 'd', 'i', { '' => undef, 'o' => ['o'], }, 't', { 'a' => ['a', { 'b' => ['b'], 'x' => ['x'], } ], 'y' => ['y', 'd'], }, ], '_insert_path dio?tax -> dio?t(ab|yd)', ); } { my $ra = Regexp::Assemble->new ->insert( split //, 'gait' ) ->insert( split //, 'grit' ) ->insert( split //, 'summit' ) ->insert( split //, 'submit' ) ->_reduce ; is_deeply( $ra->_path, [ { 'g' => ['g', { 'a' => ['a'], 'r' => ['r'], }, ], 's' => [ 's', 'u', { 'b' => ['b'], 'm' => ['m'], }, 'm', ], }, 'i', 't', ], '/gait/ /grit/ /summit/ /submit/', ); } { my $ra = Regexp::Assemble->new ->insert( split //, 'gait' ) ->insert( split //, 'grit' ) ->insert( split //, 'summit' ) ->insert( split //, 'submit' ) ->insert( split //, 'it' ) ->insert( split //, 'emit' ) ->_reduce ; is_deeply( $ra->_path, [ { '' => undef, 'g' => ['g', { 'a' => ['a'], 'r' => ['r'], }, ], 'e' => [ { 'e' => ['e'], 's' => ['s', 'u', { 'b' => ['b'], 'm' => ['m'], }, ], }, 'm', ], }, 'i', 't', ], '/gait/ /grit/ /summit/ /submit/ /it/ /emit/', ); } { my $ra = Regexp::Assemble->new ->insert( split //, 'gait' ) ->insert( split //, 'grit' ) ->insert( split //, 'lit' ) ->insert( split //, 'limit' ) ->_reduce ; is_deeply( $ra->_path, [ { 'g' => ['g', { 'a' => ['a'], 'r' => ['r'], }, ], 'l' => [ 'l', { '' => undef, 'i' => ['i','m'], }, ], }, 'i', 't', ], '/gait/ /grit/ /lit/ /limit/', ); } { my $ra = Regexp::Assemble->new ->insert( split //, 'gait' ) ->insert( split //, 'grit' ) ->insert( split //, 'bait' ) ->insert( split //, 'brit' ) ->_reduce ; is_deeply( $ra->_path, [ { 'b' => ['b'], 'g' => ['g'], }, { 'a' => ['a'], 'r' => ['r'], }, 'i', 't', ], '/gait/ /grit/ /bait/ /brit/', ); } { my $ra = Regexp::Assemble->new ->insert( split //, 'gait' ) ->insert( split //, 'grit' ) ->insert( split //, 'bebait' ) ->insert( split //, 'bait' ) ->insert( split //, 'brit' ) ->_reduce ; is_deeply( $ra->_path, [ { 'b' => ['b', { 'e' => [ { '' => undef, 'e' => ['e','b'], }, 'a', ], 'r' => ['r'], }, ], 'g' => ['g', { 'a' => ['a'], 'r' => ['r'], } ] }, 'i', 't', ], '/gait/ /grit/ /bait/ /bebait/ /brit/', ); } { my $ra = Regexp::Assemble->new ->insert( split //, 'gait' ) ->insert( split //, 'grit' ) ->insert( split //, 'bait' ) ->insert( split //, 'brit' ) ->insert( split //, 'summit' ) ->insert( split //, 'submit' ) ->insert( split //, 'emit' ) ->insert( split //, 'transmit' ) ->_reduce ; is_deeply( $ra->_path, [ { 'b' => [ { 'b' => ['b'], 'g' => ['g'], }, { 'a' => ['a'], 'r' => ['r'], }, ], 'e' => [ { 'e' => ['e'], 's' => ['s','u',{'b'=>['b'],'m'=>['m']}], 't' => ['t','r','a','n','s'], }, 'm', ], }, 'i', 't', ], '/gait/ /grit/ /bait/ /brit/ /emit/ /summit/ /submit/ /transmit/', ); } { my $ra = Regexp::Assemble->new ->insert( split //, 'lit' ) ->insert( split //, 'limit' ) ->insert( split //, 'commit' ) ->insert( split //, 'emit' ) ->insert( split //, 'transmit' ) ->_reduce ; is_deeply( $ra->_path, [ { 'c' => [ { 'c' => ['c','o','m'], 'e' => ['e'], 't' => ['t','r','a','n','s'], }, 'm', ], 'l' => ['l', { '' => undef, 'i' => ['i','m'], }, ], }, 'i', 't', ], '/lit/ /limit/ /emit/ /commit/ /transmit/', ); } { my $ra = Regexp::Assemble->new ->insert( split //, 'apocryphal' ) ->insert( split //, 'apocrustic' ) ->insert( split //, 'apocrenic' ) ->_reduce ; is_deeply( $ra->_path, [ 'a','p','o','c','r', { 'e' => [ { 'e' => ['e', 'n'], 'u' => ['u', 's', 't'], }, 'i','c', ], 'y' => ['y','p','h','a','l'], }, ], '/apocryphal/ /apocrustic/ /apocrenic/', ); } { my @list = qw/ den dent din dint ten tent tin tint /; my $ra = Regexp::Assemble->new; # $ra->insert( split // ) for @list; for my $l (@list) { $ra->insert( split //, $l ) } $ra->_reduce; is_deeply( $ra->_path, [ { 'd' => ['d', { 'e' => [ 'e', 'n', { '' => undef, 't' => ['t'], }, ], 'i' => [ 'i', 'n', { '' => undef, 't' => ['t'], }, ], }, ], 't' => ['t', { 'e' => [ 'e', 'n', { '' => undef, 't' => ['t'], }, ], 'i' => [ 'i', 'n', { '' => undef, 't' => ['t'], }, ], }, ], }, ], join( ' ', map { "/$_/" } @list ), ); } { my @list = qw/ gait git grapefruit grassquit grit guitguit /; my $ra = Regexp::Assemble->new; # $ra->insert( split // ) for @list; for my $l (@list) { $ra->insert( split //, $l ) } $ra->_reduce; is_deeply( $ra->_path, [ 'g', { '' => undef, 'a' => ['a'], 'r' => ['r', { '' => undef, 'a' => ['a', { 'p' => ['p','e','f','r'], 's' => ['s','s','q'], }, 'u', ], }, ], 'u' => [ 'u','i','t','g','u'], }, 'i', 't' ], join( ' ', map { "/$_/" } @list ), ); } { my @list = qw/ gait gambit gaslit giggit git godwit goldtit goodwillit gowkit grapefruit grassquit grit guitguit /; my $ra = Regexp::Assemble->new; # $ra->insert( split // ) for @list; for my $l (@list) { $ra->insert( split //, $l ) } $ra->_reduce; is_deeply( $ra->_path, [ 'g', { 'a' => [ 'a', { '' => undef, 'm' => ['m','b'], 's' => ['s','l'], }, ], 'i' => [ { '' => undef, 'i' => ['i','g','g'], } ], 'o' => [ 'o', { 'd' => ['d','w'], 'l' => ['l','d','t'], 'o' => ['o','d','w','i','l','l'], 'w' => ['w','k'], } ], 'r' => [ 'r', { '' => undef, 'a' => ['a', { 'p' => ['p','e','f','r'], 's' => ['s','s','q'], }, 'u', ], }, ], 'u' => [ 'u','i','t','g','u'], }, 'i', 't' ], join( ' ', map { "/$_/" } @list ), ); } { my @list = qw/ lit limit lid livid /; my $ra = Regexp::Assemble->new; # $ra->insert( split // ) for @list; for my $l (@list) { $ra->insert( split //, $l ) } $ra->_reduce; is_deeply( $ra->_path, [ 'l','i', { 'm' => [ { '' => undef, 'm' => ['m','i'], }, 't' ], 'v' => [ { '' => undef, 'v' => ['v','i'], }, 'd' ], }, ], join( ' ', map { "/$_/" } @list ), ); } { my @list = qw/ theatre metre millimetre /; my $ra = Regexp::Assemble->new; # $ra->insert( split // ) for @list; for my $l (@list) { $ra->insert( split //, $l ) } $ra->_reduce; is_deeply( $ra->_path, [ { 'm' => [ { '' => undef, 'm' => ['m','i','l','l','i'], }, 'm','e', ], 't' => ['t','h','e','a'], }, 't','r','e' ], join( ' ', map { "/$_/" } @list ), ); } { my @list = qw/ sad salad spread/; my $ra = Regexp::Assemble->new; # $ra->insert( split // ) for @list; for my $l (@list) { $ra->insert( split //, $l ) } $ra->_reduce; is_deeply( $ra->_path, [ 's', { 'a' => [ { '' => undef, 'a' => ['a','l'], }, ], 'p' => ['p','r','e'], }, 'a','d', ], join( ' ', map { "/$_/" } @list ), ); } { my @list = qw/ tough trough though thorough /; my $ra = Regexp::Assemble->new; # $ra->insert( split // ) for @list; for my $l (@list) { $ra->insert( split //, $l ) } $ra->_reduce; is_deeply( $ra->_path, [ 't', { '' => undef, 'h' => ['h', { '' => undef, 'o' => ['o','r'], } ], 'r' => ['r'], }, 'o','u','g','h', ], join( ' ', map { "/$_/" } @list ), ); } { my @list = qw/ tough though trough through thorough /; my $ra = Regexp::Assemble->new; # $ra->insert( split // ) for @list; for my $l (@list) { $ra->insert( split //, $l ) } $ra->_reduce; is_deeply( $ra->_path, ['t', { '' => undef, h => [ 'h', { o => [ { '' => undef, o => ['o','r'] } ], r => ['r'], } ], r => ['r'], }, 'o','u','g','h' ], join( ' ', map { "/$_/" } @list ), ); } { my @list = qw/ tit titanate titania titanite titano tite titi titian titien tittie /; my $ra = Regexp::Assemble->new; # $ra->insert( split // ) for @list; for my $l (@list) { $ra->insert( split //, $l ) } $ra->_reduce; is_deeply( $ra->_path, ['t','i','t', { '' => undef, 'a' => [ 'a','n', { 'a' => ['a','t','e'], 'i' => ['i', { 'a' => ['a'], 't' => ['t','e'] } ], 'o' => ['o'] } ], 'i' => [ 'i', { '' => undef, 'a' => [ { 'e' => ['e'], 'a' => ['a'] }, 'n' ] } ], 't' => [ { '' => undef, 't' => ['t','i'] }, 'e' ] } ], join( ' ', map { "/$_/" } @list ), ); } { my $ra = Regexp::Assemble->new; $ra->add( 'dasin' ); $ra->add( 'dosin' ); $ra->add( 'dastin' ); $ra->add( 'dostin' ); $ra->_reduce; is_deeply( $ra->_path, [ 'd', { 'a' =>['a'], 'o' =>['o'], }, 's', { '' => undef, 't' => ['t'], }, 'i', 'n', ], 'dasin/dosin/dastin/dosting' ) or diag ($ra->_path); } is( $_, $fixed, '$_ has not been altered' ); Regexp-Assemble-0.38/t/07_warning.t0000644000175000017500000000353211022301341015176 0ustar ronron# 07_warning.t # # test suite for Regexp::Assemble # Make sure warnings are emitted when asked for # # copyright (C) 2005-2006 David Landgren use constant WARN_TESTS => 6; eval qq{use Test::More tests => WARN_TESTS}; if( $@ ) { warn "# Test::More not available, no tests performed\n"; print "1..1\nok 1\n"; exit 0; } my $have_Test_Warn; BEGIN { $have_Test_Warn = do { eval "use Test::Warn"; $@ ? 0 : 1; }; } use Regexp::Assemble; SKIP: { skip( 'Test::Warn not installed on this system', WARN_TESTS ) unless $have_Test_Warn; my $ra = Regexp::Assemble->new( dup_warn => 1 ) ->add( qw( abc def ghi )); my $rax = Regexp::Assemble->new( dup_warn => 0 ) ->add( qw( abc def ghi )); my $ram = Regexp::Assemble->new->dup_warn ->add( qw( abc def ghi )); warning_is { $rax->add( 'def' ) } { carped => "" }, "do not carp explicit"; SKIP: { skip( "Sub::Uplevel version $Sub::Uplevel::VERSION broken on 5.8.8, 0.13 or better required", 2 ) if $] == 5.008008 and $Sub::Uplevel::VERSION < 0.13; warning_like { $ra->add('def') } qr(duplicate pattern added: /def/ at \S+ line \d+\s*), "carp duplicate pattern, warn from new"; warning_like { $ram->add('abc') } qr(duplicate pattern added: /abc/ at \S+ line \d+\s*), "carp duplicate pattern, warn from method"; } $ra->dup_warn(0); warning_is { $ra->add( 'ghi' ) } { carped => "" }, "do not carp"; $ra->dup_warn(1); my $dup_count = 0; $ra->dup_warn( sub { ++$dup_count } ); $ra->add( 'abc' ); cmp_ok( $dup_count, 'eq', 1, 'dup callback' ); $ra->dup_warn( sub { warn join('-', @{$_[-1]}) } ); $ra->add( 'dup' ); warning_is { $ra->add( 'dup' ) } 'd-u-p', "custom carp duplicate pattern"; } # SKIP Regexp-Assemble-0.38/t/03_str.t0000644000175000017500000006010511547335016014356 0ustar ronron# 03_str.t # # Test suite for Regexp::Assemble # Ensure the the generated patterns seem reasonable. # # copyright (C) 2004-2011 David Landgren use strict; eval qq{use Test::More tests => 210}; if( $@ ) { warn "# Test::More not available, no tests performed\n"; print "1..1\nok 1\n"; exit 0; } use Regexp::Assemble; my $fixed = 'The scalar remains the same'; $_ = $fixed; is( Regexp::Assemble->new->as_string, $Regexp::Assemble::Always_Fail, 'empty' ); for my $test ( [ '(?:)?', [''] ], [ 'd', ['d'] ], [ 'dot', ['d', 'o', 't'] ], [ '[dot]', ['d'], ['o'], ['t'] ], [ 'd?', ['d'], [''] ], [ 'da', ['d', 'a'] ], [ 'da?', ['d', 'a'], ['d'] ], [ '(?:da)?', ['d', 'a'], [''] ], [ '[ad]?', ['d'], [''], ['a'] ], [ '(?:do|a)?', ['d', 'o'], [''], ['a'] ], [ '.', ['x'], ['.'] ], [ '.', ['\033'], ['.'] ], [ '.', ['\\d'], ['\\s'], ['.'] ], [ '.', ['\\d'], ['\\D'] ], [ '.', ['\\s'], ['\\S'] ], [ '.', ['\\w'], ['\\W'] ], [ '.', ['\\w'], ['\\W'], ["\t"] ], [ '\\d', ['\\d'], ['5'] ], [ '\\d', ['\\d'], [5], [7], [0] ], [ '\\d?', ['\\d'], ['5'], [''] ], [ '\\s', ['\\s'], [' '] ], [ '\\s?', ['\\s'], [''] ], [ '[\\dx]', ['\\d'], [5], [7], [0], ['x'] ], [ '[\\d\\s]', ['\\d'], ['\\s'], [5], [7], [0], [' '] ], [ '[.p]', ['\\.'], ['p'] ], [ '\\w', ['\\w'], [5], [1], [0], ['a'], ['_'] ], [ '[*\\d]?', ['\\d'], [''], ['\\*'] ], [ '[\\d^]?', ['\\d'], [''], ['\\^'] ], [ 'a[?@]z', ['a', '@', 'z'], ['a', "\?", 'z'] ], [ '\\+', ['\\+'] ], [ '\\+', [quotemeta('+')] ], [ '[*+]', ['\\+'], ['\\*'] ], [ '[*+]', [quotemeta('+')], [quotemeta('*')] ], [ '[-0z]', ['-'], ['0'], ['z'] ], [ '[-.z]', ['-'], ['\\.'], ['z'] ], [ '[-*+]', ['\\+'], ['-'], ['\\*'] ], [ '[-.]', ['\\.'], ['-'] ], [ '(?:[0z]|^)', ['^'], ['0'], ['z'] ], [ '(?:[-0z]|^)', ['^'], ['0'], ['-'], ['z'] ], [ '(?:[-\\w]|^)', ['^'], ['0'], ['-'], ['z'], ['\\w'] ], [ '(?:[-0]|$)', ['$'], ['0'], ['-'] ], [ '(?:[-0]|$|^)', ['$'], ['0'], ['-'], ['^'] ], [ '\\d', [0], [1], [2], [3], [4], [5], [6], [7], [8], [9] ], [ '[\\dx]', [0], [1], [2], [3], [4], [5], [6], [7], [8], [9], ['x'] ], [ '(?:b[ey])?', ['b', 'e'], [''], ['b', 'y'] ], [ '(?:be|do)?', ['b', 'e'], [''], ['d', 'o'] ], [ '(?:b[ey]|a)?', ['b', 'e'], [''], ['b', 'y'], ['a'] ], [ 'da[by]', [qw(d a b)], [qw(d a y)] ], [ 'da(?:ily|b)', [qw(d a b)], [qw(d a i l y)] ], [ '(?:night|day)', [qw(n i g h t)], [qw(d a y)] ], [ 'da(?:(?:il)?y|b)', [qw(d a b)], [qw(d a y)], [qw(d a i l y)] ], [ 'dab(?:ble)?', [qw(d a b)], [qw(d a b b l e)] ], [ 'd(?:o(?:ne?)?)?', [qw(d)], [qw(d o)], [qw(d o n)], [qw(d o n e)] ], [ '(?:d(?:o(?:ne?)?)?)?', [qw(d)], [qw(d o)], [qw(d o n)], [qw(d o n e)], [''] ], [ 'd(?:o[begnt]|u[bd])', [qw(d o b)], [qw(d o e)], [qw(d o g)], [qw(d o n)], [qw(d o t)], [qw(d u b)], [qw(d u d)] ], [ 'da(?:m[ep]|r[kt])', [qw(d a m p)], [qw(d a m e)], [qw(d a r t)], [qw(d a r k)] ], ) { my $result = shift @$test; my $r = Regexp::Assemble->new; $r->insert(@$_) for @$test; my $args = join( ') (', map {join('', @$_)} @$test ); is( $r->as_string, $result, "insert ($args)") or diag( Regexp::Assemble::_dump([@$test]) ); } my $xism = ($] < 5.013) ? '-xism' : '^'; for my $test ( [ qq'(?$xism:(?:^|m)a)', qw(^a ma) ], [ qq'(?$xism:(?:[mw]|^)a)', qw(^a ma wa) ], [ qq'(?$xism:(?:^|\\^)a)', qw(^a), '\\^a' ], [ qq'(?$xism:(?:^|0)a)', qw(^a 0a) ], [ qq'(?$xism:(?:[m^]|^)a)', qw(^a ma), '\\^a' ], [ qq'(?$xism:(?:ma|^)a)', qw(^a maa) ], [ qq'(?$xism:a.+)', qw(a.+) ], [ qq'(?$xism:b?)', '[b]?' ], [ qq'(?$xism:\\.)', '[.]' ], [ qq'(?$xism:\\.+)', '[.]+' ], [ qq'(?$xism:\\.+)' , '[\\.]+' ], [ qq'(?$xism:\\^+)', '[\\^]+' ], [ qq'(?$xism:%)', '[%]' ], [ qq'(?$xism:%)', '[\\%]' ], [ qq'(?$xism:!)', '[!]' ], [ qq'(?$xism:!)', '[\\!]' ], [ qq'(?$xism:@)', '[@]' ], [ qq'(?$xism:@)', '[\\@]' ], [ qq'(?$xism:a|[bc])', 'a|[bc]' ], [ qq'(?$xism:ad?|[bc])', 'ad?|[bc]' ], [ qq'(?$xism:'.'b(?:$|e))', qw(b$ be) ], [ qq'(?$xism:'.'b(?:[ae]|$))', qw(b$ be ba) ], [ qq'(?$xism:'.'b(?:$|\\$))', qw(b$), 'b\\$' ], [ qq'(?$xism:(?:^a[bc]|de))', qw(^ab ^ac de) ], [ qq'(?$xism:(?i:/))', qw(/), {flags => 'i'} ], [ qq'(?$xism:(?i:(?:^a[bc]|de)))', qw(^ab ^ac de), {flags => 'i'} ], [ qq'(?$xism:(?im:(?:^a[bc]|de)))', qw(^ab ^ac de), {flags => 'im'} ], [ qq'(?$xism:a(?:%[de]|=[bc]))', quotemeta('a%d'), quotemeta('a=b'), quotemeta('a%e'), quotemeta('a=c') ], [ qq'(?$xism:\\^[,:])', quotemeta('^:'), quotemeta('^,') ], [ qq'(?$xism:a[-*=])', quotemeta('a='), quotemeta('a*'), quotemeta('a-') ], [ qq'(?$xism:l(?:im)?it)', qw(lit limit) ], [ qq'(?$xism:a(?:(?:g[qr]|h)w|[de]n|m)z)', qw(amz adnz aenz agrwz agqwz ahwz) ], [ qq'(?$xism:a(?:(?:e(?:[gh]u|ft)|dkt|f)w|(?:(?:ij|g)m|hn)v)z)', qw(adktwz aeftwz aeguwz aehuwz afwz agmvz ahnvz aijmvz) ], [ qq'(?$xism:b(?:d(?:kt?|i)|ckt?)x)', qw(bcktx bckx bdix bdktx bdkx) ], [ qq'(?$xism:d(?:[ln]dr?t|x))', qw(dldrt dndrt dldt dndt dx) ], [ qq'(?$xism:d(?:[ln][dp]t|x))', qw(dldt dndt dlpt dnpt dx) ], [ qq'(?$xism:d(?:[ln][dp][mr]t|x))', qw(dldrt dndrt dldmt dndmt dlprt dnprt dlpmt dnpmt dx) ], [ qq'(?$xism:'.'(?:\(scan|\*mens|\[mail))', '\\*mens', '\\(scan', '\\[mail'], [ qq'(?$xism:a\\[b\\[c)', '\\Qa[b[c' ], [ qq'(?$xism:a\\]b\\]c)', '\\Qa]b]c' ], [ qq'(?$xism:a\\(b\\(c)', '\\Qa(b(c' ], [ qq'(?$xism:a\\)b\\)c)', '\\Qa)b)c' ], [ qq'(?$xism:a[(+[]b)', '\\Qa(b', '\\Qa[b', '\\Qa+b' ], [ qq'(?$xism:a[-+^]b)', '\\Qa^b', '\\Qa-b', '\\Qa+b' ], [ qq'(?$xism:car(?:rot)?)', qw(car carrot), {lookahead => 1} ], [ qq'(?$xism:car[dpt]?)', qw(car cart card carp), {lookahead => 1} ], [ qq'(?$xism:[bc]a[nr]e)', qw(bane bare cane care), {lookahead => 1} ], [ qq'(?$xism:(?=[ru])(?:ref)?use)', qw(refuse use), {lookahead => 1} ], [ qq'(?$xism:(?=[bcd])(?:bird|cat|dog))', qw(bird cat dog), {lookahead => 1} ], [ qq'(?$xism:sea(?=[hs])(?:horse|son))', qw(seahorse season), {lookahead => 1} ], [ qq'(?$xism:car(?:(?=[dr])(?:rot|d))?)', qw(car card carrot), {lookahead => 1} ], [ qq'(?$xism:(?:(?:[hl]o|s?t|ch)o|[bf]a)ked)', qw(looked choked hooked stoked toked baked faked) ], [ qq'(?$xism:(?=[frt])(?:trans|re|f)action)', qw(faction reaction transaction), {lookahead => 1} ], [ qq'(?$xism:c(?=[ao])(?:or(?=[np])(?:pse|n)|ar(?=[de])(?:et|d)))', qw(card caret corn corpse), {lookahead => 1} ], [ qq'(?$xism:car(?:(?=[dipt])(?:[dpt]|i(?=[no])(?:ng|on)))?)', qw(car cart card carp carion caring), {lookahead => 1} ], [ qq'(?$xism:(?=[dfrst])(?:(?=[frt])(?:trans|re|f)a|(?=[ds])(?:dir|s)e)ction)', qw(faction reaction transaction direction section), {lookahead => 1} ], [ qq'(?$xism:car(?=[eir])(?:e(?=[flst])(?:(?=[ls])(?:le)?ss|ful|t)|i(?=[no])(?:ng|on)|r(?=[iy])(?:ied|y)))', qw(caret caress careful careless caring carion carry carried), {lookahead => 1} ], [ qq'(?$xism:(?=[uv])(?:u(?=[nr])(?:n(?=[iprs])(?:(?=[ip])(?:(?:p[or]|impr))?i|(?:sea)?|rea)|r)|v(?=[ei])(?:en(?=[it])(?:trime|i)|i))son)', qw(unimprison unison unpoison unprison unreason unseason unson urson venison ventrimeson vison), {lookahead => 1} ], [ qq'(?$xism:(?:a?bc?)?d)', qw(abcd abd bcd bd d) ], [ qq'(?$xism:(?:a?bc?|c)d)', qw(abcd abd bcd bd cd) ], [ qq'(?$xism:(?:(?:a?bc?)?d|c))', qw(abcd abd bcd bd c d) ], [ qq'(?$xism:(?:(?:a?bc?)?d|cd?))', qw(abcd abd bcd bd c cd d) ], [ qq'(?$xism:(?:(?:ab?|b)c?)?d)', qw(abcd abd acd ad bcd bd d) ], [ qq'(?$xism:(?:(?:ab)?cd?)?e)', qw(abcde abce cde ce e) ], [ qq'(?$xism:(?:(?:(?:ab?|b)c?)?d|c))', qw(abcd abd acd ad bcd bd c d) ], [ qq'(?$xism:(?:(?:(?:ab?|b)c?)?d|cd?))', qw(abcd abd acd ad bcd bd c cd d) ], [ qq'(?$xism:'.'^(?:b?cd?|ab)$)', qw(^ab$ ^bc$ ^bcd$ ^c$ ^cd$) ], [ qq'(?$xism:'.'^(?:(?:ab?c|cd?)e?|e)$)', qw(^abc$ ^abce$ ^ac$ ^ace$ ^c$ ^cd$ ^cde$ ^ce$ ^e$) ], [ qq'(?$xism:'.'^(?:abc|bcd)e?$)', qw(^abc$ ^abce$ ^bcd$ ^bcde$) ], [ qq'(?$xism:'.'^(?:abcdef|bcdefg)h?$)', qw(^abcdef$ ^abcdefh$ ^bcdefg$ ^bcdefgh$) ], [ qq'(?$xism:'.'^(?:bcdefg|abcd)h?$)', qw(^abcd$ ^abcdh$ ^bcdefg$ ^bcdefgh$) ], [ qq'(?$xism:'.'^(?:abcdef|bcd)h?$)', qw(^abcdef$ ^abcdefh$ ^bcd$ ^bcdh$) ], [ qq'(?$xism:'.'^(?:a(?:bcd|cd?)e?|e)$)', qw(^abcd$ ^abcde$ ^ac$ ^acd$ ^acde$ ^ace$ ^e$) ], [ qq'(?$xism:'.'^(?:bcd|cd?)e?$)', qw(^bcd$ ^bcde$ ^c$ ^cd$ ^cde$ ^ce$) ], [ qq'(?$xism:'.'^(?:abc|bc?)(?:de)?$)', qw(^abc$ ^abcde$ ^b$ ^bc$ ^bcde$ ^bde$) ], [ qq'(?$xism:'.'^(?:b(?:cd)?|abd)e?$)', qw(^abd$ ^abde$ ^b$ ^bcd$ ^bcde$ ^be$) ], [ qq'(?$xism:'.'^(?:ad?|bcd)e?$)', qw(^a$ ^ad$ ^ade$ ^ae$ ^bcd$ ^bcde$) ], [ qq'(?$xism:'.'^(?:a(?:bcd|cd?)e?|de)$)', qw(^abcd$ ^abcde$ ^ac$ ^acd$ ^acde$ ^ace$ ^de$) ], [ qq'(?$xism:'.'^(?:a(?:bcde)?|bc?d?e)$)', qw(^a$ ^abcde$ ^bcde$ ^bce$ ^bde$ ^be$) ], [ qq'(?$xism:'.'^(?:a(?:b[cd]?)?|bd?e?f)$)', qw(^a$ ^ab$ ^abc$ ^abd$ ^bdef$ ^bdf$ ^bef$ ^bf$) ], [ qq'(?$xism:'.'^(?:a(?:bc?|dd)?|bd?e?f)$)', qw(^a$ ^ab$ ^abc$ ^add$ ^bdef$ ^bdf$ ^bef$ ^bf$) ], [ qq'(?$xism:'.'^(?:a(?:bc?|de)?|bc?d?f)$)', qw(^a$ ^ab$ ^abc$ ^ade$ ^bcdf$ ^bcf$ ^bdf$ ^bf$) ], [ qq'(?$xism:'.'^(?:a(?:bc?|de)?|cd?e?f)$)', qw(^a$ ^ab$ ^abc$ ^ade$ ^cdef$ ^cdf$ ^cef$ ^cf$) ], [ qq'(?$xism:'.'^(?:a(?:bc?|e)?|bc?de?f)$)', qw(^a$ ^ab$ ^abc$ ^ae$ ^bcdef$ ^bcdf$ ^bdef$ ^bdf$) ], [ qq'(?$xism:'.'^(?:a(?:bc?|e)?|b(?:cd)?e?f)$)', qw(^a$ ^ab$ ^abc$ ^ae$ ^bcdef$ ^bcdf$ ^bef$ ^bf$) ], [ qq'(?$xism:'.'^(?:b(?:cde?|d?e)f|a(?:bc?|e)?)$)', qw(^a$ ^ab$ ^abc$ ^ae$ ^bcdef$ ^bcdf$ ^bdef$ ^bef$) ], [ qq'(?$xism:\\b(?:c[de]|ab)\\b)', qw(ab cd ce), {anchor_word => 1} ], [ qq'(?$xism:\\b(?:c[de]|ab))', qw(ab cd ce), {anchor_word_begin => 1} ], [ qq'(?$xism:'.'^(?:c[de]|ab)$)', qw(ab cd ce), {anchor_line => 1} ], [ qq'(?$xism:(?:c[de]|ab))', qw(ab cd ce), {anchor_line => 0} ], [ qq'(?$xism:'.'(?:c[de]|ab)$)', qw(ab cd ce), {anchor_line_end => 1} ], [ qq'(?$xism:\\A(?:c[de]|ab)\\Z)', qw(ab cd ce), {anchor_string => 1} ], [ qq'(?$xism:(?:c[de]|ab))', qw(ab cd ce), {anchor_string => 0} ], [ qq'(?$xism:x[[:punct:]][yz])', qw(x[[:punct:]]y x[[:punct:]]z) ], ) { my $result = shift @$test; my $param = ref($test->[-1]) eq 'HASH' ? pop @$test : {}; my $r = Regexp::Assemble->new(%$param)->add(@$test); my $args = '(' . join( ') (', @$test ) . ')'; if (keys %$param) { $args .= ' {' . join( ', ', map {"$_ => $param->{$_}"} sort keys %$param) . '}'; } is( $r->re, $result, "add $args") } { my $r = Regexp::Assemble->new->add( 'de' ); my $re = $r->re; is( "$re", qq'(?$xism:de)', 'de' ); my $re2 = $r->re; is( "$re2", qq'(?$xism:de)', 'de again' ); } is( Regexp::Assemble->new->lookahead->add( qw/ car cart card carp carion / )->as_string, 'car(?:(?=[dipt])(?:[dpt]|ion))?', 'lookahead car carp cart card carion' ); is( Regexp::Assemble->new->anchor_word ->add(qw(ab cd ce)) ->as_string, '\\b(?:c[de]|ab)\\b', 'implicit anchor word via method' ); is( Regexp::Assemble->new->anchor_word_end ->add(qw(ab cd ce)) ->as_string, '(?:c[de]|ab)\\b', 'implicit anchor word end via method' ); is( Regexp::Assemble->new->anchor_word(0) ->add(qw(ab cd ce)) ->as_string, '(?:c[de]|ab)', 'no implicit anchor word' ); is( Regexp::Assemble->new( anchor_word => 1 )->anchor_word_end(0) ->add(qw(ab cd ce)) ->as_string, '\\b(?:c[de]|ab)', 'implicit anchor word, no anchor word end' ); is( Regexp::Assemble->new->anchor_word_begin(1) ->add(qw(ab cd ce)) ->as_string, '\\b(?:c[de]|ab)', 'implicit anchor word begin' ); is( Regexp::Assemble->new ->add(qw(ab cd ce)) ->anchor_line ->as_string, '^(?:c[de]|ab)$', 'implicit anchor line via new' ); is( Regexp::Assemble->new ->add(qw(ab cd ce)) ->anchor_line_begin ->as_string, '^(?:c[de]|ab)', 'implicit anchor line via method' ); is( Regexp::Assemble->new->anchor_line_begin->anchor_line(0) ->add(qw(ab cd ce)) ->as_string, '(?:c[de]|ab)', 'no implicit anchor line via method' ); is( Regexp::Assemble->new ->add(qw(ab cd ce)) ->anchor_string ->as_string, '\\A(?:c[de]|ab)\\Z', 'implicit anchor string via method' ); is( Regexp::Assemble->new ->add(qw(ab cd ce)) ->anchor_string_absolute ->as_string, '\\A(?:c[de]|ab)\\z', 'implicit anchor string absolute via method' ); is( Regexp::Assemble->new(anchor_string_absolute => 1) ->add(qw(de df fe)) ->as_string, '\\A(?:d[ef]|fe)\\z', 'implicit anchor string absolute via new' ); is( Regexp::Assemble->new(anchor_string_absolute => 1, anchor_string_begin => 0) ->add(qw(de df)) ->as_string, 'd[ef]\\z', 'anchor string absolute and no anchor_string_begin via new' ); is( Regexp::Assemble->new(anchor_word => 1, anchor_word_end => 0) ->add(qw(ze zf zg)) ->as_string, '\bz[efg]', 'anchor word and no anchor_word_begin via new' ); is( Regexp::Assemble->new(anchor_string_absolute => 0) ->add(qw(de df fe)) ->as_string, '(?:d[ef]|fe)', 'no implicit anchor string absolute via new' ); is( Regexp::Assemble->new ->add(qw(ab cd ce)) ->anchor_word_begin ->anchor_string_end_absolute ->as_string, '\\b(?:c[de]|ab)\\z', 'implicit anchor word begin/string absolute end via method' ); is( Regexp::Assemble->new ->add(qw(ab ad)) ->anchor_string(1) ->anchor_string_end(0) ->as_string, '\\Aa[bd]', 'explicit anchor string/no end via method' ); is( Regexp::Assemble->new ->anchor_string_end ->add(qw(ab ad)) ->as_string, 'a[bd]\\Z', 'anchor string end via method' ); is( Regexp::Assemble->new ->anchor_string_absolute(1) ->add(qw(ab ad)) ->as_string, '\\Aa[bd]\\z', 'anchor string end via method' ); is( Regexp::Assemble->new(anchor_word_begin => 1, anchor_string_end_absolute => 1) ->add(qw(de ad be ef)) ->as_string, '\\b(?:[bd]e|ad|ef)\\z', 'implicit anchor word begin/string absolute end via new' ); is( Regexp::Assemble->new ->add(qw(ab cd ce)) ->anchor_word_begin ->anchor_string_begin ->as_string, '\\b(?:c[de]|ab)', 'implicit anchor word beats string' ); TODO: { use vars '$TODO'; local $TODO = "\\d+ does not absorb digits"; is( Regexp::Assemble->new->add( '5', '\\d+' )->as_string, '\\d+', '\\d+ absorbs single char', ); is( Regexp::Assemble->new->add( '54321', '\\d+' )->as_string, '\\d+', '\\d+ absorbs multiple chars', ); is( Regexp::Assemble->new ->add( qw/ abz acdez a5txz a7z /, 'a\\d+z', 'a\\d+-\\d+z' ) # 5.6.0 kluge ->as_string, 'a(?:b|(?:\d+-)?\d+|5tx|cde)z', 'abz a\\d+z acdez a\\d+-\\d+z a5txz a7z' ); } my $mute = Regexp::Assemble->new->mutable(1); $mute->add( 'dog' ); is( $mute->as_string, 'dog', 'mute dog' ); is( $mute->as_string, 'dog', 'mute dog cached' ); $mute->add( 'dig' ); is( $mute->as_string, 'd(?:ig|og)', 'mute dog' ); my $red = Regexp::Assemble->new->reduce(0); $red->add( 'dog' ); $red->add( 'dig' ); is( $red->as_string, 'd(?:ig|og)', 'mute dig dog' ); $red->add( 'dog' ); is( $red->as_string, 'dog', 'mute dog 2' ); $red->add( 'dig' ); is( $red->as_string, 'dig', 'mute dig 2' ); is( Regexp::Assemble->new->add(qw(ab cd))->as_string(indent => 0), '(?:ab|cd)', 'indent 0' ); is( Regexp::Assemble->new ->add( qw/ dldrt dndrt dldt dndt dx / ) ->as_string(indent => 3), 'd (?: [ln]dr?t |x )' , 'dldrt dndrt dldt dndt dx (indent 3)' ); is( Regexp::Assemble->new( indent => 2 ) ->add( qw/foo bar/ ) ->as_string, '(?: bar |foo )' , 'pretty foo bar' ); is( Regexp::Assemble->new ->indent(2) ->add( qw/food fool bar/ ) ->as_string, '(?: foo[dl] |bar )' , 'pretty food fool bar' ); is( Regexp::Assemble->new ->add( qw/afood afool abar/ ) ->indent(2) ->as_string, 'a (?: foo[dl] |bar )' , 'pretty afood afool abar' ); is( Regexp::Assemble->new ->add( qw/dab dam day/ ) ->as_string(indent => 2), 'da[bmy]', 'pretty dab dam day' ); is( Regexp::Assemble->new(indent => 5) ->add( qw/be bed/ ) ->as_string(indent => 2), 'bed?' , 'pretty be bed' ); is( Regexp::Assemble->new(indent => 5) ->add( qw/b-d b\.d/ ) ->as_string(indent => 2), 'b[-.]d' , 'pretty b-d b\.d' ); is( Regexp::Assemble->new ->add( qw/be bed beg bet / ) ->as_string(indent => 2), 'be[dgt]?' , 'pretty be bed beg bet' ); is( Regexp::Assemble->new ->add( qw/afoodle afoole abarle/ ) ->as_string(indent => 2), 'a (?: food? |bar ) le' , 'pretty afoodle afoole abarle' ); is( Regexp::Assemble->new ->add( qw/afar afoul abate aback/ ) ->as_string(indent => 2), 'a (?: ba (?: ck |te ) |f (?: oul |ar ) )' , 'pretty pretty afar afoul abate aback' ); is( Regexp::Assemble->new ->add( qw/stormboy steamboy saltboy sockboy/ ) ->as_string(indent => 5), 's (?: t (?: ea |or ) m |alt |ock ) boy' , 'pretty stormboy steamboy saltboy sockboy' ); is( Regexp::Assemble->new ->add( qw/stormboy steamboy stormyboy steamyboy saltboy sockboy/ ) ->as_string(indent => 4), 's (?: t (?: ea |or ) my? |alt |ock ) boy' , 'pretty stormboy steamboy stormyboy steamyboy saltboy sockboy' ); is( Regexp::Assemble->new ->add( qw/stormboy steamboy stormyboy steamyboy stormierboy steamierboy saltboy/ ) ->as_string(indent => 1), 's (?: t (?: ea |or ) m (?: ier |y ) ? |alt ) boy' , 'pretty stormboy steamboy stormyboy steamyboy stormierboy steamierboy saltboy' ); is( Regexp::Assemble->new ->add( qw/showerless showeriness showless showiness show shows/ ) ->as_string(indent => 4), 'show (?: (?: (?: er ) ? (?: in |l ) es ) ?s ) ?' , 'pretty showerless showeriness showless showiness show shows' ); is( Regexp::Assemble->new->add( qw/ showerless showeriness showdeless showdeiness showless showiness show shows / )->as_string(indent => 4), 'show (?: (?: (?: de |er ) ? (?: in |l ) es ) ?s ) ?' , 'pretty showerless showeriness showdeless showdeiness showless showiness show shows' ); is( Regexp::Assemble->new->add( qw/ convenient consort concert / )->as_string(indent => 4), 'con (?: (?: ce |so ) r |venien ) t', 'pretty convenient consort concert' ); is( Regexp::Assemble->new->add( qw/ 200.1 202.1 207.4 208.3 213.2 / )->as_string(indent => 4), '2 (?: 0 (?: [02].1 |7.4 |8.3 ) |13.2 )', 'pretty 200.1 202.1 207.4 208.3 213.2' ); is( Regexp::Assemble->new->add( qw/ yammail\.com yanmail\.com yeah\.net yourhghorder\.com yourload\.com / )->as_string(indent => 4), 'y (?: (?: our (?: hghorder |load ) |a[mn]mail ) \.com |eah\.net )' , 'pretty yammail.com yanmail.com yeah.net yourhghorder.com yourload.com' ); is( Regexp::Assemble->new->add( qw/ convenient containment consort concert / )->as_string(indent => 4), 'con (?: (?: tainm |veni ) en | (?: ce |so ) r ) t' , 'pretty convenient containment consort concert' ); is( Regexp::Assemble->new->add( qw/ sat sit bat bit sad sid bad bid / )->as_string(indent => 5), '(?: b (?: a[dt] |i[dt] ) |s (?: a[dt] |i[dt] ) )' , 'pretty sat sit bat bit sad sid bad bid' ); is( Regexp::Assemble->new->add( qw/ commercial\.net compuserve\.com compuserve\.net concentric\.net coolmail\.com coventry\.com cox\.net / )->as_string(indent => 5), 'co (?: m (?: puserve\. (?: com |net ) |mercial\.net ) | (?: olmail |ventry ) \.com | (?: ncentric |x ) \.net )' , 'pretty c*.*' ); is( Regexp::Assemble->new->add( qw/ ambient\.at agilent\.com americanexpress\.com amnestymail\.com amuromail\.com angelfire\.com anya\.com anyi\.com aol\.com aolmail\.com artfiles\.de arcada\.fi att\.net / )->as_string(indent => 5), 'a (?: m (?: (?: (?: nesty |uro ) mail |ericanexpress ) \.com |bient\.at ) | (?: n (?: gelfire |y[ai] ) |o (?: lmai ) ?l |gilent ) \.com |r (?: tfiles\.de |cada\.fi ) |tt\.net )' , 'pretty a*.*' ); is( Regexp::Assemble->new->add( qw/ looked choked hooked stoked toked baked faked / )->as_string(indent => 4), '(?: (?: [hl]o |s?t |ch ) o |[bf]a ) ked' , 'looked choked hooked stoked toked baked faked' ); is( Regexp::Assemble->new->add( qw/ arson bison brickmason caisson comparison crimson diapason disimprison empoison foison foreseason freemason godson grandson impoison imprison jettison lesson liaison mason meson midseason nonperson outreason parson person poison postseason precomparison preseason prison reason recomparison reimprison salesperson samson season stepgrandson stepson stonemason tradesperson treason unison venison vison whoreson / )->as_string(indent => 4), '(?: p (?: r (?: e (?: compari |sea ) |i ) |o (?: stsea |i ) |[ae]r ) |s (?: t (?: ep (?: grand ) ? |onema ) |a (?: lesper |m ) |ea ) | (?: v (?: en ) ? |imp[or] |empo |jett |un ) i |f (?: o (?: resea |i ) |reema ) |re (?: (?: compa |imp ) ri |a ) |m (?: (?: idse ) ?a |e ) |c (?: ompari |ais |rim ) |di (?: simpri |apa ) |g (?: ran |o ) d |tr (?: adesper |ea ) |b (?: rickma |i ) | (?: nonpe |a ) r |l (?: iai |es ) |outrea |whore ) son' , '.*son' ); is( Regexp::Assemble->new->add( qw/ deathweed deerweed deeded detached debauched deboshed detailed defiled deviled defined declined determined declared deminatured debentured deceased decomposed demersed depressed dejected deflected delighted / )->as_string(indent => 2), 'de (?: c (?: (?: ompo |ea ) s |l (?: ar |in ) ) |b (?: (?: auc |os ) h |entur ) |t (?: a (?: ch |il ) |ermin ) |f (?: i[ln] |lect ) |m (?: inatur |ers ) | (?: ligh |jec ) t |e (?: rwe |d ) |athwe |press |vil ) ed', 'indent de.*ed' ); is( $_, $fixed, '$_ has not been altered' ); Regexp-Assemble-0.38/t/08_track.t0000644000175000017500000002230311022504235014642 0ustar ronron# 08_track.t # # Test suite for Regexp::Assemble # Tests to see that tracked patterns behave themselves # # copyright (C) 2004-2007 David Landgren use strict; use constant TESTS => 75; eval qq{use Test::More tests => TESTS + 4}; if( $@ ) { warn "# Test::More not available, no tests performed\n"; print "1..1\nok 1\n"; exit 0; } my $PERL_VERSION_TOO_LOW = ($] < 5.007); my $PERL_VERSION_5_005 = ($] < 5.006); use Regexp::Assemble; my $fixed = 'The scalar remains the same'; $_ = $fixed; my $ra = Regexp::Assemble->new; is_deeply( $ra->mbegin, [], 'mbegin is [] on non-tracked R::A object' ); is_deeply( $ra->mend, [], 'mend is [] on non-tracked R::A object' ); { my $re = Regexp::Assemble->new ->add( 'cat' ) ->add( 'dog' ) ; my $regexp = $re->re; ok( $re->match( 'cat' ), 'match without tracking' ); ok( !defined( $re->match( 'eagle' )), 'match fail without tracking' ); } { my $re = Regexp::Assemble->new->track(1)->add(q(dog)); ok( $re->match('dog'), 're pattern-0 dog match' ); is( $re->source(0), 'dog', 'source is dog' ); $re = Regexp::Assemble->new( track=>1 ) ->add( qw/dog dogged fish fetish flash fresh/ ); $re->add('foolish-\\d+'); ok( $re->match('dog'), 're pattern-1 dog match' ); SKIP: { skip( "matched() is not implemented in this version of perl ($])", 1 ) if $PERL_VERSION_TOO_LOW; cmp_ok( $re->matched, 'eq', 'dog', 're pattern-1 dog matched' ); } ok( $re->match('dogged'), 're pattern-1 dogged match' ); SKIP: { skip( "matched() is not implemented in this version of perl ($])", 1 ) if $PERL_VERSION_TOO_LOW; cmp_ok( $re->matched, 'eq', 'dogged', 're pattern-1 dogged matched' ); } ok( $re->match('fetish'), 're pattern-1 fetish match' ); SKIP: { skip( "matched() is not implemented in this version of perl ($])", 1 ) if $PERL_VERSION_TOO_LOW; cmp_ok( $re->matched, 'eq', 'fetish', 're pattern-1 fetish matched' ); } ok( $re->match('foolish-245'), 're pattern-1 foolish-\\d+ match' ); SKIP: { skip( "matched() is not implemented in this version of perl ($])", 2 ) if $PERL_VERSION_TOO_LOW; cmp_ok( $re->matched, 'eq', 'foolish-\\d+', 're pattern-1 foolish-\\d+ matched' ); is ($re->source, 'foolish-\\d+', 're pattern-1 foolish source'); } ok( !defined($re->match('foolish-')), 're pattern-1 foolish-\\d+ 4' ); ok( !defined($re->source), 're pattern-1 foolish-\\d+ source' ); SKIP: { skip( "matched() is not implemented in this version of perl ($])", 1 ) if $PERL_VERSION_TOO_LOW; ok( !defined($re->matched), 're pattern-1 foolish-\\d+ 5' ); } if ($] < 5.009005) { ok( do {use re 'eval'; 'cat' !~ /$re/}, 're pattern-1 cat <5.10' ); ok( do {use re 'eval'; 'foolish-808' =~ /$re/}, 're pattern-1 foolish-808 <5.10' ); } else { ok( 'cat' !~ /$re/, 're pattern-1 cat 5.10' ); ok( 'foolish-808' =~ /$re/, 're pattern-1 foolish-808 5.10' ); } } { my $re = Regexp::Assemble->new( track=>1 ) ->add( '^a-\\d+$' ) ->add( '^a-\\d+-\\d+$' ); my $str = $re->as_string; SKIP: { skip( "/?{...}/ and \\d+ cause a panic in this version of perl ($])", 2 ) if $PERL_VERSION_5_005; ok( !defined $re->match('foo'), 'match pattern-2 foo' ); ok( defined($re->match('a-22-44')), 'match pattern-2 a-22-44' ); } SKIP: { skip( "/?{...}/ and \\d+ cause a panic in this version of perl ($])", 1 ) if $PERL_VERSION_5_005; cmp_ok( $re->match('a-22-55555'), 'eq', '^a-\\d+-\\d+$', 're pattern-2 a-22-55555' ); } SKIP: { skip( "/?{...}/ and \\d+ cause a panic in this version of perl ($])", 1 ) if $PERL_VERSION_5_005; ok( $re->match('a-000'), 're pattern-2 a-000 match' ); } SKIP: { skip( "matched() is not implemented in this version of perl ($])", 1 ) if $PERL_VERSION_TOO_LOW; cmp_ok( $re->matched, 'eq', '^a-\\d+$', 're pattern-2 a-000 matched' ); } } { my $re = Regexp::Assemble->new( track=>1 ) ->add( '^b-(\\d+)$' ) ->add( '^b-(\\d+)-(\\d+)$' ) ; SKIP: { skip( "/?{...}/ and \\d+ cause a panic in this version of perl ($])", 12 ) if $PERL_VERSION_5_005; ok( !defined $re->match('foo'), 'match pattern-3 foo' ); ok( defined $re->match('b-34-56'), 'match pattern-3 b-34-56' ); cmp_ok( $re->mvar(0), 'eq', 'b-34-56', 'match pattern-3 capture 1' ); cmp_ok( $re->mvar(1), '==', 34, 'match pattern-3 capture 2' ); cmp_ok( $re->mvar(2), '==', 56, 'match pattern-3 capture 3' ); is_deeply( $re->mvar, ['b-34-56', 34, 56], 'match pattern-3 mvar' ); is_deeply( $re->mbegin, [0, 2, 5], 'match pattern-3 mbegin' ); is_deeply( $re->mend, [7, 4, 7], 'match pattern-3 ' ); ok( defined $re->match('b-789'), 'match pattern-3 b-789' ); cmp_ok( $re->mvar(0), 'eq', 'b-789', 'match pattern-3 capture 4' ); cmp_ok( $re->mvar(1), '==', 789, 'match pattern-3 capture 5' ); ok( !defined($re->mvar(2)), 'match pattern-3 undef' ); } } { my $re = Regexp::Assemble->new( track=>1 ) ->add( '^c-(\\d+)$' ) ->add( '^c-(\\w+)$' ) ->add( '^c-([aeiou])-(\\d+)$' ) ; SKIP: { skip( "/?{...}/ and \\d+ cause a panic in this version of perl ($])", 12 ) if $PERL_VERSION_5_005; ok( !defined $re->match('foo'), 'match pattern-4 foo' ); ok( !defined $re->mvar(2), 'match pattern-4 foo novar' ); my $target = 'c-u-350'; ok( defined $re->match($target), "match pattern-4 $target" ); ok( $re->mvar(0) eq $target, 'match pattern-4 capture 1' ); ok( $re->mvar(1) eq 'u', 'match pattern-4 capture 2' ); ok( $re->mvar(2) == 350, 'match pattern-4 capture 3' ); $target = 'c-2048'; ok( defined $re->match($target), "match pattern-4 $target" ); ok( $re->mvar(0) eq $target, 'match pattern-4 capture 4' ); ok( $re->mvar(1) == 2048, 'match pattern-4 capture 5' ); ok( !defined($re->mvar(2)), 'match pattern-4 undef' ); is_deeply( $re->mbegin, [0, undef, undef, 2], 'match pattern-3 mbegin' ); is_deeply( $re->mend, [6, undef, undef, 6, undef], 'match pattern-3 mend' ); } } { my $re = Regexp::Assemble->new( track=>1 ) ->add( '^c-\\d+$' ) ->add( '^c-\\w+$' ) ->add( '^c-[aeiou]-\\d+$' ) ; SKIP: { skip( "/?{...}/ and \\d+ cause a panic in this version of perl ($])", 6 ) if $PERL_VERSION_5_005; ok( !defined $re->match('foo'), 'match pattern-5 foo' ); ok( !defined $re->mvar(2), 'match pattern-4 foo novar' ); my $target = 'c-u-350'; ok( defined $re->match($target), "match pattern-5 $target" ); ok( $re->mvar(0) eq $target, 'match pattern-5' ); ok( !defined $re->mvar(1), 'match pattern-5 no capture 2' ); ok( !defined $re->mvar(2), 'match pattern-5 no capture 3' ); } } { my $re = Regexp::Assemble->new( track=>1 ) ->add( '^cat' ) ->add( '^candle$' ) ->flags( 'i' ) ; SKIP: { skip( "match()/matched() return undef in this version of perl ($])", 8 ) if $PERL_VERSION_5_005; ok( !defined $re->match('foo'), 'not match pattern-6 foo' ); my $target = 'cat'; ok( defined $re->match($target), "match pattern-6 $target" ); cmp_ok( $re->matched, 'eq', '^cat', "match pattern-6 $target re" ); $target = 'CATFOOD'; ok( defined $re->match($target), "match pattern-6 $target" ); cmp_ok( $re->matched, 'eq', '^cat', "match pattern-6 $target re" ); $target = 'candle'; ok( defined $re->match($target), "match pattern-6 $target" ); cmp_ok( $re->matched, 'eq', '^candle$', "match pattern-6 $target re" ); $target = 'Candlestick'; ok( !defined $re->match($target), "match pattern-6 $target" ); } } { my @capture; my $re = Regexp::Assemble->new( track=>1 ) ->add( '^ab-(\d+)-(\d+)' ) ->add( '^ac-(\d+)' ) ->add( '^nothing' ) ->add( '^ad-((\d+)-(\d+))' ) ; SKIP: { skip( "/?{...}/ and \\d+ cause a panic in this version of perl ($])", 15 ) if $PERL_VERSION_5_005; ok( !defined($re->capture), 'match p7 no prior capture' ); ok( defined $re->match('nothing captured'), 'match p7-1' ); is( scalar($re->capture), 0, 'match p7-1 no capture' ); ok( defined $re->match('ac-417 captured'), 'match p7-2' ); @capture = $re->capture; is( scalar(@capture), 1, 'match p7-2 capture' ); is( $capture[0], 417, "match p7-2 value 0 ok" ); ok( defined $re->match('ab-21-17 captured'), 'match p7-3' ); @capture = $re->capture; is( scalar(@capture), 2, 'match p7-3 capture' ); is( $capture[0], 21, "match p7-3 value 0 ok" ); is( $capture[1], 17, "match p7-3 value 1 ok" ); ok( defined $re->match('ad-808-245 captured'), 'match p7-4' ); @capture = $re->capture; is( scalar(@capture), 3, 'match p7-4 capture' ); is( $capture[0], '808-245', "match p7-4 value 0 ok" ); is( $capture[1], 808, "match p7-4 value 1 ok" ); is( $capture[2], 245, "match p7-4 value 2 ok" ); } } cmp_ok( $_, 'eq', $fixed, '$_ has not been altered' ); Regexp-Assemble-0.38/t/00_basic.t0000644000175000017500000006506613122052522014624 0ustar ronron# 00_basic.t # # Test suite for Regexp::Assemble # Make sure the basic stuff works # # The fact that many of these tests access object internals directly # does not constitute a coding recommendation. # # copyright (C) 2004-2007 David Landgren use strict; use warnings; use Test::More tests => 323; use Regexp::Assemble; my $fixed = 'The scalar remains the same'; $_ = $fixed; diag('Testing Regexp::Assemble'); my $rt = Regexp::Assemble->new; ok( defined($rt), 'new() defines something' ); is( ref($rt), 'Regexp::Assemble', 'new() returns a Regexp::Assemble object' ); cmp_ok( length(Regexp::Assemble::Default_Lexer), '>', 0, 'default lexer is something' ); is( ref( $rt->_path ), 'ARRAY', '_path() isa ARRAY' ); is( scalar @{$rt->_path}, 0, '_path() is empty' ); { my $r = Regexp::Assemble->new( chomp => 1 ); is( $r->{chomp}, 1, 'chomp new(1)' ); $r->chomp( 0 ); is( $r->{chomp}, 0, 'chomp(0)' ); $r->chomp(); is( $r->{chomp}, 1, 'chomp()' ); } { my $r = Regexp::Assemble->new( indent => 1 ); is( $r->{indent}, 1, 'indent new(1)' ); $r->indent( 4 ); is( $r->{indent}, 4, 'indent(4)' ); $r->indent(); is( $r->{indent}, 0, 'indent()' ); } { my $r = Regexp::Assemble->new( reduce => 1 ); is( $r->{reduce}, 1, 'reduce new(1)' ); $r->reduce( 0 ); is( $r->{reduce}, 0, 'reduce(0)' ); $r->reduce(); is( $r->{reduce}, 1, 'reduce()' ); } { my $r = Regexp::Assemble->new( mutable => 1 ); is( $r->{mutable}, 1, 'mutable new(1)' ); $r->mutable( 0 ); is( $r->{mutable}, 0, 'mutable(0)' ); $r->mutable(); is( $r->{mutable}, 1, 'mutable()' ); } { my $r = Regexp::Assemble->new( flags => 'i' ); is( $r->{flags}, 'i', 'flags new(i)' ); $r->flags( 'sx' ); is( $r->{flags}, 'sx', 'flags(sx)' ); $r->flags( '' ); is( $r->{flags}, '', q{flags('')} ); $r->flags( 0 ); is( $r->{flags}, '0', 'flags(0)' ); $r->flags(); is( $r->{flags}, '', q{flags()} ); } { my $r = Regexp::Assemble->new( modifiers => 'i' ); is( $r->{flags}, 'i', 'modifiers flags new(i)' ); $r->modifiers( 'sx' ); is( $r->{flags}, 'sx', 'modifiers flags(sx)' ); $r->modifiers( '' ); is( $r->{flags}, '', q{modifiers flags('')} ); $r->modifiers( 0 ); is( $r->{flags}, '0', 'modifiers flags(0)' ); $r->modifiers(); is( $r->{flags}, '', q{modifiers flags()} ); } { my $r = Regexp::Assemble->new( track => 2 ); is( $r->{track}, 2, 'track new(n)' ); $r->track( 0 ); is( $r->{track}, 0, 'track(0)' ); $r->track( 1 ); is( $r->{track}, 1, 'track(1)' ); $r->track( 0 ); is( $r->{track}, 0, 'track(0) 2nd' ); $r->track(); is( $r->{track}, 1, 'track()' ); } { my $r = Regexp::Assemble->new( mutable => 2 ); is( $r->{mutable}, 2, 'mutable new(n)' ); $r->mutable( 0 ); is( $r->{mutable}, 0, 'track(0)' ); } { my $r = Regexp::Assemble->new( reduce => 2 ); is( $r->{reduce}, 2, 'reduce new(n)' ); $r->reduce( 0 ); is( $r->{reduce}, 0, 'reduce(0)' ); } { my $r = Regexp::Assemble->new( pre_filter => sub { undef } ); is( ref($r->{pre_filter}), 'CODE', 'pre_filter new(n)' ); $r->pre_filter( undef ); ok( !defined $r->{pre_filter}, 'pre_filter(0)' ); } { my $r = Regexp::Assemble->new( filter => sub { undef } ); is( ref($r->{filter}), 'CODE', 'filter new(n)' ); $r->filter( undef ); ok( !defined $r->{filter}, 'filter(0)' ); } is( Regexp::Assemble::_node_key( { a => 1, b=>2, c=>3 } ), 'a', '_node_key(1)' ); is( Regexp::Assemble::_node_key( { b => 3, c=>2, z=>1 } ), 'b', '_node_key(2)' ); is( Regexp::Assemble::_node_key( { a => 1, 'a.' => 2, b => 3 } ), 'a', '_node_key(3)' ); is( Regexp::Assemble::_node_key( { '' => undef, a => 1, 'a.' => 2, b => 3 } ), 'a', '_node_key(4)' ); is( Regexp::Assemble::_node_key( { '' => undef, abc => 1, def => 2, g => 3 } ), 'abc', '_node_key(5)' ); is( Regexp::Assemble::_node_offset( [ 'a', 'b', '\\d+', 'e', '\\d' ] ), -1, '_node_offset(1)' ); is( Regexp::Assemble::_node_offset( [ {x => ['x'], '' => undef}, 'a', 'b', '\\d+', 'e', '\\d' ] ), 0, '_node_offset(2)' ); is( Regexp::Assemble::_node_offset( [ 'a', 'b', '\\d+', 'e', {a => 1, b => 2}, 'x', 'y', 'z' ] ), 4, '_node_offset(3)' ); is( Regexp::Assemble::_node_offset( [ { z => 1, x => 2 }, 'b', '\\d+', 'e', {a => 1, b => 2}, 'z' ] ), 0, '_node_offset(4)' ); is( Regexp::Assemble::_node_offset( [ [ 1, 2, 3, {a => ['a'], b=>['b']} ], 'a', { z => 1, x => 2 } ] ), 2, '_node_offset(5)' ); is( Regexp::Assemble::_node_eq( {}, {}), 1, '{} eq {}'); is( Regexp::Assemble::_node_eq( undef, {}), 0, 'undef ne {}'); is( Regexp::Assemble::_node_eq( {}, undef), 0, '{} ne undef'); is( Regexp::Assemble::_node_eq( undef, undef), 0, 'undef ne undef'); is( Regexp::Assemble::_node_eq( [], []), 1, '[] eq []'); is( Regexp::Assemble::_node_eq( [], {}), 0, '[] ne {}'); is( Regexp::Assemble::_node_eq( {}, []), 0, '{} ne []'); is( Regexp::Assemble::_node_eq( [0], [0]), 1, 'eq [0]'); is( Regexp::Assemble::_node_eq([0,1,2],[0,1,2]), 1, 'eq [0,1,2]'); is( Regexp::Assemble::_node_eq([0,1,2],[0,1,3]), '', 'ne [0,1,2]'); is( Regexp::Assemble::_node_eq( [1,2],[0,1,2]), '', 'ne [1,2]'); is( Regexp::Assemble::_node_eq( {'a'=>['a','b']}, {'a'=>['a','b']}, ), 1, 'eq {a}' ); is( Regexp::Assemble::_node_eq( {'a'=>['a','b']}, {'a'=>['a','b'], '' => undef}, ), '', 'ne {a}' ); is( Regexp::Assemble::_node_eq( {'a'=>['a','b'], 'b'=>['b','c']}, {'a'=>['a','b'], 'b'=>['b','c']}, ), 1, 'eq {a,b}' ); is( Regexp::Assemble::_node_eq( {'a'=>['a','b'], 'b'=>['b','c']}, {'a'=>['a','b'], 'b'=>['b','d']}, ), '', 'ne {a,b}' ); is( Regexp::Assemble::_node_eq( [{'a'=>['a','b'], 'b'=>['b','c']}, {'z'=>['z','y'], 'm'=>['m','n']}], [{'a'=>['a','b'], 'b'=>['b','c']}, {'z'=>['z','y'], 'm'=>['m','n']}], ), 1, 'eq {a,b},{z,m}' ); is( Regexp::Assemble::_node_eq( [{'a'=>['a','b'], 'b'=>['b','c']}, {'z'=>['z','y'], 'm'=>['m','n']}], [{'a'=>['a','b'], 'b'=>['b','c']}, {'z'=>['z','y'], 'm'=>['m','n','o']}], ), '', 'ne {a,b},{z,m}' ); is( Regexp::Assemble::_node_eq( {''=>undef, 'a'=>['a','b']}, {''=>undef, 'a'=>['a','b']}, ), 1, '{eq {* a}' ); is( Regexp::Assemble::_node_eq( {''=>undef, 'a'=>['a','b']}, {''=>undef, 'a'=>['a','b','c']}, ), '', '{ne {* a}' ); is( Regexp::Assemble::_node_eq( ['z','\\d+', {'a'=>['a','b']}], ['z','\\d+', {'a'=>['a','b']}], ), 1, 'eq [z \d+ {a}]' ); is( Regexp::Assemble::_node_eq( ['z','\\d+', {'a'=>['a','b'], 'z'=>['z','y','x']}], ['z','\\d+', {'a'=>['a','b'], 'z'=>['z','y','x']}], ), 1, 'eq [z \d+ {a,z}]' ); my $stub = Regexp::Assemble->new; is( Regexp::Assemble::_make_class($stub, qw/ a b c / ), '[abc]', '_make_class a b c' ); is( Regexp::Assemble::_make_class($stub, qw/ a a c / ), '[ac]', '_make_class a a c' ); is( Regexp::Assemble::_make_class($stub, qw/ 0 1 2 / ), '[012]', '_make_class 0 1 2' ); is( Regexp::Assemble::_make_class($stub, qw/ 0 1 2 3 4 5 6 7 8 9 / ), '\\d', '_make_class 0 1 ... 9' ); is( Regexp::Assemble::_make_class($stub, '\\d', '\\D' ), '.', '_make_class \\d \\D' ); is( Regexp::Assemble::_make_class($stub, '\\s', '\\S' ), '.', '_make_class \\s \\S' ); is( Regexp::Assemble::_make_class($stub, '\\w', '\\W' ), '.', '_make_class \\w \\W' ); is( Regexp::Assemble::_make_class($stub, '\\w', '\\d' ), '\\w', '_make_class \\w \\d' ); is( Regexp::Assemble::_make_class($stub, '\\W', '\\D' ), '\\W', '_make_class \\W \\D' ); is( Regexp::Assemble::_make_class($stub, '\\W', '\\d' ), '[\\W\\d]', '_make_class \\W \\d' ); is( Regexp::Assemble::_make_class($stub, '\\d', qw/5 a / ), '[\\da]', '_make_class \\d 5 a' ); is( Regexp::Assemble::_make_class($stub, qw/ a z - / ), '[-az]', '_make_class a z -' ); is( Regexp::Assemble::_make_class($stub, qw/ a z ^ / ), '[az^]', '_make_class a z ^' ); is( Regexp::Assemble::_make_class($stub, qw/ a z ^ - / ), '[-az^]', '_make_class a z ^ -' ); is( Regexp::Assemble::_make_class($stub, '\\.', '\\+' ), '[+.]', '_make_class \\. \\+' ); $stub->fold_meta_pairs(0); is( Regexp::Assemble::_make_class($stub, '\\d', '\\D' ), '[\\D\\d]', '_make_class \\d \\D no fold meta pairs' ); is( Regexp::Assemble::_make_class($stub, '\\s', '\\S' ), '[\\S\\s]', '_make_class \\s \\S no fold meta pairs' ); is( Regexp::Assemble::_make_class($stub, '\\w', '\\W' ), '[\\W\\w]', '_make_class \\w \\W no fold meta pairs' ); $stub->fold_meta_pairs(); is( Regexp::Assemble::_make_class($stub, '\\s', '\\S' ), '.', '_make_class \\s \\S implicit fold_meta_pairs' ); sub xcmp { my $r = Regexp::Assemble->new; is_deeply( $r->_lex( $_[0] ), [ $_[1] ], sprintf( '_lex \\x%02x', ord( $_[1] )) ); } xcmp( '\x20', ' ' ); xcmp( '\x21', '!' ); xcmp( '\x22', '"' ); xcmp( '\x23', '#' ); xcmp( '\x24', '\\$' ); xcmp( '\x25', '%' ); xcmp( '\x26', '&' ); xcmp( '\x27', q{'} ); xcmp( '\x28', '\\(' ); xcmp( '\x29', '\\)' ); xcmp( '\x2a', '\*' ); xcmp( '\x2b', '\+' ); xcmp( '\x2c', ',' ); xcmp( '\x2d', '-' ); xcmp( '\x2e', '\\.' ); xcmp( '\x2f', '\/' ); xcmp( '\x30', '0' ); xcmp( '\x3a', ':' ); xcmp( '\x3b', ';' ); xcmp( '\x3c', '<' ); xcmp( '\x3d', '=' ); xcmp( '\x3e', '>' ); xcmp( '\x3f', '\\?' ); xcmp( '\x40', '\\@' ); xcmp( '\x41', 'A' ); xcmp( '\x5a', 'Z' ); xcmp( '\x5b', '\\[' ); xcmp( '\x5c', '\\\\' ); xcmp( '\x5d', '\\]' ); xcmp( '\x5e', '\\^' ); xcmp( '\x5f', '_' ); xcmp( '\x60', '`' ); xcmp( '\x61', 'a' ); xcmp( '\x7a', 'z' ); xcmp( '\x7b', '\{' ); xcmp( '\x7c', '\|' ); xcmp( '\x7d', '}' ); xcmp( '\x7e', '~' ); xcmp( '\x7f', '' ); sub lcmp { is_deeply( Regexp::Assemble->new->_lex( $_[0] ), [ $_[0] ], "_lex $_[0] source line $_[1]" ); } lcmp( 'X?', __LINE__ ); lcmp( '\\?', __LINE__ ); lcmp( '\\+', __LINE__ ); lcmp( '\\*', __LINE__ ); lcmp( '\\@', __LINE__ ); lcmp( '\\.', __LINE__ ); lcmp( '\\(', __LINE__ ); lcmp( '\\)', __LINE__ ); lcmp( '\\[', __LINE__ ); lcmp( '\\]', __LINE__ ); lcmp( '\\|', __LINE__ ); lcmp( 'X??', __LINE__ ); lcmp( '\\??', __LINE__ ); lcmp( '\\+?', __LINE__ ); lcmp( '\\*?', __LINE__ ); lcmp( '\\@?', __LINE__ ); lcmp( '\\.?', __LINE__ ); lcmp( '\\(?', __LINE__ ); lcmp( '\\)?', __LINE__ ); lcmp( '\\[?', __LINE__ ); lcmp( '\\]?', __LINE__ ); lcmp( '\\|?', __LINE__ ); lcmp( 'X+?', __LINE__ ); lcmp( '\\?+?', __LINE__ ); lcmp( '\\++?', __LINE__ ); lcmp( '\\*+?', __LINE__ ); lcmp( '\\@+?', __LINE__ ); lcmp( '\\.+?', __LINE__ ); lcmp( '\\(+?', __LINE__ ); lcmp( '\\)+?', __LINE__ ); lcmp( '\\[+?', __LINE__ ); lcmp( '\\]+?', __LINE__ ); lcmp( '\\|+?', __LINE__ ); lcmp( 'X{2}', __LINE__ ); lcmp( '\\?{2}', __LINE__ ); lcmp( '\\+{2}', __LINE__ ); lcmp( '\\*{2}', __LINE__ ); lcmp( '\\@{2}', __LINE__ ); lcmp( '\\.{2}', __LINE__ ); lcmp( '\\({2}', __LINE__ ); lcmp( '\\){2}', __LINE__ ); lcmp( '\\[{2}', __LINE__ ); lcmp( '\\]{2}', __LINE__ ); lcmp( '\\|{2}', __LINE__ ); lcmp( 'X{2}?', __LINE__ ); lcmp( '\\?{2}?', __LINE__ ); lcmp( '\\+{2}?', __LINE__ ); lcmp( '\\*{2}?', __LINE__ ); lcmp( '\\@{2}?', __LINE__ ); lcmp( '\\.{2}?', __LINE__ ); lcmp( '\\({2}?', __LINE__ ); lcmp( '\\){2}?', __LINE__ ); lcmp( '\\[{2}?', __LINE__ ); lcmp( '\\]{2}?', __LINE__ ); lcmp( '\\|{2}?', __LINE__ ); lcmp( 'X{2,}', __LINE__ ); lcmp( '\\?{2,}', __LINE__ ); lcmp( '\\+{2,}', __LINE__ ); lcmp( '\\*{2,}', __LINE__ ); lcmp( '\\@{2,}', __LINE__ ); lcmp( '\\.{2,}', __LINE__ ); lcmp( '\\({2,}', __LINE__ ); lcmp( '\\){2,}', __LINE__ ); lcmp( '\\[{2,}', __LINE__ ); lcmp( '\\]{2,}', __LINE__ ); lcmp( '\\|{2,}', __LINE__ ); lcmp( 'X{2,}?', __LINE__ ); lcmp( '\\?{2,}?', __LINE__ ); lcmp( '\\+{2,}?', __LINE__ ); lcmp( '\\*{2,}?', __LINE__ ); lcmp( '\\@{2,}?', __LINE__ ); lcmp( '\\.{2,}?', __LINE__ ); lcmp( '\\({2,}?', __LINE__ ); lcmp( '\\){2,}?', __LINE__ ); lcmp( '\\[{2,}?', __LINE__ ); lcmp( '\\]{2,}?', __LINE__ ); lcmp( '\\|{2,}?', __LINE__ ); lcmp( 'X{2,4}', __LINE__ ); lcmp( '\\?{2,4}', __LINE__ ); lcmp( '\\+{2,4}', __LINE__ ); lcmp( '\\*{2,4}', __LINE__ ); lcmp( '\\@{2,4}', __LINE__ ); lcmp( '\\.{2,4}', __LINE__ ); lcmp( '\\({2,4}', __LINE__ ); lcmp( '\\){2,4}', __LINE__ ); lcmp( '\\[{2,4}', __LINE__ ); lcmp( '\\]{2,4}', __LINE__ ); lcmp( '\\|{2,4}', __LINE__ ); lcmp( 'X{2,4}?', __LINE__ ); lcmp( '\\?{2,4}?', __LINE__ ); lcmp( '\\+{2,4}?', __LINE__ ); lcmp( '\\*{2,4}?', __LINE__ ); lcmp( '\\@{2,4}?', __LINE__ ); lcmp( '\\.{2,4}?', __LINE__ ); lcmp( '\\({2,4}?', __LINE__ ); lcmp( '\\){2,4}?', __LINE__ ); lcmp( '\\[{2,4}?', __LINE__ ); lcmp( '\\]{2,4}?', __LINE__ ); lcmp( '\\|{2,4}?', __LINE__ ); { my $r = Regexp::Assemble->new; is_deeply( Regexp::Assemble->new->_lex( '' ), [], '_lex empty string' ); my $str = 'abc'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ 'a', 'b', 'c' ], "_lex $str",); $str = 'a+b*c?'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ 'a+', 'b*', 'c?' ], "_lex $str", ); $str = '\e\t\cb\cs'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ '\e', '\t', '\cb', '\cs' ], "_lex $str", ); $str = 'a+\\d+'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ 'a+', '\\d+' ], "_lex $str", ); $str = 'a/b'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ 'a', '\\/', 'b' ], "_lex $str", ); $str = 'a+?b*?c??'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ 'a+?', 'b*?', 'c??' ], "_lex $str", ); $str = 'abc[def]g'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ 'a', 'b', 'c', '[def]', 'g' ], "_lex $str", ); $str = '(?:ab)?c[def]+g'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ '(?:ab)?', 'c', '[def]+', 'g' ], "_lex $str", ); $str = '(?:ab)?c[def]{2,7}?g'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ '(?:ab)?', 'c', '[def]{2,7}?', 'g' ], "_lex $str", ); $str = 'abc[def]g(?:hi[jk]lm[no]p)'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ 'a', 'b', 'c', '[def]', 'g', '(?:hi[jk]lm[no]p)' ], "_lex $str", ); $str = 'abc[def]g[,.%\\]$&].\\.$'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ 'a', 'b', 'c', '[def]', 'g', '[,.%\\]$&]', '.', '\\.', '$' ], "_lex $str", ); $str = 'abc[def]g[,.%\\]$&{]{2,4}.\\.$'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ 'a', 'b', 'c', '[def]', 'g', '[,.%\\]$&{]{2,4}', '.', '\\.', '$' ], "_lex $str", ); $str = '\\w+\\d{2,}\\s+?\\w{1,100}?\\cx*'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ '\\w+', '\\d{2,}', '\\s+?', '\\w{1,100}?', '\\cx*' ], "_lex $str", ); $str = '\\012+\\.?\\xae+\\x{dead}\\x{beef}+'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ '\\012+', '\\.?', '\\xae+', '\\x{dead}', '\\x{beef}+' ], "_lex $str", ); $str = '\\012+\\.?\\xae+\\x{dead}\\x{beef}{2,}'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ '\\012+', '\\.?', '\\xae+', '\\x{dead}', '\\x{beef}{2,}' ], "_lex $str", ); $str = '\\c[\\ca\\c]\\N{foo}'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ '\\c[', '\\ca', '\\c]', '\\N{foo}' ], "_lex $str", ); $str = '\\b(?:ab\(cd\)ef)+?(?:ab[cd]+e)*'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ '\\b', '(?:ab\(cd\)ef)+?', '(?:ab[cd]+e)*' ], "_lex $str", ); $str = '\\A[^bc\]\d]+\\Z'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ '\\A', '[^bc\]\d]+', '\\Z' ], "_lex $str", ); $str = 'a\\d+\\w*:[\\d\\s]+.z(?!foo)d'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ 'a', '\\d+', '\\w*', ':', '[\\d\\s]+', '.', 'z', '(?!foo)', 'd' ], "_lex $str", ); $str = '\Qa+b*\Ec?'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ 'a', '\+', 'b', '\*', 'c?' ], "_lex $str", ); $str = 'a\\ub'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ 'a', 'B' ], "_lex $str", ); $str = 'A\\lB'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ 'A', 'b' ], "_lex $str", ); $str = '\\Qx*'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ 'x', '\\*' ], "_lex $str" ); $str = 'a\\Q+x*\\Eb+'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ 'a', '\\+', 'x', '\\*', 'b+' ], "_lex $str" ); $str = 'a\\Q+x*b+'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ 'a', '\\+', 'x', '\\*', 'b', '\\+' ], "_lex $str" ); $str = 'a\\Q\\L\\Ez'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ 'a', 'z' ], "_lex $str" ); $str = 'a\\L\\Q\\Ez'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ 'a', 'z' ], "_lex $str" ); $str = 'a\\L\\Q\\U\\Ez'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ 'a', 'z' ], "_lex $str" ); $str = 'a\\L\\Q\\Uz'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ 'a', 'Z' ], "_lex $str" ); $str = 'a\\Eb'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ 'a', 'b', ], "_lex $str" ); $str = 'a\\LBCD\\Ee'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ 'a', 'b', 'c', 'd', 'e' ], "_lex $str" ); $str = 'f\\LGHI'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ 'f', 'g', 'h', 'i' ], "_lex $str" ); $str = 'a\\Ubcd\\Ee'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ 'a', 'B', 'C', 'D', 'e' ], "_lex $str" ); $str = 'a\\Ub/d\\Ee'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ 'a', 'B', '\\/', 'D', 'e' ], "_lex $str" ); $str = 'f\\Ughi'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ 'f', 'G', 'H', 'I' ], "_lex $str" ); $str = 'f\\Ughi\\LMX'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ 'f', 'G', 'H', 'I', 'm', 'x' ], "_lex $str" ); $str = 'f\\Ughi\\E\\LMX'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ 'f', 'G', 'H', 'I', 'm', 'x' ], "_lex $str" ); $str = 'f\\Ugh\\x20'; is_deeply( Regexp::Assemble->new->_lex( $str ), [ 'f', 'G', 'H', ' ' ], "_lex $str" ); $str = 'a\\Q+x*\\Eb+'; is_deeply( Regexp::Assemble->new->add( $str )->_path, [ 'a', '\\+', 'x', '\\*', 'b+' ], "add $str" ); $str = 'a\\Q+x*b+'; is_deeply( Regexp::Assemble->new->add( $str )->_path, [ 'a', '\\+', 'x', '\\*', 'b', '\\+' ], "add $str" ); my $out; $str = 'X\\LK+L{2,4}M\\EY'; is_deeply( $out = Regexp::Assemble->new->add( $str )->_path, [ 'X', 'k+', 'l{2,4}', 'm', 'Y' ], "add $str" ) or diag("@$out"); $str = 'p\\Q\\L\\Eq'; is_deeply( $out = Regexp::Assemble->new->add( $str )->_path, [ 'p', 'q' ], "add $str" ) or diag("@$out"); $str = 'q\\U\\Qh{7,9}\\Ew'; is_deeply( Regexp::Assemble->new->add( $str )->_path, [ 'q', 'H', '\{', '7', ',', '9', '\}', 'w' ], "add $str" ); $str = 'a\\Ubc\\ldef\\Eg'; is_deeply( Regexp::Assemble->new->add( $str )->_path, [ 'a', 'B', 'C', 'd', 'E', 'F', 'g' ], "add $str" ); $str = 'a\\LBL+\\uxy\\QZ+'; is_deeply( Regexp::Assemble->new->add( $str )->_path, [ 'a', 'b', 'l+', 'X', 'y', 'z', '\+' ], "add $str" ); $str = '\Q^a[b['; is_deeply( Regexp::Assemble->new->add( $str )->_path, [ '\\^', 'a', '\\[', 'b', '\\[' ], "add $str" ); } { my $path; $path = []; is_deeply( $path, Regexp::Assemble::_path_copy($path), '_path_copy([])' ); $path = [0, qw[ab cd ef]]; is_deeply( $path, Regexp::Assemble::_path_copy($path), '_path_copy(0 ab cd ef)' ); $path = {}; is_deeply( $path, Regexp::Assemble::_node_copy($path), '_node_copy({})' ); $path = {'a' => [qw[a bb ccc]], 'b'=>[qw[b cc ddd]]}; is_deeply( $path, Regexp::Assemble::_node_copy($path), '_node_copy({a,b})' ); $path = [ {'c'=>['c','d'],'e'=>['e','f']}, 't', {'d'=>['d','f'],'b'=>['b',0]}, { '' => undef, 'a' => ['a']}, ]; is_deeply( $path, Regexp::Assemble::_path_copy($path), '_path_copy({c,e} t {d,b} {* a}' ); $path = [ [0, 1, 2], ['a','b','c'], ['d',{'e'=>['e','f'],'g'=>['g','h']}], ]; is_deeply( $path, Regexp::Assemble::_path_copy($path), '_path_copy(ab cd ef {* a})' ); } is_deeply( $rt->_path, [], 'path is empty' ); my $context = { debug => 0, depth => 0 }; is_deeply( Regexp::Assemble::_unrev_path( [0, 1], $context), [1, 0], 'path(0,1)' ); is_deeply( Regexp::Assemble::_unrev_path( [qw[ ab cd ef ]], $context), [qw[ ef cd ab ]], 'path(ab,cd,ef)' ); is_deeply( Regexp::Assemble::_unrev_path( Regexp::Assemble::_unrev_path( [qw[ ab cd ef ]], $context), $context), [qw[ ab cd ef ]], 'path(ab,cd,ef) back' ); is_deeply( Regexp::Assemble::_unrev_path( [qw[ ab cd ef \\d+ \\D ghi jkl mno ]], $context), [qw[ mno jkl ghi \\D \\d+ ef cd ab ]], 'path(ab cd...)' ); is_deeply( Regexp::Assemble::_unrev_path( Regexp::Assemble::_unrev_path( [qw[ ab cd ef \\d+ \\D ghi jkl mno ]], $context), $context), [qw[ ab cd ef \\d+ \\D ghi jkl mno ]], 'path(ab cd...) back' ); is_deeply( Regexp::Assemble::_unrev_node( { 0 => [0, 1]}, $context), { 1 => [1, 0]}, 'node(0)' ); is_deeply( Regexp::Assemble::_unrev_node( { 0 => [0, 1], 2 => [2, 0]}, $context), { 1 => [1, 0], 0 => [0, 2]}, 'node(0,2)' ); is_deeply( Regexp::Assemble::_unrev_node( { '' => undef, a => [qw[a b]] }, $context), { '' => undef, b => [qw[b a]] }, 'node(*,a,b)' ); is_deeply( Regexp::Assemble::_unrev_node( { '' => undef, a => [qw[a b]], b => [qw[b c d e f g]] }, $context), { '' => undef, b => [qw[b a]], g => [qw[g f e d c b]] }, 'node(*a,b2)' ); is_deeply( Regexp::Assemble::_unrev_path( [{x => [qw[x 0]], '' => undef }], $context), [{0 => [qw[0 x]], '' => undef }], 'node(* 0)' ); is_deeply( Regexp::Assemble::_unrev_node( { ab => [qw[ab bc]], bc => [qw[bc cd de ef fg gh]], ef => [qw[ef gh ij]] }, $context), { bc => [qw[bc ab]], gh => [qw[gh fg ef de cd bc]], ij => [qw[ij gh ef]] }, 'node(ab,bc,ef)' ); is_deeply( Regexp::Assemble::_unrev_node( {''=>undef,b=>[[{b=>['b'],'b?'=>[{''=>undef,b=>['b']},'a']}],{''=>undef,c=>['c']}]}, $context), {''=>undef,c=>[{''=>undef,c=>['c']},[{a=>['a',{''=>undef,b=>['b']}],b=>['b']}]]}, 'node of (?:(?:ab?|b)c?)?' ); is_deeply( Regexp::Assemble::_unrev_path( [qw[a b], {c=>[qw[c d e]], f=>[qw[f g h]], i=>[qw[i j], {k => [qw[k l m]], n=>[qw[n o p]]}, 'x' ]}], $context), [{e=>[qw[e d c]], h=>[qw[h g f]], x=>['x', {m=>[qw[m l k]], p=>[qw[p o n]]}, qw[j i]]}, qw[b a]], 'path(node(path))'); { my $ra = Regexp::Assemble->new ->add( 'refused' ) ->add( 'fused' ) ->add( 'used' ); $ra->_reduce; ok( eq_set( [keys %{Regexp::Assemble::_lookahead($ra->{path}[0])}], ['f', 'r']), '_lookahead refused/fused/used' ); $ra->reset ->add( 'refused' ) ->add( 'reamused' ) ->add( 'fused' ) ->add( 'amused' ) ->add( 'used' ) ->_reduce; ok( eq_set( [keys %{Regexp::Assemble::_lookahead($ra->{path}[0])}], ['a', 'f', 'r']), '_lookahead reamused/refused/amused/fused/used' ); $ra->reset ->add( 'reran' ) ->add( 'ran' ) ->_reduce; ok( eq_set( [keys %{Regexp::Assemble::_lookahead($ra->{path}[0])}], ['r']), '_lookahead reran/ran' ); $ra->reset ->add( 'cruised' ) ->add( 'bruised' ) ->add( 'hosed' ) ->add( 'gazed' ) ->add( 'used' ) ->_reduce; ok( eq_set( [keys %{Regexp::Assemble::_lookahead($ra->{path}[0])}], ['b', 'c', 'g', 'h', 'u']), '_lookahead cruised/bruised/hosed/gazed/used' ); } is( Regexp::Assemble::_dump( [1, 0, undef] ), '[1 0 *]', 'dump undef' ); is( Regexp::Assemble::_dump( [1, 0, q{ }] ), q{[1 0 ' ']}, 'dump space' ); is( Regexp::Assemble::_dump( {a => ['a', 'b'], b => ['b']} ), '{a=>[a b] b=>[b]}', 'dump node' ); is( Regexp::Assemble::_dump( ['a', chr(7), 'b'] ), '[a \\x07 b]', 'dump pretty' ); is( Regexp::Assemble->new->insert(qw( ))->insert(qw( ))->dump, '[\\x07 {\\x05=>[\\x05] \\x06=>[\\x06]}]', 'dump pretty node' ); is( Regexp::Assemble::_dump( ['a', chr(7), 'b'] ), '[a \\x07 b]', 'dump pretty' ); is( Regexp::Assemble::_combine($stub, '?=', qw/ c a b / ), '(?=[abc])', '_combine c a b' ); is( Regexp::Assemble::_combine($stub, '?=', qw/ c ab de / ), '(?=ab|de|c)', '_combine c ab de' ); is( Regexp::Assemble::_combine($stub, '?=', qw/ in og / ), '(?=in|og)', '_combine in og' ); is( Regexp::Assemble::_combine($stub, '?=', qw/ in og j k l / ), '(?=[jkl]|in|og)', '_combine in og j k l' ); is( Regexp::Assemble::_combine($stub, '?=', qw/ in og 0 1 2 3 4 5 6 7 8 9 / ), '(?=\d|in|og)', '_combine in og 0 1 ... 9' ); is_deeply( Regexp::Assemble::_unrev_path( [{x1 => ['x1', 'z\\d'], '' => undef }], $context), [{'z\\d' => ['z\\d', 'x1'], '' => undef }], 'node(* metachar)' ); is_deeply( Regexp::Assemble::_unrev_path( [{x => ['x', '\\d'], '' => undef }], $context), [{'\\d' => ['\\d', 'x'], '' => undef }], 'node(* metachar) 2' ); is_deeply( Regexp::Assemble::_unrev_path( [qw[ ab cd ef ], {x1 => ['x1', 'y2', 'z\\d'], mx => [qw[mx us ca]] }], $context), [{ 'z\\d' => ['z\\d', 'y2', 'x1'], ca => [qw[ca us mx]]}, qw[ef cd ab]], 'path(node)' ); { my $r = Regexp::Assemble->new; is_deeply( $r->lexstr( 'ab' ), ['a', 'b'], q{lexstr('ab')} ); is_deeply( $r->lexstr( 'a\\,b' ), ['a', ',', 'b'], q{lexstr('a\\,b')} ); } eval { my $ra = Regexp::Assemble->new; $ra->Default_Lexer( qr/\d+/ ); }; like( $@, qr/^Cannot pass a Regexp::Assemble to Default_Lexer at \S+ line \d+/m, 'Default_Lexer die' ); is_deeply( Regexp::Assemble->new->_fastlex('ab+c{2,4}'), ['a', 'b+', 'c{2,4}'], '_fastlex reg plus min-max' ); my $x; is_deeply( $x = Regexp::Assemble->new->_fastlex('\\d+\\s{3,4}?\\Qa+\\E\\lL\\uu\\Ufoo\\E\\Lbar\\x40'), ['\\d+', '\\s{3,4}?', 'a', '\\+', qw(l U F O O b a r @)], '_fastlex backslash' ) or diag("@$x"); is_deeply( $x = Regexp::Assemble->new->_fastlex('\\Q\\L\\Ua+\\E\\Ub?\\Ec'), [qw(a \\+ B? c)], '_fastlex in and out of quotemeta' ) or diag("@$x"); is_deeply( $x = Regexp::Assemble->new->_fastlex('\\A\\a\\e\\f\\r\\n\\t\\Z'), [qw(\\A \\a \\e \\f \\r \\n \\t \\Z)], '_fastlex backslash letter' ) or diag("@$x"); is_deeply( $x = Regexp::Assemble->new->_fastlex('\\cG\\cd\\007*?\\041\\z'), [qw(\\cG \\cD \\cG*? ! \\z)], '_fastlex backslash misc' ) or diag("@$x"); package Regexp::Assemble; my @list = ('a', 'a'); my @out = sort _re_sort @list; package main; is_deeply( [@list], [@out], 'bogus coverage improvements rulez' ); is( $_, $fixed, '$_ has not been altered' ); Regexp-Assemble-0.38/t/09_debug.t0000644000175000017500000002315111547335041014640 0ustar ronron# 09_debug.t # # Test suite for Regexp::Assemble # Exercise the debug parts # # copyright (C) 2006-2011 David Landgren use strict; eval qq{use Test::More tests => 68}; if( $@ ) { warn "# Test::More not available, no tests performed\n"; print "1..1\nok 1\n"; exit 0; } use Regexp::Assemble; my $PERL_VERSION_TOO_HIGH = ($] >= 5.013); my $fixed = 'The scalar remains the same'; $_ = $fixed; { my $r = Regexp::Assemble->new( debug => 15 ); is( $r->{debug}, 15, 'debug new(n)' ); $r->debug( 0 ); is( $r->{debug}, 0, 'debug(0)' ); $r->debug( 4 ); is( $r->{debug}, 4, 'debug(4)' ); $r->debug(); is( $r->{debug}, 0, 'debug()' ); } { my $u = Regexp::Assemble->new(unroll_plus => 1)->debug(4); my $str; $u->add( "[a]", ); $str = $u->as_string; is( $str, 'a', '[a] -> a' ); $u->add( "a+b", 'ac' ); $str = $u->as_string; is( $str, 'a(?:a*b|c)', 'unroll plus a+b ac' ); $u->add( "\\LA+B", "ac" ); $str = $u->as_string; is( $str, 'a(?:a*b|c)', 'unroll plus \\LA+B ac' ); $u->add( '\\Ua+?b', "AC" ); $str = $u->as_string; is( $str, 'A(?:A*?B|C)', 'unroll plus \\Ua+?b AC' ); $u->add( "\\d+d", "\\de" ); $str = $u->as_string; is( $str, '\\d(?:\d*d|e)', 'unroll plus \\d+d \\de' ); $u->add( "\\xab+f", "\\xabg" ); $str = $u->as_string; is( $str, "\xab(?:\xab*f|g)", 'unroll plus \\xab+f \\xabg' ); $u->add( "[a-e]+h", "[a-e]i" ); $str = $u->as_string; is( $str, "[a-e](?:[a-e]*h|i)", 'unroll plus [a-e]+h [a-e]i' ); $u->add( "a+b" ); $str = $u->as_string; is( $str, "a+b", 'reroll a+b' ); $u->add( "a+b", "a+" ); $str = $u->as_string; is( $str, "a+b?", 'reroll a+b?' ); $u->add( "a+?b", "a+?" ); $str = $u->as_string; is( $str, "a+?b?", 'reroll a+?b?' ); $u->add( qw(defused fused used) ); $str = $u->as_string; is( $str, "(?:(?:de)?f)?used", 'big debug block in _insert_path()' ); } { my $str = '\t+b*c?\\x41'; is_deeply( Regexp::Assemble->new->debug(4)->_lex( $str ), [ '\t+', 'b*', 'c?', 'A' ], "_lex $str", ); $str = '\Q['; is_deeply( Regexp::Assemble->new->debug(4)->_lex( $str ), [ '\\[' ], "_lex $str", ); $str = '\Q]'; is_deeply( Regexp::Assemble->new->debug(4)->_lex( $str ), [ '\\]' ], "_lex $str", ); $str = '\Q('; is_deeply( Regexp::Assemble->new->debug(4)->_lex( $str ), [ '\\(' ], "_lex $str", ); $str = '\Q)'; is_deeply( Regexp::Assemble->new->debug(4)->_lex( $str ), [ '\\)' ], "_lex $str", ); $str = '\Qa+b*c?'; is_deeply( Regexp::Assemble->new->debug(4)->_lex( $str ), [ 'a', '\+', 'b', '\*', 'c', '\?' ], "_lex $str", ); $str = 'a\\LBC\\Ude\\Ef\\Qg+'; is_deeply( Regexp::Assemble->new->debug(4)->_lex( $str ), [ 'a', 'b', 'c', 'D', 'E', 'f', 'g', '\\+' ], "_lex $str", ); $str = 'a\\uC'; is_deeply( Regexp::Assemble->new(debug => 4) ->_lex( $str ), [ 'a', 'C' ], "_lex $str", ); $str = '\Q\/?'; is_deeply( Regexp::Assemble->new->debug(4)->_lex( $str ), [ '\/', '\?' ], "_lex $str" ); $str = 'p\\L\\QA+\\EZ'; is_deeply( Regexp::Assemble->new->debug(4)->add( $str )->_path, [ 'p', 'a', '\\+', 'Z' ], "add $str" ); $str = '^\Qa[b['; is_deeply( Regexp::Assemble->new->debug(15)->add( $str )->_path, [ '^', 'a', '\\[', 'b', '\\[' ], "add $str" ); } { my $r = Regexp::Assemble->new->debug(4)->add('\x45'); is_deeply( $r->_path, [ 'E' ], '_lex(\\x45) with debug' ); } { my $ra = Regexp::Assemble->new(debug => 1); $ra->insert( undef ); is_deeply( $ra->_path, [{'' => undef}], 'insert(undef)' ); } { my $r = Regexp::Assemble->new(lex => '\\d'); is_deeply( $r->debug(4)->add( '67abc123def+' )->_path, [ '6', '7', 'abc', '1', '2', '3', 'def+' ], '67abc123def+ with \\d lexer', ); is_deeply( $r->reset->debug(0)->add( '67ab12de+' )->_path, [ '6', '7', 'ab', '1', '2', 'de+' ], '67ab12de+ with \\d lexer', ); } { my $r = Regexp::Assemble->new(lex => '\\d'); is_deeply( $r->debug(4)->add( '67\\Q1a*\\E12jk' )->_path, [ '6', '7', '1', 'a', '\\*', '1', '2', 'jk' ], '67\\Q1a*\\E12jk with \\d lexer', ); } { my $r = Regexp::Assemble->new(lex => '\\d'); is_deeply( $r->debug(4)->add( '67\\Q1a*45k+' )->_path, [ '6', '7', '1', 'a', '\\*', '4', '5', 'k', '\\+' ], '67\\Q1a*45k+ with \\d lexer', ); } { my $r = Regexp::Assemble->new(lex => '\\d'); is_deeply( $r->debug(4)->add( '7\U6a' )->_path, [ '7', '6', 'A' ], '7\\U6a with \\d lexer', ); } { my $r = Regexp::Assemble->new(lex => '\\d'); is_deeply( $r->debug(4)->add( '8\L9C' )->_path, [ '8', '9', 'c' ], '8\\L9C with \\d lexer', ); } { my $r = Regexp::Assemble->new(lex => '\\d'); is_deeply( $r->debug(4)->add( '57\\Q2a+23d+' )->_path, [ '5', '7', '2', 'a', '\\+', '2', '3', 'd', '\\+' ], '57\\Q2a+23d+ with \\d lexer', ); } { my $save = $Regexp::Assemble::Default_Lexer; Regexp::Assemble::Default_Lexer('\\d'); my $r = Regexp::Assemble->new; is_deeply( $r->debug(4)->add( '67\\Uabc\\E123def' )->_path, [ '6', '7', '\\Uabc\\E', '1', '2', '3', 'def' ], '67\Uabc\\E123def with \\d lexer', ); is_deeply( $r->reset->add( '67\\Q(?:a)?\\E123def' )->_path, [ '6', '7', '\\Q(?:a)?\\E', '1', '2', '3', 'def' ], '67\Uabc\\E123def with \\d lexer', ); $Regexp::Assemble::Default_Lexer = $save; } is( Regexp::Assemble->new->debug(1)->add( qw/ 0\.0 0\.2 0\.7 0\.01 0\.003 / )->as_string(indent => 4), '0\. (?: 0 (?: 03 |1 ) ? |[27] )' , 'pretty 0.0 0.2 0.7 0.01 0.003' ); { my $ra = Regexp::Assemble->new->debug(3); is( $ra->add( qw/ dog darkness doggerel dark / )->as_string, 'd(?:ark(?:ness)?|og(?:gerel)?)' ); is( $ra->add( qw/ limit lit / )->as_string, 'l(?:im)?it' ); is( $ra->add( qw/ seafood seahorse sea / )->as_string, 'sea(?:horse|food)?' ); is( $ra->add( qw/ bird cat dog elephant fox / )->as_string, '(?:(?:elephan|ca)t|bird|dog|fox)' ); is( $ra->add( qw/ bit bat sit sat fit fat / )->as_string, '[bfs][ai]t' ); is( $ra->add( qw/ split splat slit slat flat flit / )->as_string, '(?:sp?|f)l[ai]t' ); is( $ra->add( qw/bcktx bckx bdix bdktx bdkx/ ) ->as_string, 'b(?:d(?:kt?|i)|ckt?)x', 'bcktx bckx bdix bdktx bdkx' ); is( $ra->add( qw/gait grit wait writ /)->as_string, '[gw][ar]it' ); is( $ra->add( qw/gait grit lit limit /)->as_string, '(?:l(?:im)?|g[ar])it' ); is( $ra->add( qw/bait brit frit gait grit tait wait writ /)->as_string, '(?:[bgw][ar]|fr|ta)it' ); is( $ra->add( qw/schoolkids acids acidoids/ )->as_string, '(?:ac(?:ido)?|schoolk)ids' ); is( $ra->add( qw/schoolkids acidoids/ )->as_string, '(?:schoolk|acido)ids' ); is( $ra->add( qw/nonschoolkids nonacidoids/ )->as_string, 'non(?:schoolk|acido)ids' ); is( $ra->add( qw/schoolkids skids acids acidoids/ )->as_string, '(?:s(?:chool)?k|ac(?:ido)?)ids' ); is( $ra->add( qw/kids schoolkids skids acids acidoids/ )->as_string, '(?:(?:s(?:chool)?)?k|ac(?:ido)?)ids' ); is( $ra->add( qw(abcd abd acd ad bcd bd d) )->as_string, '(?:(?:ab?|b)c?)?d', 'abcd abd acd ad bcd bd d', 'indentical nodes in sub_path/insert_node(bifurc)'); is( $ra->add( qw(^a$ ^ab$ ^abc$ ^abd$ ^bdef$ ^bdf$ ^bef$ ^bf$) )->as_string, '^(?:a(?:b[cd]?)?|bd?e?f)$', 'fused node'); is( $ra->add(qw[bait brit frit gait grit tait wait writ])->as_string, '(?:[bgw][ar]|fr|ta)it', 'after _insert_path()'); is( $ra->add(qw(0 1 10 100))->as_string, '(?:1(?:0?0)?|0)', '_scan_node slid' ); is( $ra->add( qw(abcd abd bcd bd d) )->as_string, '(?:a?bc?)?d', 'abcd abd bcd bd d' ); } SKIP: { skip("perl version too recent ($]), 5.012+ max", 2) if $PERL_VERSION_TOO_HIGH; { my $r = Regexp::Assemble->new->debug(8)->add(qw(this that)); my $re = $r->re; is( $re, '(?-xism:th(?:at|is))', 'time debug' ); } { my $r = Regexp::Assemble->new->add(qw(this that))->debug(8)->add('those'); my $re = $r->re; is( $re, '(?-xism:th(?:ose|at|is))', 'deferred time debug' ); } } { my $r = Regexp::Assemble->new->debug(8)->add(qw(this that those)); # sabotage delete $r->{_begin_time}; is( $r->as_string, 'th(?:ose|at|is)', 'time debug mangle' ); # use internal time() instead of Time::HiRes delete $r->{_time_func}; $r->{_use_time_hires} = 'more sabotage'; $r->reset->add(qw(abc ac)); is( $r->as_string, 'ab?c', 'internal time debug' ); } is_deeply( Regexp::Assemble->new->debug(4)->_fastlex('ab+c{2,4}'), ['a', 'b+', 'c{2,4}'], '_fastlex reg plus min-max' ); my $x; is_deeply( $x = Regexp::Assemble->new->debug(4)->_fastlex('\\d+\\s{3,4}?\\Qa+\\E\\lL\\uu\\Ufo\\E\\Lba\\x40'), ['\\d+', '\\s{3,4}?', 'a', '\\+', qw(l U F O b a @)], '_fastlex backslash' ) or diag("@$x"); is_deeply( Regexp::Assemble->new->debug(4)->_fastlex('\\Q\\L\\Ua+\\E\\Ub?\\Ec'), [qw(a \\+ B? c)], '_fastlex in and out of quotemeta' ); is_deeply( $x = Regexp::Assemble->new->debug(4)->_fastlex('\\bw[0-5]*\\\\(?:x|y){,5}?\\'), [qw(\\b w [0-5]* \\\\), '(?:x|y){,5}?'], '_fastlex more metachars' ) or diag("@$x"); is_deeply( $x = Regexp::Assemble->new(debug => 4)->_fastlex('\\cG\\007'), [qw(\\cG \\cG)], '_fastlex backslash misc' ) or diag("@$x"); is( $_, $fixed, '$_ has not been altered' ); Regexp-Assemble-0.38/t/10_perl514.t0000644000175000017500000000130211547335050014730 0ustar ronron# 10_perl514.t # # Test suite for Regexp::Assemble # Exercise regular expressions beyond perl 5.12 # # copyright (C) 2011 David Landgren use strict; use Test::More; if ($] < 5.013) { plan skip_all => 'Irrelevant below perl <= 5.12'; } else { plan tests => 3; } use Regexp::Assemble; my $fixed = 'The scalar remains the same'; $_ = $fixed; { my $r = Regexp::Assemble->new->debug(8)->add(qw(this that)); my $re = $r->re; is( $re, '(?^:th(?:at|is))', 'time debug' ); } { my $r = Regexp::Assemble->new->add(qw(this that))->debug(8)->add('those'); my $re = $r->re; is( $re, '(?^:th(?:ose|at|is))', 'deferred time debug' ); } is( $_, $fixed, '$_ has not been altered' ); Regexp-Assemble-0.38/t/05_hostmatch.t0000644000175000017500000002517012564001205015533 0ustar ronron# 05_hostmatch.t # # Test suite for Regexp::Assemble # Test a mini-application that you can build with Regexp::Assemble # # copyright (C) 2004-2007 David Landgren use strict; use Regexp::Assemble; use constant file_testcount => 3; # tests requiring Test::File::Contents eval qq{use Test::More tests => 22 + file_testcount}; if( $@ ) { warn "# Test::More not available, no tests performed\n"; print "1..1\nok 1\n"; exit 0; } use constant NR_GOOD => 45; use constant NR_BAD => 529; use constant NR_ERROR => 0; my $fixed = 'The scalar remains the same'; $_ = $fixed; my $have_Test_File_Contents = do { eval { require Test::File::Contents; import Test::File::Contents }; $@ ? 0 : 1; }; my @re = ; # ordinarily we could have just chomp the array after having slurped # , but that would be no fun. # insert them all into an R::A object, chomping the lines my $ra = Regexp::Assemble->new->chomp(1)->add( @re ); is( ref($ra), 'Regexp::Assemble', 'have a Regexp::Assemble object' ); # now map each RE into its compiled form @re = map { chomp; qr/$_/ } @re; ok( open(GOOD, '>t/good.out'), "can open t/good.out for output" ) or print "# $!\n"; ok( open(BAD, '>t/bad.out'), "can open t/bad.out for output" ) or print "# $!\n"; ok( open(ERROR, '>t/error.out'), "can open t/error.out for output" ) or print "# $!\n"; my( $good, $bad, $error ) = (0, 0, 0); END { if( !$error ) { unlink $_ for qw{ t/good.out t/bad.out t/error.out }; } } ok( open(IN, 'examples/hostmatch/source.in'), "can open examples/hostmatch/source.in" ) or print "# $!\n"; while( defined( my $rec = )) { chomp $rec; if( $rec =~ /^$ra$/ ) { my $seen = 0; my $re; for $re (@re) { if( $rec =~ /^$re$/ ) { print BAD "$rec\n"; ++$bad; ++$seen; last; } } if( not $seen ) { print ERROR "$rec\n"; ++$error; } } else { my $seen = 0; my $re; for $re (@re) { if( $rec =~ /^$re$/ ) { print ERROR "$rec\n"; ++$error; ++$seen; last; } } if( not $seen ) { print GOOD "$rec\n"; ++$good; } } } close GOOD; close BAD; close ERROR; is( NR_GOOD, $good, NR_GOOD. ' good records not matched' ); is( NR_BAD, $bad, NR_BAD. ' bad records matched' ); is( NR_ERROR, $error, NR_ERROR. ' records in error' ); is( NR_GOOD+NR_BAD+NR_ERROR, $., "$. total records" ); SKIP: { skip( 'Test::File::Contents not installed on this system', file_testcount ) unless $have_Test_File_Contents; my $file; for $file( qw/good bad error/ ) { file_contents_identical( "t/$file.out", "examples/hostmatch/$file.canonical", "saw expected $file output" ); } } # SKIP { my $r = Regexp::Assemble->new; $r->add_file('examples/file.1')->add_file('examples/file.2'); is( $r->as_string, '(?:b(?:l(?:ea|o)|[eo]a)t|s[aiou]ng)', q{add_file('file.1'), add_file('file.2')}, 'add_file() 2 calls' ); is( Regexp::Assemble->new->chomp->add_file( qw[examples/file.1 examples/file.2] ) ->as_string, '(?:b(?:l(?:ea|o)|[eo]a)t|s[aiou]ng)', 'add_file() multiple files' ); is( Regexp::Assemble->new->chomp->add_file({ file => [qw[examples/file.1 examples/file.2]] }) ->as_string, '(?:b(?:l(?:ea|o)|[eo]a)t|s[aiou]ng)', 'add_file() alternate interface' ); my $str = Regexp::Assemble->new ->add_file({ file => ['examples/file.4'], rs => '/', }) ->as_string; is( $str, '(?:(?:do|pi)g|c(?:at|ow)|hen)', 'add_file with explicit record separator' ); is( Regexp::Assemble->new( rs => '/' ) ->add_file({ file => ['examples/file.4'] }) ->as_string, $str, 'add_file hashref with record separator specified in new()' ); is( Regexp::Assemble->new ->add_file({ file => 'examples/file.4', input_record_separator => '/', }) ->as_string, $str, 'add_file hashref with record separator specified in new()' ); is( Regexp::Assemble->new( rs => '/' ) ->add_file('examples/file.4') ->as_string, $str, 'add_file with record separator specified in new()' ); is( Regexp::Assemble->new( file => 'examples/file.4', input_record_separator => '/', ) ->as_string, $str, 'new() file and custom record separator' ); { local $/ = undef; my $raw_contents = 'cat/dog/cow/pig/hen'; is( Regexp::Assemble->new ->add_file({file => 'examples/file.4'}) ->as_string, $raw_contents, 'add_file with no record separator' ); is( Regexp::Assemble->new(file => 'examples/file.4')->as_string, $raw_contents, 'new() file and no record separator' ); } eval { my $r = Regexp::Assemble->new( file => '/does/not/exist' ) }; is( substr($@,0,38), q{cannot open /does/not/exist for input:}, 'file does not exist for new()' ); SKIP: { skip( 'ignore DOS line-ending tests on Win32', 1 ) if $^O =~ /^MSWin32/; is( Regexp::Assemble->new->chomp->add_file({ file => [qw[examples/file.3]], rs => "\r\n", }) ->as_string, '(?:e[ns]|i[ls])', 'add_file() with DOS line endings' ); } } is( $_, $fixed, '$_ has not been altered' ); __DATA__ m\d+-\d+-\d+-\d+\.andorpac\.ad de\d+\.alshamil\.net\.ae \d+-\d+-\d+-\d+\.fibertel\.com\.ar ol\d+-\d+\.fibertel\.com\.ar host\d+\.\d+\.\d+\.\d+\.ifxnw\.com\.ar int-\d+-\d+-\d+-\d+\.movi\.com\.ar host-\d+\.\d+\.\d+\.\d+-ta\.adsl\.netizen\.com\.ar dsl-\d+-\d+-\d+-\d+\.users\.telpin\.com\.ar \d+-\d+-\d+-\d+\.bbt\.net\.ar \d+-\d+-\d+-\d+\.prima\.net\.ar \d+-\d+-\d+-\d+\.cab\.prima\.net\.ar \d+-\d+-\d+-\d+\.dsl\.prima\.net\.ar \d+-\d+-\d+-\d+\.dup\.prima\.net\.ar \d+-\d+-\d+-\d+\.dup\.prima\.net\.ar \d+-\d+-\d+-\d+\.wll\.prima\.net\.ar host\d+\.\d+-\d+-\d+\.telecom\.net\.ar chello\d+\.\d+\.sc-graz\.chello\.at \d+-\d+-\d+-\d+\.dynamic\.home\.xdsl-line\.inode\.at \d+-\d+-\d+-\d+\.paris-lodron\.xdsl-line\.inode\.at h\d+\.dyn\.cm\.kabsi\.at h\d+\.med\.cm\.kabsi\.at h\d+\.moe\.cm\.kabsi\.at cm\d+-\d+\.liwest\.at \d+-\d+-\d+-\d+\.pircher\.at \d+-\d+-\d+-\d+\.dyn\.salzburg-online\.at chello\d+\.\d+\.graz\.surfer\.at chello\d+\.\d+\.klafu\.surfer\.at chello\d+\.tirol\.surfer\.at chello\d+\.\d+\.\d+\.vie\.surfer\.at d\d+-\d+-\d+-\d+\.cust\.tele\d+\.at m\d+p\d+\.adsl\.highway\.telekom\.at n\d+p\d+\.adsl\.highway\.telekom\.at l\d+p\d+\.dipool\.highway\.telekom\.at chello\d+\.\d+\.\d+\.univie\.teleweb\.at chello\d+\.\d+\.\d+\.wu-wien\.teleweb\.at dsl-linz\d+-\d+-\d+\.utaonline\.at dialup-\d+\.syd\.ar\.com\.au dialup-\d+\.\d+\.\d+\.\d+\.acc\d+-ball-lis\.comindico\.com\.au dialup-\d+\.\d+\.\d+\.\d+\.acc\d+-mcmi-dwn\.comindico\.com\.au dsl-\d+\.\d+\.\d+\.\d+\.dsl\.comindico\.com\.au \d+-\d+-\d+-\d+\.netspeed\.com\.au blaax\d+-a\d+\.dialup\.optusnet\.com\.au chtax\d+-\d+\.dialup\.optusnet\.com\.au lonax\d+-b\d+\.dialup\.optusnet\.com\.au rohax\d+-\d+\.dialup\.optusnet\.com\.au wayax\d+-\d+\.dialup\.optusnet\.com\.au winax\d+-\d+\.dialup\.optusnet\.com\.au wooax\d+-b\d+\.dialup\.optusnet\.com\.au d\d+-\d+-\d+-\d+\.dsl\.nsw\.optusnet\.com\.au c\d+-\d+-\d+-\d+\.eburwd\d+\.vic\.optusnet\.com\.au c\d+-\d+-\d+-\d+\.lowrp\d+\.vic\.optusnet\.com\.au \d+\.fip-\d+\.permisdn\.ozemail\.com\.au \d+-\d+-\d+-\d+-bri-ts\d+-\d+\.tpgi\.com\.au \d+-\d+-\d+-\d+-vic-pppoe\.tpgi\.com\.au \d+-\d+-\d+-\d+\.tpgi\.com\.au dar-\d+k-\d+\.tpgi\.com\.au sou-ts\d+-\d+-\d+\.tpgi\.com\.au ains-\d+-\d+-\d+-\d+\.ains\.net\.au cpe-\d+-\d+-\d+-\d+\.nsw\.bigpond\.net\.au cpe-\d+-\d+-\d+-\d+\.qld\.bigpond\.net\.au cpe-\d+-\d+-\d+-\d+\.sa\.bigpond\.net\.au cpe-\d+-\d+-\d+-\d+\.vic\.bigpond\.net\.au cpe-\d+-\d+-\d+-\d+\.wa\.bigpond\.net\.au ppp-\d+\.cust\d+-\d+-\d+\.ghr\.chariot\.net\.au adsl-\d+\.cust\d+-\d+-\d+\.qld\.chariot\.net\.au \d+-\d+-\d+-\d+\.dyn\.iinet\.net\.au \d+\.a\.\d+\.mel\.iprimus\.net\.au \d+\.b\.\d+\.pth\.iprimus\.net\.au \d+\.a\.\d+\.sop\.iprimus\.net\.au r\d+-\d+-\d+-\d+\.cpe\.unwired\.net\.au dial-\d+\.\d+\.\d+\.\d+\.cotas\.com\.bo \d+-dial-user-ecp\.acessonet\.com\.br \d+-\d+-\d+-\d+\.corp\.ajato\.com\.br \d+\.\d+\.\d+\.\d+\.user\.ajato\.com\.br \d+-\d+-\d+-\d+\.user\.ajato\.com\.br \d+\.\d+\.\d+\.\d+\.user\.ajato\.com\.br cm-net-cwb-c[\da-f]+\.brdterra\.com\.br cm-net-poa-c[\da-f]+\.brdterra\.com\.br cm-tvcidade-rec-c[\da-f]+\.brdterra\.com\.br cm-tvcidade-ssa-c[\da-f]+\.brdterra\.com\.br cm-virtua-fln-c[\da-f]+\.brdterra\.com\.br cm-virtua-poa-c[\da-f]+\.brdterra\.com\.br net-\d+-\d+\.cable\.cpunet\.com\.br \d+-\d+-\d+\.xdsl-dinamico\.ctbcnetsuper\.com\.br \d+-\d+-\d+\.xdsl-fixo\.ctbcnetsuper\.com\.br dl-nas\d+-poa-c[\da-f]+\.dialterra\.com\.br \d+-\d+-\d+-\d+\.brt\.dialuol\.com\.br \d+-\d+-\d+-\d+\.tlf\.dialuol\.com\.br \d+-\d+-\d+-\d+\.tlm\.dialuol\.com\.br \d+-\d+-\d+-\d+\.rev\.easyband\.com\.br max-\d+-\d+-\d+\.nwnet\.com\.br \d+-\d+-\d+-\d+\.papalegua\.com\.br adsl\d+c\d+\.sercomtel\.com\.br \d+\.user\.veloxzone\.com\.br \d+\.virtua\.com\.br \d+\.bhz\.virtua\.com\.br [\da-f]+\.bhz\.virtua\.com\.br [\da-f]+\.rjo\.virtua\.com\.br [\da-f]+\.soc\.virtua\.com\.br [\da-f]+\.virtua\.com\.br \d+\.rjo\.virtua\.com\.br bhe\d+\.res-com\.wayinternet\.com\.br \d+-\d+-\d+-\d+\.mganm\d+\.dial\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.pmjce\d+\.dial\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.pnisir\d+\.dial\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.pvoce\d+\.dial\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.sance\d+\.dial\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.bnut\d+\.dsl\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.bsace\d+\.dsl\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.cbabm\d+\.dsl\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.cpece\d+\.dsl\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.cslce\d+\.dsl\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.ctame\d+\.dsl\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.gnace\d+\.dsl\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.jvece\d+\.dsl\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.nhoce\d+\.dsl\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.paemt\d+\.dsl\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.pltce\d+\.dsl\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.pvoce\d+\.dsl\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.smace\d+\.dsl\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.smace\d+\.e\.brasiltelecom\.net\.br \d+-\d+-\d+-\d+\.dialdata\.net\.br \d+\.\d+\.\d+\.\d+\.dialup\.gvt\.net\.br \d+\.\d+\.\d+\.\d+\.tbprof\.gvt\.net\.br \d+-\d+-\d+-\d+\.customer\.telesp\.net\.br \d+-\d+-\d+-\d+\.dial-up\.telesp\.net\.br \d+-\d+-\d+-\d+\.dsl\.telesp\.net\.br Regexp-Assemble-0.38/xt/0000755000175000017500000000000013122055201013227 5ustar ronronRegexp-Assemble-0.38/xt/author/0000755000175000017500000000000013122055201014531 5ustar ronronRegexp-Assemble-0.38/xt/author/pod.t0000644000175000017500000000020412563765707015527 0ustar ronronuse Test::More; eval "use Test::Pod 1.45"; plan skip_all => "Test::Pod 1.45 required for testing POD" if $@; all_pod_files_ok(); Regexp-Assemble-0.38/xt/author/pod-coverage.t0000644000175000017500000000023513122052522017274 0ustar ronronuse strict; use warnings; use Test::Pod::Coverage 1.08; use Pod::Coverage::TrustPod; all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' }); Regexp-Assemble-0.38/Changes0000644000175000017500000005163513122055101014100 0ustar ronronRevision history for Perl extension Regexp::Assemble. 0.38 2017-06-20T08:51:00 - Fix test prereqs; pod tests moved to xt (RT#122136, RT#122137) Many thanx to Karen Etheridge for these patches. Note: I (Ron) have no idea where the version 2.07 originally comes from, although I have seen it before. It was not in the very first distro I got my hands on. Anyway, I've reverted Karen's patch to 0.38 to match the current sequence of version #s. Apart from that, all these fine improvements are hers. If this version # causes difficulties, I'll just bump it to 2.08. - Adopt new repo structure. For details, see http://savage.net.au/Ron/html/My.Workflow.for.Building.Distros.html. Specifically: o Delete MANIFEST and META.yml, and hereafter auto-generate them. o Modernize .gitignore and MANIFEST.SKIP. o The code says Perl licence but the LICENCE file says Artistic, so replace LICENCE file with LICENSE (so spelled), which says Perl. 0.37 2016-04-18T08:51:00 - No code changes. - Accept pull request from monsieurp to add a LICENCE (sic, see below) file. With thanx. This activity is part of the CPAN PR Challenge 2016. - Update MANIFEST to include LICENCE file. - Remove unicode characters from Changes and Changelog.ini files. - Add TODO and update MANIFEST to note unicode issues. - Add .gitignore to MANIFEST.SKIP. 0.36 2015-08-16T11:34:00 - Ron Savage is now co-maint. - Move eg/ to examples/. - Many thanx to the various parties who logged issues on RT. Some have been fixed, see below. - Add examples/failure.01.pl, downloaded, and noted in docs, from https://rt.cpan.org/Public/Bug/Display.html?id=104897 - Move pod tests into xt/author/pod.t by cutting them out of t/00_basic.t. See https://rt.cpan.org/Public/Bug/Display.html?id=85686 and https://rt.cpan.org/Public/Bug/Display.html?id=85209 - Add repository https://github.com/ronsavage/Regexp-Assemble.git. Note: github does not list Perl as one of the licence options, so the auto-generated LICENSE (sic) file is not included in the distro. See https://rt.cpan.org/Public/Bug/Display.html?id=103856. - Fix some spelling errors in the pod. See https://rt.cpan.org/Public/Bug/Display.html?id=84336 - Move ./Assemble.pm into lib/Regexp/. - Move the contents of the TODO file into the docs, and delete that file. - Rearrange pod, but not be running this module over it :-). Actually, put pod at end of file. - Update Makefile.PL. - Add Changelog.ini. - Update MANIFEST.SKIP. 0.35 2011-04-07 13:18:48 UTC - Update test suite to take into account the regexp engine changes for 5.14. No functional differences. 0.34 2008-06-17 20:20:14 UTC - Rewrite the usage of _re_sort() in order to deal with blead change #33874. Bug smoked out by Andreas Konig. 0.33 2008-06-07 14:40:57 UTC - Tweaked _fastlex() to fix bug #36399 spotted by Yves Blusseau ('a|[bc]' becomes 'a\|[bc]'). - Recognise POSIX character classes (e.g. [[:alpha:]]. Bug also spotted by Yves Blusseau (bug #36465). 0.32 2007-07-30 17:47:39 UTC - Backed out the change introduced in 0.25 (that created slimmer regexps when custom flags are used). As things stood, it meant that '/' could not appear in a pattern with flags (and could possibly dump core). Bug #28554 noted by David Morel. - Allow a+b to be unrolled into aa*b, as that may allow further reductions (bug #20847 noted by Philippe Bruhat). Not completely implemented, but bug #28554 is sufficient to push out a new release. - eg/assemble understands -U to enable plus unrollings. - Extended campaign of coverage improvements made to the test suite caught a minor flaw in source(). 0.31 2007-06-04 20:40:33 UTC - Add a fold_meta_pairs flag to control the behaviour of [\S\s] (and [\D\d], [\W\w]) being folded to '.' (bug #24171 spotted by Philippe Bruhat). 0.30 2007-05-18 15:39:37 UTC - Fixup _fastlex() bug in 5.6 (unable to discriminate \cX). This allows bug #27138 to be closed. 0.29 2007-05-17 10:48:42 UTC - Tracked patterns enhanced to take advantage of 5.10 (and works again with blead). - The mutable() functionality has been marked as deprecated. - mailing list web page was incorrect (noted by Kai Carver) 0.28 2006-11-26 21:49:26 UTC - Fixed a.+ bug (interpreted as a\.+) (bug #23623) - Handle /[a]/ => /a/ 0.27 2006-11-01 23:43:35 UTC - rewrote the lexing of patterns in _fastlex(). Unfortunately this doesn't speed things up as much as I had hoped. - eg/assemble now recognises -T to dump timing statistics. - file parameter in add_file() may accept a single scalar (or a list, as before). - rs parameter in new() was not recognised as an alias for input_record_separator, - anchor_string_absolute as a parameter to new() would not have worked correctly. - a couple of anchor_() methods would not have worked correctly. - Added MANIFEST.SKIP, now that the module is under version control. - Broke out the debug tests into a separate file (t/09_debug.t). - cmp_ok() tests that tested equality were replaced by is(). - tests in t/03_str.t transformed to a data-driven approach, in order to slim down the size of the distribution tarball. - Typo spotted in the documentation by Stephan (bug #20425). 0.26 2006-07-12 09:27:51 UTC - Incorporated a patch to the test suite from barbie, to work around a problem encountered on Win32 (bug #17507). - The "match nothing" pattern was incorrect (but so obscure as to be reasonably safe). - Removed the unguarded tests in t/06_general.t that the Test::More workaround in 0.24 skips. - Newer versions of Sub::Uplevel no longer need to be guarded against in t/07_warning.t. 0.25 2006-04-20 18:04:49 - Added a debug switch to elapsed pattern insertion and pattern reduction times. Upgraded eg/assemble to make use of it. - Tweaked the resulting pattern when it uses 'imsx' flags, giving (?i-xsm:(?:^a[bc]|de)) instead of (?-xism:(?i:(?:^a[bc]|de))) . - Changed the "match nothing" pattern to something slightly less unsurprising to those who peek behind the curtain. Reported by Philippe Bruhat (bug #18266). - Tweaked the dump() output for chars \x00 .. \x1f 0.24 2006-03-21 08:50:42 - Added an add_file() method that allows a file of patterns to be slurped into an object. Makes for less make-work code in the client code (and thus one less thing to go wrong there). - Added anchor methods that tack on \b, ^, $ and the like to an assembled pattern. - Rewrote new() and clone(). The latter is now no longer needs to know the attribute names. - _lex_stateful() subsumed into _lex() - \d and \w assemble to \w instead of [\w\d] (and similarly for \D and \W). - The Test::More workaround stated in the 0.23 changes didn't actually make it into t/06_general.t - Rewrote tests in 06_general.t to use like()/unlike() instead of ok(), and some more ok()'s replaced by cmp_ok() elsewhere. - Diagnostics for t/00_basic.t:xcmp was incorrect (displayed first param instead of second). - Guard against broken Sub::Uplevel in t/07_warning.t for perl 5.8.8. - Pretty-print characters [\x00-\x1f] in _dump() routines. - Spell-checked the POD! 0.23 2006-01-03 17:03:35 - More bugs in the reduction code shaken out by examining powersets. Exhaustive testing (iterating through the powerset of a, b, c, d, e) makes me think that the pathological cases are taken care of. The code is horrible, though, a rewrite is next on the agenda. - Guard against earlier buggy versions of Test::More (0.47) in t/06_general.t - Carp::croak rewritten as Carp::croak() to fix failures noted on blead. - Rewrote _re_path() for speed. - added lexstr() routine. - added eg/stress-test program. 0.22 2005-12-02 11:31:42 UTC - Amended the test suite to ensure that it runsh0orrectly under 5.005_04. (The documentation was updated to reflect the limitations). Sbastien Aperghis-Tramoni provided the impetus for this fix. No other changes in functionality. - The SKIP counts in t/06_general.t were out of whack for 5.6 and 5.005 testing. 0.21 2005-11-26 16:16:06 UTC - Fixed a nasty bug after generating a series of lists of patterns using Data::PowerSet: ^abc$ ^abcd$ ^ac$ ^acd$ ^b$ ^bc$ ^bcd$ ^bd$ would produce the incorrect ^b(?:(?:ab?)?c)?d?$ pattern. It should if fact produce the ^(?:ab?c|bc?)d?$ pattern. - Improve the reduction of, for example, 'sing', 'singing', 'sting'. In prior versions this would produce s(?:ing(?:ing)?|ting), now it produces s(?:(?:ing)?|t)ing. The code is a bit horrendous (especially the part at the end of _reduce_path). And it's still not perfect. See the TODO. - Duplicate pattern detection wasn't quite right. The code was lacking an else clause, which meant 'abcdef' followed by 'abc' would have the latter treated as a duplicate. - Now that there's a statistic that keeps track of when a duplicate input pattern was encountered, it becomes possible to let the user know about it. Two possibilities are available: a simple carp(), or a callback for complete control. The first time I tried this out on a real file of 3558 patterns, it found 9 dups (or rather, 8 dups and a bug in the module). - The above improvement means the test suite now requires Test::Warn. As a result, t/07_pod.t was subsumed into t/00_basic.t and t/07_warning.t was born. - Added an eg/ircwatcher script that demonstrates how to set up a dispatch table on a tracked regular expression. Credit to David Rigaudiere for the idea. - Made sure all routines use an explicit return when it makes sense to do so. (I have a tendency to use implicit returns, which is evil). - the Carp module is require'ed on an on-demand basis. - eg/naive updated to bring its idea of $Single_Char in line with Assemble.pm. - Cleaned up typos and PODos in the documentation. Fixed minor typo noted by David Rigaudiere. - Reworked as_string() and re() to play nicely with Devel::Cover, but alas, the module no longer runs under D::C at all. Something to do with the overloading of "" for re()? 0.20 2005-11-07 18:03:32 UTC - Fixed long-standing indent bug: $ra->add( 'a\.b' )->add( 'a-b' )->as_string(indent=>2) ... would produce a(?:\.|-b) instead of a[-.]b. - Fixed bug ($ and ^ not treated correctly). See RT ticket #15522. Basically, '^a' and 'ma' produced [m^]a instead of (?:^|m)a - Statistics! See the stats_* methods. - eg/assemble now has an -s switch to display these statistics - Minor tweak to t/02_reduce.t to get it to play nicely with Devel::Cover. - t/02_reduce.t had an unnecessary use Data::Dumper. 0.19 2005-11-02 15:16:16 UTC - Change croaking diagnostic concerning Default_Lexer. Bug spotted by barbie in ticket #15044. - Pointer to C in the documentation. - Excised Test::Deep probe in 00_basic.t, since the module is no longer used. - Detabbed eg/* 0.18 2005-10-08 20:37:53 UTC - Fixed '\Q[' to be as treated as '\[' instead of '['. What's more, the tests had this as the Right Thing. What was I thinking? Wound up rewriting _lex_stateful in a much less hairier way, even though it now uses gotos. - Introduced a context hash for dragging around the bits and pieces required by the descent into _reduce_path. It doesn't really help much right now, but is vital for solving the qw(be by my me) => /[bm][ey]/ problem. See TODO for more notes. - Fixed the debug output to play nicely with the test harness (by prefixing everything with a #). It had never been a problem, but you never know. - Added a script named 'debugging' to help people figure out why assembled patterns go wonky (which is invariably due to nested parentheses). - Added a script 'tld', that produces a regexp for matching internet Top Level Domain names. This happens to be an ideal example of showing how the alternations are sorted. - Added a script 'roman', that produces a regexp for matching Roman numerals. Just for fun. - Removed the 'assemble-check' script, whose functionality is adequately dealt with via 'assemble -t'. - Tightened up the explanation of why tracked patterns are bulkier - ISOfied the dates in this file. 0.17 2005-09-10 16:41:22 UTC - Add capture() method. - Restructure _insert_path(). - Factor out duplicated code introduced in 0.16 into _build_re(). - Ensure that the test suite exercises the fallback code path for when Storable is missing, even if Storable is available. - Added test_pod_coverage, merely to earn a free Kwalitee point. 0.16 2005-08-22 23:04:02 UTC - Tracked patterns silently ignored imsx flags. Spotted by Bart Lateur. 0.15 2005-04-27 06:50:31 UTC - Oops. Detabbed all the files and did not rerun the tests. t/03_str.t explicitly performs a test on a literal TAB character, and so it failed. Always, always, *ALWAYS* run the test suite as the last task before uploading. Grrr. 0.14 2005-04-27 00:32:43 UTC - Performance tuning release. Played around significantly with _insertr and lex but major improvement will only come about by writing the lexing routine in C. - Reordered $Default_Lexer to bring the most common cases to the front of the pattern. - Inline the effects of \U, \L, \c, \x. This is handled by _lex_stateful (which offloads some of the worst case lexing costs into a separate routine and thus makes the more usual cases run faster). Handling of \Q in the previous release was incorrect. (Sigh). - Backslash slashes. - Passed arrays around by reference between _lex and a newly introduced _insertr routine. - Silenced warning in _slide_tail (ran/reran) - Fixed bug in _slide_tail (didn't handle '0' as a token). One section of the code used to do its own sliding, now it uses _slide_tail. - Fixed bug in _node_eq revealed by 5.6.1 (implicit ordering of hash keys). - Optimized node_offset() - replace ok() in tests by better things (is, like, ...) - removed use of Test::Differences, since it doesn't work on complex structures. 0.13 2005-04-11 21:59:26 UTC - Deal with \Q...\E patterns. - $Default_Lexer pattern fails on 5.6.x: it would lex '\-' as '\', '-'. - Tests to prove that the global $_ is not clobbered by the module. - Used cmp_ok rather than ok where it makes sense. - Added a (belated) DEBUG_LEX debugging mode 0.12 2005-04-11 23:49:16 UTC - Forgot to guard against the possibility of Test::Differences not being available. This would cause erroneous failures in the test suite if it was not installed. - Quotemeta was still giving troubles. Exhaustive testing also turned up the fact that a bare add('0') would be ignored (and thus the null-match pattern would be returned. - More tweaks to the documentation. 0.11 Sat Apr 9 19:44:19 2005 UTC - Performed coverage testing with Devel::Cover Numerous tests added as a result. Borderline bugs fixed (bizarre copy of ARRAY in leave under D::C - fixed in 0.10). - Finalised the interface to using zero-width lookahead assertions. Depending on the match/failure ratio of the pattern to targets, the pattern execution may be slower with ZWLAs than without. Benchmark it. - Made _dump call _dump_node if passed a reference to a hash. This simplifies the code a bit, since one no longer has to worry about whether the thing we are looking at is a node or a path. All in all a minor patch, just to tidy up some loose ends before moving to heftier optimisations. - The fix in 0.10 for quotemeta didn't go far enough. Hopefully this version gets it right. - A number of minor tweaks based on information discovered during coverage testing. - Added documentation about the mailing list. Sundry documentation tweaks. 0.10 2005-03-29 09:01:49 UTC - Correct Default_Lexer$ pattern to deal with the excessively backslashed tokens that C likes to produce. Bug spotted by Walter Roberson. - Added a fix to an obscure bug that Devel::Cover uncovered. The next release will fold in similar improvements found by using Devel::Cover. 0.09 2005-01-22 9:28:21 UTC - Added lookahead assertions at nodes. (This concept is shamelessly pinched from Dan Kogai's Regexp::Optimizer). The code is currently commented out, because in all my benchmarks the resulting regexps are slower with them. Look for calls to _combine if you want to play around with this. - $Default_Lexer and $Single_Char regexps updated to fix a bug where backslashed characters were broken apart between the backslash and the character, resulting in uncompilable regexps. - Character classes are now sorted to the left of a list of alternations. - Corrected license info in META.yml - Started to switch from ok() to cmp_ok() in the test suite to produce human-readable test failures. 0.08 2005-01-03 11:23:50 UTC - Bug in insert_node fixed: did not deal with the following correctly: qw/bcktx bckx bdix bdktx bdkx/ (The assymetry introduced by 'bdix' threw things off, or something like that). - Bug in reduced regexp generation (reinstated code that had been excised from _re_path() et al). - Rewrote the tests to eliminate the need for Test::Deep. Test::More::is_deeply is sufficient. 0.07 2004-12-17 19:31:18 UTC - It would have been nice to have remembered to update the release date in the POD, and the version in the README. 0.06 2004-12-17 17:38:41 UTC - Can now track regular expressions. Given a match, it is possible to determine which original pattern gave rise to the match. - Improved character class generation: . (anychar) was not special-cased, which would have lead to a.b axb giving a[.x]b Also takes into account single-char width metachars like \t \e et al. Filters out digits if \d appears, and for similar metachars (\D, \s, \W...) - Added a pre_filter method, to perform input filtering prior to the pattern being lexed. - Added a flags method, to allow for (?imsx) pattern modifiers. - enhanced the assemble script: added -b, -c, -d, -v; documented -r - Additions to the README - Added Test::Simple and Test::More as prerequisites. 0.05 2004-12-10 11:52:13 UTC - Bug fix in tests. The skip test in version 0.04 did not deal correctly with non-5.6.0 perls that do not have Test::Deep installed. 0.04 2004-12-09 22:29:56 UTC - In 5.6.0, the backlashes in a quoted word list, qw[ \\d ], will have their backslashes doubled up. In this case, don't run the tests. (Reading from a file or getting input from some other source other than qw[] operators works just fine). 0.03 2004-12-08 21:55:27 UTC - Bug fix: Leading 0s could be omitted from paths because of the difference between while($p) versus while(defined($p)). - An assembled pattern can be generated with whitespace. This can be used in conjunction with the /x modifier, and also for debugging. - Code profiled: dead code paths removed, hotspots rewritten to run more quickly. - Documentation typos and wordos. - assemble script now accepts a number of command line switches to control its behaviour. - More tests. Now with Test::Pod. 0.02 2004-11-19 11:16:33 UTC - An R::A object that has had nothing added to it now produces a pattern that explicitly matches nothing (the original behaviour would match anything). - An object can now chomp its own input. Useful for slurping files. It can also filter the input tokens and discard patterns that don't adhere to what's expected (sanity checking e.g.: don't want spaces). - Documented and added functions to allow for the lexer pattern to be manipulated. - The reset() method was commented out (and the test suite didn't catch the fact). - Detabbed the Assemble.pm, eg/* and t/* files (I like interpreting tabs as four spaces, but this produces horrible indentation on www.cpan.org). - t/00_basic.t test counts were wrong. This showed up if Test::Deep was not installed. - t/02_reduce.t does not need to 'use Data::Dumper'. - Tweaked eg/hostmatch/hostmatch; added eg/assemble, eg/assemble-check - Typos, corrections and addtions to the documentation. 0.01 2004-07-09 21:05:18 UTC - original version; created by h2xs 1.19 (seriously!) Regexp-Assemble-0.38/META.yml0000644000175000017500000000130213122055201014041 0ustar ronron--- abstract: 'Assemble multiple Regular Expressions into a single RE' author: - 'David Landgren' build_requires: ExtUtils::MakeMaker: '0' Test::More: '1.001014' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.22, CPAN::Meta::Converter version 2.150005' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Regexp-Assemble no_index: directory: - t - inc requires: constant: '0' strict: '0' vars: '0' warnings: '0' resources: repository: https://github.com/ronsavage/Regexp-Assemble.git version: '0.38' x_serialization_backend: 'CPAN::Meta::YAML version 0.012' Regexp-Assemble-0.38/MANIFEST0000644000175000017500000000161413122055201013727 0ustar ronronChangelog.ini Changes examples/assemble examples/debugging examples/failure.01.pl examples/fee examples/file.1 examples/file.2 examples/file.3 examples/file.4 examples/hostmatch/bad.canonical examples/hostmatch/error.canonical examples/hostmatch/good.canonical examples/hostmatch/hostmatch examples/hostmatch/source.in examples/ircwatcher examples/naive examples/roman examples/stress-test.pl examples/tld examples/track-5.10 examples/unquotemeta lib/Regexp/Assemble.pm LICENSE Makefile.PL MANIFEST This list of files MANIFEST.SKIP README t/00_basic.t t/01_insert.t t/02_reduce.t t/03_str.t t/04_match.t t/05_hostmatch.t t/06_general.t t/07_warning.t t/08_track.t t/09_debug.t t/10_perl514.t TODO xt/author/pod-coverage.t xt/author/pod.t META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Regexp-Assemble-0.38/LICENSE0000644000175000017500000004740713122054744013630 0ustar ronronTerms of Perl itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" ---------------------------------------------------------------------------- The General Public License (GPL) Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS ---------------------------------------------------------------------------- The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End