Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[regex] lexicalize free-standing regex
  • Loading branch information
perlpilot committed Jun 12, 2010
1 parent ef42d30 commit 61514b0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
22 changes: 11 additions & 11 deletions src/regexes.pod
Expand Up @@ -11,8 +11,8 @@ simple technique uses so-called I<regular expressions> or I<regexes>:

my $s = 'the quick brown fox jumped over the the lazy dog';

token word { \w+ [ \' \w+]? }
regex dup { <word> \W+ $<word> }
my token word { \w+ [ \' \w+]? }
my regex dup { <word> \W+ $<word> }
if $s ~~ m/ <dup> / {
say "Found '{$<dup><word>}' twice in a row";
}
Expand Down Expand Up @@ -508,8 +508,8 @@ or C<isn't>:

=begin programlisting

regex word { \w+ [ \' \w+]? }
regex dup { « <word> \W+ $<word> » }
my regex word { \w+ [ \' \w+]? }
my regex dup { « <word> \W+ $<word> » }

if $s ~~ m/ <dup> / {
say "Found '{$<dup><word>}' twice in a row";
Expand Down Expand Up @@ -620,8 +620,8 @@ word:

=begin programlisting

regex word { :ratchet \w+ [ \' \w+]? }
regex dup { <word> \W+ $<word> }
my regex word { :ratchet \w+ [ \' \w+]? }
my regex dup { <word> \W+ $<word> }

# no match, doesn't match the 'and'
# in 'strand' without backtracking
Expand All @@ -641,8 +641,8 @@ C<token { ... }>. The duplicate word searcher is idiomatic when written:

=begin programlisting

B<token> word { \w+ [ \' \w+]? }
regex dup { <word> \W+ $<word> }
my B<token> word { \w+ [ \' \w+]? }
my regex dup { <word> \W+ $<word> }

=end programlisting

Expand All @@ -653,7 +653,7 @@ A token that also switches on the C<:sigspace> modifier is a C<rule>:

=begin programlisting

rule wordlist { <word> ** \, 'and' <word> }
my rule wordlist { <word> ** \, 'and' <word> }

=end programlisting

Expand Down Expand Up @@ -817,8 +817,8 @@ assertions, though usually not quite as efficient:

my $s = "the quick\nbrown fox jumped\nover the the lazy dog";

token word { \w+ [ \' \w+]? }
regex dup { <word> \W+ $<word> }
my token word { \w+ [ \' \w+]? }
my regex dup { <word> \W+ $<word> }
if $s ~~ m/ <dup> / {
my ($line, $column) = line-and-column($/);
say "Found '{$<dup><word>}' twice in a row";
Expand Down
6 changes: 3 additions & 3 deletions src/roles.pod
Expand Up @@ -16,9 +16,9 @@ simple commands.
# does provide opportunities to discuss runtime mixins, compile time
# composition, requirements and a few other bits.

regex nick { \w+ }
regex join-line { ... <nick> ... }
regex message-line { $<sender>=[...] $<message>=[...] }
my regex nick { \w+ }
my regex join-line { ... <nick> ... }
my regex message-line { $<sender>=[...] $<message>=[...] }

class IRCBot {
has $.bot-nick;
Expand Down

0 comments on commit 61514b0

Please sign in to comment.