Skip to content

Commit

Permalink
RakuAST: remove special translator actions
Browse files Browse the repository at this point in the history
These appear to cause problems when mixing in slangs.  Since the
actions are pretty simple, just run that code in the grammar.  This
appears to fix the initial teething issues for other natural language
versions of Raku.
  • Loading branch information
lizmat committed Sep 19, 2023
1 parent 6175970 commit f1c6261
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 27 deletions.
19 changes: 2 additions & 17 deletions src/Raku/Actions.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,6 @@ role Raku::CommonActions {
class Raku::Actions is HLL::Actions does Raku::CommonActions {
method OperatorProperties() { $OperatorProperties }

#-------------------------------------------------------------------------------
# Translatable tokens

method block-elsif($/) { @*IF-PARTS.push('Elsif') }
method block-if($/) { @*IF-PARTS.push('If') }
method block-orwith($/) { @*IF-PARTS.push('Orwith') }
method block-with($/) { @*IF-PARTS.push('With') }

method block-until($/) { $*WHILE := 'Until' }
method block-while($/) { $*WHILE := 'While' }

method phaser-BEGIN($/) { $*DOC-PHASER := 'Begin' }
method phaser-CHECK($/) { $*DOC-PHASER := 'Check' }
method phaser-INIT($/) { $*DOC-PHASER := 'Init' }

#-------------------------------------------------------------------------------
# Compilation unit, language version and other entry point bits

Expand Down Expand Up @@ -666,10 +651,10 @@ class Raku::Actions is HLL::Actions does Raku::CommonActions {

# Handling of all forms of loops
method statement-control:sym<repeat>($/) {
self.takes-loop($/, 'Repeat' ~ $*WHILE)
self.takes-loop($/, 'Repeat' ~ ($*WHILE // 'While'))
}
method statement-control:sym<while>($/) {
self.takes-loop($/, $*WHILE)
self.takes-loop($/, $*WHILE // 'While')
}

# Handling of whenever
Expand Down
20 changes: 10 additions & 10 deletions src/Raku/Grammar.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -923,10 +923,6 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common {
my $*SORRY_REMAINING := 10; # decremented on each sorry; panic when 0
my $*BORG := {}; # who gets blamed for a missing block
# Fallback dynvars for translated token -> RakuAST class mapping
my $*WHILE; # while/until
my $*DOC-PHASER; # DOC BEGIN | CHECK | INIT
# -1 indicates we're outside of any "supply" or "react" block
my $*WHENEVER-COUNT := -1;
Expand Down Expand Up @@ -1265,7 +1261,7 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common {
# Handle "while" / "until"
rule statement-control:sym<while> {
:my $*WHILE;
[<.block-while>|<.block-until>]<.kok>
[<.block-while>|<.block-until>{$*WHILE := 'Until'}]<.kok>
{}
:my $*GOAL := '{';
:my $*BORG := {};
Expand Down Expand Up @@ -1304,15 +1300,15 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common {
# Handle "if" / "with"
rule statement-control:sym<if> {
:my @*IF-PARTS;
[<.block-if>|<.block-with>]<.kok>
[<.block-if>{@*IF-PARTS.push('If')}|<.block-with>{@*IF-PARTS.push('With')}]<.kok>
{}
:my $*GOAL := '{';
:my $*BORG := {};
<EXPR> # initial condition
<pointy-block> # initial body
[ # any elsifs/orwiths
[
| [<.block-elsif>|<.block-orwith>]
| [<.block-elsif>{@*IF-PARTS.push('Elsif')}|<.block-orwith>{@*IF-PARTS.push('Orwith')}]
<EXPR>
<pointy-block>
Expand Down Expand Up @@ -1350,14 +1346,14 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common {
<.block-repeat><.kok>
{}
[
| [<.block-while>|<.block-until>]<.kok>
| [<.block-while>|<.block-until>{$*WHILE := 'Until'}]<.kok>
:my $*GOAL := '{';
:my $*BORG := {};
<EXPR>
<pointy-block>
| <pointy-block>
[
[<.block-while>|<.block-until>]<.kok>
[<.block-while>|<.block-until>{$*WHILE := 'Until'}]<.kok>
|| <.missing: '"while" or "until"'>
]
<EXPR>
Expand Down Expand Up @@ -1558,7 +1554,11 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common {
:my $*DOC-PHASER;
<.phaser-DOC>
<.kok>
[<.phaser-BEGIN> || <.phaser-CHECK> || <.phaser-INIT>]
[
<.phaser-BEGIN> { $*DOC-PHASER := 'Begin' }
|| <.phaser-CHECK> { $*DOC-PHASER := 'Check' }
|| <.phaser-INIT> { $*DOC-PHASER := 'Init' }
]
<.end-keyword>
<.ws>
<blorst>
Expand Down

0 comments on commit f1c6261

Please sign in to comment.