~ubuntu-branches/ubuntu/vivid/nqp/vivid-proposed

« back to all changes in this revision

Viewing changes to src/QRegex/P5Regex/Grammar.nqp

  • Committer: Package Import Robot
  • Author(s): Alessandro Ghedini
  • Date: 2013-11-01 12:09:18 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20131101120918-kx51sl0sxl3exsxi
Tags: 2013.10-1
* New upstream release
* Bump versioned (Build-)Depends on parrot
* Update patches
* Install new README.pod
* Fix vcs-field-not-canonical
* Do not install rubyish examples
* Do not Depends on parrot-devel anymore
* Add 07_disable-serialization-tests.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
}
39
39
 
40
40
grammar QRegex::P5Regex::Grammar is HLL::Grammar {
 
41
    my $cur_handle := 0;
41
42
    token TOP {
42
43
        :my %*RX;
43
 
        :my $*W := QRegex::P5Regex::World.new(:handle(nqp::sha1(self.target)));
 
44
        :my $handle := '__QREGEX_P5REGEX__' ~ $cur_handle++;
 
45
        :my $*W := QRegex::P5Regex::World.new(:$handle);
44
46
        <nibbler>
45
47
        [ $ || <.panic: 'Confused'> ]
46
48
    }
69
71
        <![|)]>
70
72
        <!rxstopper>
71
73
        <atom>
72
 
        [ <.ws> <quantifier=p5quantifier> ]?
 
74
        [ <.ws> <!before <rxstopper> > <quantifier=p5quantifier> ]**0..1
73
75
        <.ws>
74
76
    }
75
77
    
84
86
    proto token p5metachar { <...> }
85
87
    
86
88
    token p5metachar:sym<quant> {
 
89
        <![(?]>
87
90
        <quantifier=p5quantifier>
88
91
        <.panic: "quantifier quantifies nothing">
89
92
    }
94
97
        '$' <?before \W | $>
95
98
    }
96
99
    token p5metachar:sym<(? )> {
97
 
        '(?' {} <assertion=p5assertion>
98
 
        [ ')' || <.panic: "Perl 5 regex assertion not terminated by parenthesis"> ]
 
100
        '(?' <![?]>
 
101
            [
 
102
            | <?[<]> '<' $<name>=[<-[>]>+] '>' {} <nibbler>
 
103
            | <?[']> "'" $<name>=[<-[']>+] "'" {} <nibbler>
 
104
            | <assertion=p5assertion>
 
105
            ]
 
106
        [ ')' || <.panic: "Perl 5 named capture group not terminated by parenthesis"> ]
99
107
    }
 
108
    token p5metachar:sym<(?: )> { '(?:' {} <nibbler> ')' }
100
109
    token p5metachar:sym<( )> { '(' {} <nibbler> ')' }
101
110
    token p5metachar:sym<[ ]> { <?before '['> <cclass> }
102
111
    
106
115
        $<sign>=['^'|<?>]
107
116
        [
108
117
        || $<charspec>=(
109
 
               \s* ( '\\' <backslash=p5backslash> || (<?{ $pastfirst == 0 }> <-[\\]> || <-[\]\\]>) )
 
118
               ( '\\' <backslash=p5backslash> || (<?{ $pastfirst == 0 }> <-[\\]> || <-[\]\\]>) )
110
119
               [
111
120
                   \s* '-' \s*
112
121
                   ( '\\' <backslash=p5backslash> || (<-[\]\\]>) )
113
 
               ]?
 
122
               ]**0..1
114
123
               { $pastfirst++ }
115
124
           )+
116
 
           \s* ']'
 
125
           ']'
117
126
        || <.panic: "failed to parse character class; unescaped ']'?">
118
127
        ]
119
128
    }
121
130
    proto token p5backslash { <...> }
122
131
    
123
132
    token p5backslash:sym<A> { <sym> }
 
133
    token p5backslash:sym<b> { $<sym>=[<[bB]>] }
 
134
    token p5backslash:sym<r> { <sym> }
 
135
    token p5backslash:sym<R> { <sym> }
 
136
    token p5backslash:sym<s> { $<sym>=[<[dDnNsSwW]>] }
 
137
    token p5backslash:sym<t> { <sym> }
 
138
    token p5backslash:sym<x> { <sym> <hexint> }
124
139
    token p5backslash:sym<z> { <sym> }
125
140
    token p5backslash:sym<Z> { <sym> }
126
 
    token p5backslash:sym<b> { $<sym>=[<[bB]>] }
127
 
    token p5backslash:sym<s> { $<sym>=[<[dDnNsSwW]>] }
128
141
    token p5backslash:sym<misc> { $<litchar>=(\W) | $<number>=(\d+) }
129
142
    token p5backslash:sym<oops> { <.panic: "Unrecognized Perl 5 regex backslash sequence"> }
130
143
 
135
148
    token p5assertion:sym<!> { <sym> [ <?before ')'> | <nibbler> ] }
136
149
    
137
150
    token p5mod  { <[imsox]>* }
138
 
    token p5mods { <on=p5mod> [ '-' <off=p5mod> ]? }
 
151
    token p5mods { <on=p5mod> [ '-' <off=p5mod> ]**0..1 }
139
152
    token p5assertion:sym<mod> {
140
153
        :my %*OLDRX := nqp::getlexdyn('%*RX');
141
154
        :my %*RX;
144
157
        }
145
158
        <mods=p5mods>
146
159
        [
147
 
        | ':' <nibbler>?
 
160
        | ':' <nibbler>**0..1
148
161
        | <?before ')' >
149
162
        ]
150
163
    }
157
170
    token p5quantifier:sym<{ }> {
158
171
        '{' 
159
172
        $<start>=[\d+] 
160
 
        [ $<comma>=',' $<end>=[\d*] ]?
 
173
        [ $<comma>=',' $<end>=[\d*] ]**0..1
161
174
        '}' <quantmod>
162
175
    }
163
176
    
201
214
        | '$' $<pos>=[\d+]
202
215
        ]
203
216
 
204
 
        [ <.ws> '=' <.ws> <quantified_atom> ]?
 
217
        [ <.ws> '=' <.ws> <quantified_atom> ]**0..1
205
218
    }
206
219
 
207
220
    proto token backslash { <...> }
230
243
            | ':' <arglist>
231
244
            | '(' <arglist> ')'
232
245
            | <.normspace> <nibbler>
233
 
            ]?
 
246
            ]**0..1
234
247
    }
235
248
}