Skip to content

Commit

Permalink
prepare for YAPC
Browse files Browse the repository at this point in the history
  • Loading branch information
mishin committed Aug 15, 2015
1 parent 6448555 commit 430623b
Show file tree
Hide file tree
Showing 96 changed files with 3,479 additions and 0 deletions.
5 changes: 5 additions & 0 deletions 0123_t.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use feature 'signatures';

sub normal_signature ($foo) {}

sub slurpy_signature ($foo, @) {}
5 changes: 5 additions & 0 deletions N.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$_ = "The brown fox jumps over the lazy dog";
/the (\S+)(?{ $color = $^N }) (\S+)(?{ $animal = $^N })/i;
print "color = $color, animal = $animal\n";
print $^R."\n";
print $^R->[1]."\n";
10 changes: 10 additions & 0 deletions amelia_1.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use v5.10;
$_ = <<'HERE';
Amelia said "I am a camel"
HERE

say "Matched [$+{said}]!" if m/
( ['"] )
(?<said>.*?)
( ['"] )
/x;
9 changes: 9 additions & 0 deletions amelia_1.pl.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$_ = <<'HERE';
Amelia said "I am a camel"
HERE

say "Matched [$+{said}]!" if m/
( ['"] )
(?<said>.*?)
( ['"] )
/x;
27 changes: 27 additions & 0 deletions amelia_10.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use v5.18;
$_ = <<'HERE';
Out "Top 'Middle "Bottom" Middle' Out"
HERE

my @matches;

say "Matched!" if m/
(?(DEFINE)
(?<QUOTE_MARK> ['"])
(?<NOT_QUOTE_MARK> [^'"])
(?<QUOTE>
(
(?<quote>(?&QUOTE_MARK))
(?:
(?&NOT_QUOTE_MARK)++
(?&QUOTE)
)*
\g{quote}
)
(?{ [ @{$^R}, $^N ] })
)
)
(?&QUOTE) (?{ @matches=@{ $^R } })
/x;

27 changes: 27 additions & 0 deletions amelia_11.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use v5.18;
$_ = <<'HERE';
Out "Top 'Middle "Bottom" Middle' Out"
HERE

my @matches;

say "Matched!" if m/
(?(DEFINE)
(?<QUOTE_MARK> ['"])
(?<NOT_QUOTE_MARK> [^'"])
(?<QUOTE>
(
(?<quote>(?&QUOTE_MARK))
(?:
(?&NOT_QUOTE_MARK)++
|
(?&QUOTE)
)*
\g{quote}
)
(?{ [ @{$^R}, $^N ] })
)
)
(?&QUOTE) (?{ @matches = @{ $^R } })
/x;
10 changes: 10 additions & 0 deletions amelia_2.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use v5.10;
$_ = <<'HERE';
Amelia said "I am a camel"
HERE

say "Matched [$+{said}]!" if m/
( ['"] )
(?<said>.*?)
( \1 )
/x;
10 changes: 10 additions & 0 deletions amelia_3.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use v5.10;
$_ = <<'HERE';
Amelia said "I am a camel"
HERE

say "Matched [$+{said}]!" if m/
( ['"] )
(?<said>.*?)
(?1)
/x;
10 changes: 10 additions & 0 deletions amelia_4.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use v5.10;
$_ = <<'HERE';
Amelia said "I am a camel'
HERE

say "Matched [$+{said}]!" if m/
( ['"] )
(?<said>.*?)
(?1)
/x;
16 changes: 16 additions & 0 deletions amelia_5.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use v5.18;
$_ = <<'HERE';
He said 'Amelia said "I am a camel"'
HERE

say "Matched [$+{said}]!" if m/
(?<said> #$1
(?<quote>['"])
(?:
[^'"]++
|
(?<said> (?1) )
)*
\g{quote}
)
/x;
17 changes: 17 additions & 0 deletions amelia_6.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use v5.18;
$_ = <<'HERE';
Out "Top 'Middle "Bottom" Middle' Out"
HERE

say "Matched [$+{said}]!" if m/
(?<said> #$1
(?<quote>['"])
(?:
[^'"]++
|
(?R)
)*
\g{quote}
)
(?{say "Inside regex: $+{said}"})
/x;
23 changes: 23 additions & 0 deletions amelia_7.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use v5.18;
$_ = <<'HERE';
Out "Top 'Middle "Bottom" Middle' Out"
HERE


say "Matched [$+{said}]!" if m/
(?(DEFINE)
(?<QUOTE> ['"])
(?<NOT_QUOTE> [^'"])
)
(?<said>
(?<quote>(?&QUOTE))
(?:
(?&NOT_QUOTE)++
|
(?R)
)*
\g{quote}
)
(?{ say "Inside regex: $+{said}" })
/x;

26 changes: 26 additions & 0 deletions amelia_8.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use v5.18;
$_ = <<'HERE';
Out "Top 'Middle "Bottom" Middle' Out"
HERE

my @matches;

say "Matched [$+{said}]!" if m/
(?(DEFINE)
(?<QUOTE> ['"])
(?<NOT_QUOTE> [^'"])
)
(?<said>
(?<quote>(?&QUOTE))
(?:
(?&NOT_QUOTE)++
|
(?R)
)*
\g{quote}
)
(?{ push @matches, $^N })
/x;

say "\n".join '|',@matches;

27 changes: 27 additions & 0 deletions amelia_9.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use v5.18;
$_ = <<'HERE';
Out "Top 'Middle "Bottom" Middle' Out"
HERE

my @matches;

say "Matched!" if m/
(?(DEFINE)
(?<QUOTE_MARK> ['"])
(?<NOT_QUOTE_MARK> [^'"])
(?<QUOTE>
(
(?<quote>(?&QUOTE_MARK))
(?:
(?&NOT_QUOTE_MARK)++
(?&QUOTE)
)*
\g{quote}
)
(?{ push @matches, $^N })
)
)
(?&QUOTE)
/x;

8 changes: 8 additions & 0 deletions buggy.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/perl
use Modern::Perl;

my $i = 1;
while ($i & 8 == 0 || $i & 256 == 0){
++$i;
}
print $i, "\n";
106 changes: 106 additions & 0 deletions json.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/usr/bin/env perl

use Data::Dumper qw(Dumper);

my $FROM_JSON = qr{
(?&VALUE) (?{ $_ = $^R->[1] })
(?(DEFINE)
(?<OBJECT>
(?{ [$^R, {}] })
\{
(?: (?&KV) # [[$^R, {}], $k, $v]
(?{ # warn Dumper { obj1 => $^R };
[$^R->[0][0], {$^R->[1] => $^R->[2]}] })
(?: , (?&KV) # [[$^R, {...}], $k, $v]
(?{ # warn Dumper { obj2 => $^R };
[$^R->[0][0], {%{$^R->[0][1]}, $^R->[1] => $^R->[2]}] })
)*
)?
\}
)
(?<KV>
(?&STRING) # [$^R, "string"]
: (?&VALUE) # [[$^R, "string"], $value]
(?{ # warn Dumper { kv => $^R };
[$^R->[0][0], $^R->[0][1], $^R->[1]] })
)
(?<ARRAY>
(?{ [$^R, []] })
\[
(?: (?&VALUE) (?{ [$^R->[0][0], [$^R->[1]]] })
(?: , (?&VALUE) (?{ # warn Dumper { atwo => $^R };
[$^R->[0][0], [@{$^R->[0][1]}, $^R->[1]]] })
)*
)?
\]
)
(?<VALUE>
\s*
(
(?&STRING)
|
(?&NUMBER)
|
(?&OBJECT)
|
(?&ARRAY)
|
true (?{ [$^R, 1] })
|
false (?{ [$^R, 0] })
|
null (?{ [$^R, undef] })
)
\s*
)
(?<STRING>
(
"
(?:
[^\\"]+
|
\\ ["\\/bfnrt]
# |
# \\ u [0-9a-fA-f]{4}
)*
"
)
(?{ [$^R, eval $^N] })
)
(?<NUMBER>
(
-?
(?: 0 | [1-9]\d* )
(?: \. \d+ )?
(?: [eE] [-+]? \d+ )?
)
(?{ [$^R, eval $^N] })
)
) }xms;

sub from_json {
local $_ = shift;
local $^R;
eval { m{\A$FROM_JSON\z}; } and return $_;
die $@ if $@;
return 'no match';
}

while (<>) {
chomp;
print Dumper from_json($_);
}



15 changes: 15 additions & 0 deletions regex_recursion/.help
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

<SPACE> Advance
<BACKSPACE> Go back

?? Help
QQ Quit Vroom

RR Run slide as a program
VV vroom vroom
EE Edit file under cursor
OO Open file under cursor (Mac OS X)


(Press SPACE to leave Help screen and continue)

29 changes: 29 additions & 0 deletions regex_recursion/.vimrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
" This .vimrc file was created by Vroom-0.37
set nocompatible
syntax on

map <SPACE> :n<CR>:<CR>gg
map <BACKSPACE> :N<CR>:<CR>gg
map R :!vroom -run %<CR>
map RR :!vroom -run %<CR>
map AA :call RunNow()<CR>:<CR>
map VV :!vroom -vroom<CR>
map QQ :q!<CR>
map OO :!open <cWORD><CR><CR>
map EE :e <cWORD><CR>
map !! G:!open <cWORD><CR><CR>
map ?? :e .help<CR>
set laststatus=2
set statusline=%-20f\ Recursion\ in\ Regex!

" Overrides from /home/mishin/.vroom/vimrc


" Values from slides.vroom config section. (under 'vimrc')
set statusline=%-3f\ \ \ \ \ Recursioni\ in\ Regex\ (or:\ How\ parse\ IBM\ Datastage\ dsx\ file)
map <C-C> 3<C-^><Ctrl-Home>
map <C-O> 2<C-^><Ctrl-Home>
map <C-E> 5<C-^><Ctrl-Home>
map <C-P> 11<C-^><Ctrl-Home>
map MSM ouse Method::Signatures::Modifiers;<Esc>
Loading

0 comments on commit 430623b

Please sign in to comment.