Skip to content

Commit ba5494a

Browse files
committed
introduce my \term before initializer is parsed
(Still doesn't work, since we haven't really closed the definitional loop yet.)
1 parent f3d060e commit ba5494a

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

src/Perl6/Actions.nqp

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,30 @@ class Perl6::Actions is HLL::Actions does STDActions {
227227
}
228228
}
229229

230+
method deftermnow($/) {
231+
# 'my \foo' style declaration
232+
if $*SCOPE ne 'my' {
233+
$*W.throw($/, 'X::Comp::NYI',
234+
feature => "$*SCOPE scoped term definitions (only 'my' is supported at the moment)");
235+
}
236+
my $name := $<defterm>.ast;
237+
my $cur_lexpad := $*W.cur_lexpad;
238+
if $cur_lexpad.symbol($name) {
239+
$*W.throw($/, ['X', 'Redeclaration'], symbol => $name);
240+
}
241+
if $*OFTYPE {
242+
my $type := $*OFTYPE.ast;
243+
$cur_lexpad[0].push(QAST::Var.new( :$name, :scope('lexical'),
244+
:decl('var'), :returns($type) ));
245+
$cur_lexpad.symbol($name, :$type, :scope<lexical>);
246+
}
247+
else {
248+
$cur_lexpad[0].push(QAST::Var.new(:$name, :scope('lexical'), :decl('var')));
249+
$cur_lexpad.symbol($name, :scope('lexical'));
250+
}
251+
make $<defterm>.ast;
252+
}
253+
230254
method defterm($/) {
231255
my $name := ~$<identifier>;
232256
if $<colonpair> {
@@ -2432,22 +2456,11 @@ Compilation unit '$file' contained the following violations:
24322456

24332457
make $list;
24342458
}
2435-
elsif $<defterm> {
2459+
elsif $<deftermnow> {
24362460
# 'my \foo' style declaration
2437-
if $*SCOPE ne 'my' {
2438-
$*W.throw($/, 'X::Comp::NYI',
2439-
feature => "$*SCOPE scoped term definitions (only 'my' is supported at the moment)");
2440-
}
2441-
my $name := $<defterm>.ast;
2442-
my $cur_lexpad := $*W.cur_lexpad;
2443-
if $cur_lexpad.symbol($name) {
2444-
$*W.throw($/, ['X', 'Redeclaration'], symbol => $name);
2445-
}
2461+
my $name := $<deftermnow>.ast;
24462462
if $*OFTYPE {
24472463
my $type := $*OFTYPE.ast;
2448-
$cur_lexpad[0].push(QAST::Var.new( :$name, :scope('lexical'),
2449-
:decl('var'), :returns($type) ));
2450-
$cur_lexpad.symbol($name, :$type, :scope<lexical>);
24512464
make QAST::Op.new(
24522465
:op<bind>,
24532466
QAST::Var.new(:$name, :scope<lexical>),
@@ -2461,14 +2474,12 @@ Compilation unit '$file' contained the following violations:
24612474
);
24622475
}
24632476
else {
2464-
$cur_lexpad[0].push(QAST::Var.new(:$name, :scope('lexical'), :decl('var')));
2465-
$cur_lexpad.symbol($name, :scope('lexical'));
24662477
make QAST::Op.new(
24672478
:op<bind>,
24682479
QAST::Var.new(:$name, :scope<lexical>),
24692480
$<term_init>.ast
24702481
);
2471-
}
2482+
}
24722483
}
24732484
else {
24742485
$/.CURSOR.panic('Unknown declarator type');

src/Perl6/Grammar.nqp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,8 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
453453
<subshortname> <sigterm>?
454454
}
455455

456+
token deftermnow { <defterm> }
457+
456458
token defterm { # XXX this is probably too general
457459
:dba('new term to be defined')
458460
<identifier>
@@ -2286,7 +2288,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
22862288
[
22872289
# STD.pm6 uses <defterm> here, but we need different
22882290
# action methods
2289-
| '\\' <defterm>
2291+
| '\\' <deftermnow>
22902292
[ <.ws> <term_init=initializer> || <.typed_panic: "X::Syntax::Term::MissingInitializer"> ]
22912293
| <variable_declarator>
22922294
[

0 commit comments

Comments
 (0)