Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 83 lines (73 sloc) 1.916 kb
1f2f75d @masak [GGE::Perl6Regex] refactoring
authored
1 use v6;
a9d4426 @masak [GGE::Perl6Regex] adapted to use GGE::OPTable
authored
2 use GGE::Match;
1f2f75d @masak [GGE::Perl6Regex] refactoring
authored
3
a9d4426 @masak [GGE::Perl6Regex] adapted to use GGE::OPTable
authored
4 enum GGE_BACKTRACK <
5 GREEDY
6 EAGER
7 NONE
8 >;
c1a1035 @masak [GGE::Perl6Regex] introduced \s
authored
9
a9d4426 @masak [GGE::Perl6Regex] adapted to use GGE::OPTable
authored
10 class GGE::Exp is GGE::Match {}
3af0ded @masak [GGE] refactoring
authored
11
a9d4426 @masak [GGE::Perl6Regex] adapted to use GGE::OPTable
authored
12 class GGE::Exp::Literal is GGE::Exp {
3af0ded @masak [GGE] refactoring
authored
13 method matches($string, $pos is rw) {
14 if $pos >= $string.chars {
15 return False;
16 }
a9d4426 @masak [GGE::Perl6Regex] adapted to use GGE::OPTable
authored
17 my $value = self.Str;
18 if $string.substr($pos, $value.chars) eq $value {
19 $pos += $value.chars;
3af0ded @masak [GGE] refactoring
authored
20 return True;
21 }
22 }
23 }
24
1f2f75d @masak [GGE::Perl6Regex] refactoring
authored
25 class GGE::Exp::Quant is GGE::Exp {
a9d4426 @masak [GGE::Perl6Regex] adapted to use GGE::OPTable
authored
26 has &.backtrack = { False };
0a7cfd5 @masak [GGE] Introduced Cursors
authored
27
a9d4426 @masak [GGE::Perl6Regex] adapted to use GGE::OPTable
authored
28 method matches($string, $pos is rw) {
29 for ^self<min> {
30 return False if !self[0].matches($string, $pos);
31 }
32 my $n = self<min>;
33 if self<backtrack> == EAGER {
34 &!backtrack = {
35 $n++ < self<max> && self[0].matches($string, $pos)
36 };
37 }
38 else {
39 my @positions;
40 while $n++ < self<max> {
41 push @positions, $pos;
42 last if !self[0].matches($string, $pos);
43 }
44 if self<backtrack> == GREEDY {
45 &!backtrack = {
46 @positions && $pos = pop @positions
47 };
48 }
49 }
50 return True;
51 }
1f2f75d @masak [GGE::Perl6Regex] refactoring
authored
52 }
53
c1a1035 @masak [GGE::Perl6Regex] introduced \s
authored
54 class GGE::Exp::CCShortcut is GGE::Exp {
3af0ded @masak [GGE] refactoring
authored
55 method matches($string, $pos is rw) {
a9d4426 @masak [GGE::Perl6Regex] adapted to use GGE::OPTable
authored
56 if $pos >= $string.chars {
57 return False;
3af0ded @masak [GGE] refactoring
authored
58 }
a9d4426 @masak [GGE::Perl6Regex] adapted to use GGE::OPTable
authored
59 if self.Str eq '.'
60 || self.Str eq '\\s' && $string.substr($pos, 1) eq ' '
61 || self.Str eq '\\S' && $string.substr($pos, 1) ne ' ' {
3af0ded @masak [GGE] refactoring
authored
62 ++$pos;
63 return True;
64 }
a9d4426 @masak [GGE::Perl6Regex] adapted to use GGE::OPTable
authored
65 else {
66 return False;
67 }
3af0ded @masak [GGE] refactoring
authored
68 }
c1a1035 @masak [GGE::Perl6Regex] introduced \s
authored
69 }
8f53695 @masak [GGE::Perl6Regex] added ^ support
authored
70
71 class GGE::Exp::Anchor is GGE::Exp {
3af0ded @masak [GGE] refactoring
authored
72 method matches($string, $pos is rw) {
a9d4426 @masak [GGE::Perl6Regex] adapted to use GGE::OPTable
authored
73 return self.Str eq '^' && $pos == 0
74 || self.Str eq '$' && $pos == $string.chars;
3af0ded @masak [GGE] refactoring
authored
75 }
8f53695 @masak [GGE::Perl6Regex] added ^ support
authored
76 }
a9d4426 @masak [GGE::Perl6Regex] adapted to use GGE::OPTable
authored
77
78 class GGE::Exp::Concat is GGE::Exp {
79 }
80
81 class GGE::Exp::Modifier is GGE::Exp {
82 }
Something went wrong with that request. Please try again.