Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Partially implement moreinput in our grammar.
  • Loading branch information
peschwa committed Mar 26, 2015
1 parent 9210cc6 commit 91b292d
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/Perl6/Grammar.nqp
Expand Up @@ -344,7 +344,12 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
%*LANG<Q-actions> := Perl6::QActions;
%*LANG<MAIN> := Perl6::Grammar;
%*LANG<MAIN-actions> := Perl6::Actions;


# For tracking how many blocks deep we are nested.
# moreinput needs this to know if it has finished asking
# for more input.
my $*NESTED_BLOCKS := 0;

# Package declarator to meta-package mapping. Starts pretty much empty;
# we get the mappings either imported or supplied by the setting. One
# issue is that we may have no setting to provide them, e.g. when we
Expand Down Expand Up @@ -494,6 +499,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
| <.vws> <.heredoc>
| <.unv>
| <.unsp>
| $ <!MARKED('nomoreinput')> { self.moreinput } <?MARKER('nomoreinput')>
]*
<?MARKER('ws')>
:my $stub := self.'!fresh_highexpect'();
Expand All @@ -509,6 +515,25 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
]*
}

token MOREINPUT {
{ if nqp::getenvhash<DEBUG_PLS> { say("nomoreinput at: " ~ self.pos) } }
[
<?{ $*NESTED_BLOCKS == 0 }> <?MARKER('nomoreinput')>
{ say("and marking as 'nomoreinput'") if nqp::getenvhash<DEBUG_PLS> }
|| <?>
]
}

method moreinput() {
nqp::say("moreinput at: " ~ self.pos) if nqp::getenvhash<DEBUG_PLS>;
return nil if self.MARKED('nomoreinput') && $*NESTED_BLOCKS == 0;
my $old_cursor := self;
$*moreinput(self) if $*moreinput;
$old_cursor.target eq self.target
?? Nil
!! self
}

token vws {
:dba('vertical whitespace')
[
Expand Down Expand Up @@ -1361,13 +1386,15 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
}

token eat_terminator {
[
|| ';'
|| <?MARKED('endstmt')> <.ws>
|| <?before ')' | ']' | '}' >
|| $
|| <?stopper>
|| <?before [if|while|for|loop|repeat|given|when] » > { self.typed_panic( 'X::Syntax::Confused', reason => "Missing semicolon" ) }
|| { $/.CURSOR.typed_panic( 'X::Syntax::Confused', reason => "Confused" ) }
] <?MOREINPUT>
}

token xblock($*IMPLICIT = 0) {
Expand Down Expand Up @@ -1436,7 +1463,9 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
<.finishpad>
[
| '{YOU_ARE_HERE}' <you_are_here>
| :dba('block') '{' ~ '}' <statementlist(1)> <?ENDSTMT>
| :dba('block') '{' ~ '}'
[ { $*NESTED_BLOCKS := $*NESTED_BLOCKS + 1 } <statementlist(1)> { $*NESTED_BLOCKS := $*NESTED_BLOCKS - 1 } ]
<?ENDSTMT>
| <?terminator> { $*W.throw($/, 'X::Syntax::Missing', what =>'block') }
| <?> { $*W.throw($/, 'X::Syntax::Missing', what => 'block') }
]
Expand Down

0 comments on commit 91b292d

Please sign in to comment.