Skip to content

Commit 2d8b6e8

Browse files
committed
Start getting various of the p5metachar bits in place, and eliminate a few bits that will be unrequired.
1 parent c5d768b commit 2d8b6e8

File tree

2 files changed

+50
-45
lines changed

2 files changed

+50
-45
lines changed

src/QRegex/P5Regex/Actions.nqp

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,51 @@ class QRegex::P5Regex::Actions is HLL::Actions {
4242
$ast.unshift($qast);
4343
$qast := $ast;
4444
}
45-
$qast.backtrack('r') if $qast && !$qast.backtrack &&
46-
(%*RX<r> || $<backmod> && ~$<backmod>[0] eq ':');
45+
$qast.backtrack('r') if $qast && !$qast.backtrack && %*RX<r>;
4746
make $qast;
4847
}
4948

5049
method atom($/) {
5150
if $<metachar> {
5251
make $<metachar>.ast;
5352
}
53+
elsif $<esc> {
54+
my $qast := QAST::Regex.new( ~$<esc>, :rxtype<literal>, :node($/));
55+
make $qast;
56+
}
5457
else {
5558
my $qast := QAST::Regex.new( ~$/, :rxtype<literal>, :node($/));
5659
$qast.subtype('ignorecase') if %*RX<i>;
5760
make $qast;
5861
}
5962
}
63+
64+
method p5metachar:sym<bs>($/) {
65+
make $<backslash>.ast;
66+
}
67+
68+
method p5metachar:sym<.>($/) {
69+
make QAST::Regex.new( :rxtype<cclass>, :subtype<.>, :node($/) );
70+
}
71+
72+
method p5metachar:sym<^>($/) {
73+
make QAST::Regex.new( :rxtype<anchor>, :subtype<bos>, :node($/) );
74+
}
75+
76+
method p5metachar:sym<$>($/) {
77+
make QAST::Regex.new(
78+
:rxtype('concat'),
79+
QAST::Regex.new(
80+
:rxtype('quant'), :min(0), :max(1),
81+
QAST::Regex.new( :rxtype('literal'), "\n" )
82+
),
83+
QAST::Regex.new( :rxtype<anchor>, :subtype<eos>, :node($/) )
84+
);
85+
}
6086

87+
88+
# XXX Below here copied from p6regex; needs review
89+
6190
method quantifier:sym<*>($/) {
6291
my $qast := QAST::Regex.new( :rxtype<quant>, :min(0), :max(-1), :node($/) );
6392
make backmod($qast, $<backmod>);
@@ -117,26 +146,6 @@ class QRegex::P5Regex::Actions is HLL::Actions {
117146
make $qast;
118147
}
119148

120-
method metachar:sym<.>($/) {
121-
make QAST::Regex.new( :rxtype<cclass>, :subtype<.>, :node($/) );
122-
}
123-
124-
method metachar:sym<^>($/) {
125-
make QAST::Regex.new( :rxtype<anchor>, :subtype<bos>, :node($/) );
126-
}
127-
128-
method metachar:sym<^^>($/) {
129-
make QAST::Regex.new( :rxtype<anchor>, :subtype<bol>, :node($/) );
130-
}
131-
132-
method metachar:sym<$>($/) {
133-
make QAST::Regex.new( :rxtype<anchor>, :subtype<eos>, :node($/) );
134-
}
135-
136-
method metachar:sym<$$>($/) {
137-
make QAST::Regex.new( :rxtype<anchor>, :subtype<eol>, :node($/) );
138-
}
139-
140149
method metachar:sym<lwb>($/) {
141150
make QAST::Regex.new( :rxtype<anchor>, :subtype<lwb>, :node($/) );
142151
}
@@ -157,10 +166,6 @@ class QRegex::P5Regex::Actions is HLL::Actions {
157166
:name<$!to>, PAST::Node.new('!LITERAL', ''), :node($/) );
158167
}
159168

160-
method metachar:sym<bs>($/) {
161-
make $<backslash>.ast;
162-
}
163-
164169
method metachar:sym<assert>($/) {
165170
make $<assertion>.ast;
166171
}

src/QRegex/P5Regex/Grammar.nqp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,27 @@ grammar QRegex::P5Regex::Grammar is HLL::Grammar {
3535
[ <.ws> <quantifier=p5quantifier> ]?
3636
<.ws>
3737
}
38+
39+
token atom {
40+
[
41+
| \w
42+
| <metachar=p5metachar>
43+
| '\\' {} $<esc>=.
44+
]
45+
}
3846

3947
proto token p5metachar { <...> }
48+
49+
token p5metachar:sym<quant> {
50+
<quantifier=p5quantifier>
51+
<.panic: "quantifier quantifies nothing">
52+
}
53+
token p5metachar:sym<bs> { <sym> <backslash=p5backslash> }
54+
token p5metachar:sym<.> { <sym> }
55+
token p5metachar:sym<^> { <sym> }
56+
token p5metachar:sym<$> {
57+
'$' <?before \W | $>
58+
}
4059

4160
proto token p5backslash { <...> }
4261

@@ -63,14 +82,6 @@ grammar QRegex::P5Regex::Grammar is HLL::Grammar {
6382
}
6483

6584
rule arglist { <arg> [ ',' <arg>]* }
66-
67-
token atom {
68-
# :dba('regex atom')
69-
[
70-
| \w [ \w+! <?before \w> ]?
71-
| <metachar>
72-
]
73-
}
7485

7586
proto token quantifier { <...> }
7687
token quantifier:sym<*> { <sym> <backmod> }
@@ -101,22 +112,11 @@ grammar QRegex::P5Regex::Grammar is HLL::Grammar {
101112
token metachar:sym<( )> { '(' <nibbler> ')' }
102113
token metachar:sym<'> { <?[']> <quote_EXPR: ':q'> }
103114
token metachar:sym<"> { <?["]> <quote_EXPR: ':qq'> }
104-
token metachar:sym<.> { <sym> }
105-
token metachar:sym<^> { <sym> }
106-
token metachar:sym<^^> { <sym> }
107-
token metachar:sym<$> { <sym> }
108-
token metachar:sym<$$> { <sym> }
109-
token metachar:sym<:::> { <sym> <.panic: '::: not yet implemented'> }
110-
token metachar:sym<::> { <sym> <.panic: ':: not yet implemented'> }
111115
token metachar:sym<lwb> { $<sym>=['<<'|'«'] }
112116
token metachar:sym<rwb> { $<sym>=['>>'|'»'] }
113117
token metachar:sym<from> { '<(' }
114118
token metachar:sym<to> { ')>' }
115-
token metachar:sym<bs> { \\ <backslash> }
116119
token metachar:sym<mod> { <mod_internal> }
117-
token metachar:sym<quantifier> {
118-
<quantifier> <.panic: 'Quantifier quantifies nothing'>
119-
}
120120

121121
## we cheat here, really should be regex_infix:sym<~>
122122
token metachar:sym<~> {

0 commit comments

Comments
 (0)