Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An if statement isn't parsed correctly if it follows on a sub #234

Closed
p6rt opened this issue Aug 12, 2008 · 14 comments
Closed

An if statement isn't parsed correctly if it follows on a sub #234

p6rt opened this issue Aug 12, 2008 · 14 comments

Comments

@p6rt
Copy link

p6rt commented Aug 12, 2008

Migrated from rt.perl.org#57876 (status was 'resolved')

Searchable as RT57876$

@p6rt
Copy link
Author

p6rt commented Jun 22, 2008

From luben@unixsol.org

There is some parse error for this simpe case​:
==code
use v6;

sub ok ($num){
  $num;
}

for 1..5000 {
  ok($_);
}
==cut

The error message is :

Statement not terminated properly at line 7, near "{ \n ok("
current instr.​: 'parrot;PGE​::Util;die' pc 120 (runtime/parrot/library/PGE/Util.pir​:82)
called from Sub 'parrot;Perl6​::Grammar;eat_terminator' pc 20925 (src/gen_grammar.pir​:2814)
called from Sub 'parrot;Perl6​::Grammar;statementlist' pc 19938 (src/gen_grammar.pir​:2451)
called from Sub 'parrot;Perl6​::Grammar;statement_block' pc 17795 (src/gen_grammar.pir​:1651)
called from Sub 'parrot;Perl6​::Grammar;TOP' pc 14067 (src/gen_grammar.pir​:225)

if we add some statement before the "for" it compiles. For example this is OK​:

==code
use v6;

sub ok ($num){
  $num;
}
;
for 1..5000 {
  ok($_);
}
==cut

Best regards
luben

@p6rt
Copy link
Author

p6rt commented Aug 12, 2008

From @masak

r30183​:
$ ./perl6 -e '
sub x {
}
if 1 {
}'
Statement not terminated properly at line 4, near "{\n}"
[...]

From S04​:

=head1 Statement-ending blocks

A line ending with a closing brace "C<}>", followed by nothing but
whitespace or comments, will terminate a statement if an end of statement
can occur there. That is, these two statements are equivalent​:

  my $x = sub { 3 }
  my $x = sub { 3 };

@p6rt
Copy link
Author

p6rt commented Aug 19, 2008

From @masak

If not actually a duplicate, then at least a close relative of #​56228.

@p6rt
Copy link
Author

p6rt commented Aug 19, 2008

@masak - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Nov 26, 2008

From @chrisdolan

I studied the solution employed by STD.pm for this. STD uses embedded
code to set flags at the end of rules​:

  endstmt = 0 (default) means we have not reached the end of a statement
  endstmt = 1 means we got a terminator or an EOF
  endstmt = 2 means a block just ended

Those flags are set in <block>, <regex_block> and <stdstopper>.

Statement modifiers are forbidden when endstmt == 2.

@p6rt
Copy link
Author

p6rt commented Nov 26, 2008

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Nov 28, 2008

From slavikg@gmail.com

if there is a grammar definition followed by an if statement, even if there
are newlines separating the two. the semi colon is required after the
grammar definition, otherwise rakudo throws an error that the statement is
not properly terminated.

grammar A {
token TOP { \w+ }
}

if ("blah" ~~ A) {
say $/;
}

slavik@​slavik-desktop​:~/code/perl6$ perl6 test.p6
Statement not terminated properly at line 5, near "{\n say $/;"

current instr.​: 'parrot;PGE;Util;die' pc 129
(runtime/parrot/library/PGE/Util.pir​:83)
called from Sub 'parrot;Perl6;Grammar;eat_terminator' pc 26362
(src/gen_grammar.pir​:3387)
called from Sub 'parrot;Perl6;Grammar;statementlist' pc 25018
(src/gen_grammar.pir​:2854)
called from Sub 'parrot;Perl6;Grammar;statement_block' pc 22454
(src/gen_grammar.pir​:1847)
called from Sub 'parrot;Perl6;Grammar;TOP' pc 18348
(src/gen_grammar.pir​:229)
called from Sub 'parrot;PCT;HLLCompiler;parse' pc 640
(src/PCT/HLLCompiler.pir​:390)
called from Sub 'parrot;PCT;HLLCompiler;compile' pc 434
(src/PCT/HLLCompiler.pir​:303)
called from Sub 'parrot;PCT;HLLCompiler;eval' pc 868
(src/PCT/HLLCompiler.pir​:502)
called from Sub 'parrot;PCT;HLLCompiler;evalfiles' pc 1233
(src/PCT/HLLCompiler.pir​:676)
called from Sub 'parrot;PCT;HLLCompiler;command_line' pc 1412
(src/PCT/HLLCompiler.pir​:765)
called from Sub 'parrot;Perl6;Compiler;main' pc 16386 (perl6.pir​:168)
slavik@​slavik-desktop​:~/code/perl6$

@p6rt
Copy link
Author

p6rt commented Nov 29, 2008

From @chrisdolan

This is a variation on "#​56228​: Perl6 grammar bug" which notices that a
"for" after blocks is misparsed as a statement modifier.

Could someone please mark this as duplicate and fix the subject line of
56228 to be more descriptive? I don't have permission to do that...

@p6rt
Copy link
Author

p6rt commented Nov 29, 2008

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Dec 24, 2008

From dwhipp@nvidia.com

(rakudo 34337)

Strange parsing error​:

sub x {
}
while 0 {
  my $b = 1;
}

breaks​: [[[ Statement not terminated properly at line 6, near "{\n
my $" ]]]

If I add a semicolon after to sub decl, then it's happy​:

sub x {
}; ## <--- semicolon here!
while 0 {
  my $b = 1;
}

The strange thing is that it's only happening for "my" decls in the
loop. If I declare the variable earlier, then I can assign it without
problems.


This email message is for the sole use of the intended recipient(s) and may contain
confidential information. Any unauthorized review, use, disclosure or distribution
is prohibited. If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.


@p6rt
Copy link
Author

p6rt commented Dec 26, 2008

From @pmichaud

On Wed Dec 24 07​:38​:04 2008, dwhipp@​nvidia.com wrote​:

(rakudo 34337)

Strange parsing error​:

sub x {
}
while 0 {
my $b = 1;
}

This is the same problem as RT #​57876 -- Rakudo currently sees a
"while", "for", or "if" following a block (such as a sub) to be
a modifier on the block. I'll merge the tickets and see if I can
bump up the priority for fixing that bug.

Pm

@p6rt
Copy link
Author

p6rt commented Dec 26, 2008

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Feb 28, 2009

From @pmichaud

On Sun Jun 22 13​:04​:51 2008, karavelov wrote​:

There is some parse error for this simpe case​:
==code
use v6;

sub ok ($num){
$num;
}

for 1..5000 {
ok($_);
}

This is now fixed in 1e22a68, as well as the other cases where
if/while/until/unless/for... were being incorrectly parsed as statement
modifiers.

Thanks!

Pm

@p6rt p6rt closed this as completed Feb 28, 2009
@p6rt
Copy link
Author

p6rt commented Feb 28, 2009

@pmichaud - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant