Skip to content

Instantly share code, notes, and snippets.

@cognominal
Created January 4, 2013 12:32
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save cognominal/4452294 to your computer and use it in GitHub Desktop.
adding a subrule in dec_number to detect a mistake cause parse to faill
I want to get a more precise message for decimal numbers with a dot but not fractionnal part.
The following does not point directly to the mistake :
> 1. + 2
1. + 2
Unsupported use of . to concatenate strings; in Perl 6 please use ~
>
in src/Per6/Grammar.pm, adding a subrule to detect malformed decimal number leads the following setting line not to parse :
nqp::sleep(1e16) while True;
It seems that the cursor is wrong so the rule postcircumfix:sym<( ) calling decint does not find the closing parenthesis
Error while constructing error object:Could not locate compile-time value for symbol Comp::AdHoc
Error while compiling, type X::Comp::AdHoc
payload: Unable to parse expression in argument list; couldn't find final ')'
at line 638, near "e16) while"
current instr.: 'panic' pc 13231 (src/stage2/gen/NQPHLL.pir:4687) (src/stage2/gen/NQPHLL.pm:328)
called from Sub '' pc 31737 (src/gen/perl6-symboltable.pir:11715) (src/Perl6/World.pm:2126)
called from Sub 'typed_exception' pc 29998 (src/gen/perl6-symboltable.pir:11049) (src/Perl6/World.pm:2036)
called from Sub 'throw' pc 29299 (src/gen/perl6-symboltable.pir:10766) (src/Perl6/World.pm:2010)
called from Sub 'typed_panic' pc 11463 (src/gen/perl6-grammar.pir:3991) (src/Perl6/Grammar.pm:216)
called from Sub 'panic' pc 11328 (src/gen/perl6-grammar.pir:3926) (src/Perl6/Grammar.pm:206)
called from Sub 'FAILGOAL' pc 13299 (src/stage2/gen/NQPHLL.pir:4721) (src/stage2/gen/NQPHLL.pm:336)
called from Sub 'postcircumfix:sym<( )>' pc 221053 (src/gen/perl6-grammar.pir:73440) (src/Perl6/Grammar.pm:3050)
Modified dec_number rule
token dec_number {
:dba('decimal number')
[
| $<coeff> = [ '.' <frac=.decint> ] <escale>?
| $<coeff> = [ <int=.decint> '.' <frac=.decint> ] <escale>?
| $<coeff> = [ <int=.decint> ] <escale>
|| <decint> '.' <.malformed: 'decimal number'> # added line
]
}
@cognominal
Copy link
Author

As FROGGS noticed, C<|> binds tighter than C<||> but using the following rule runs into another problem.
It breaks ranges like : 1..2
I would like a way to say, if the parse fail later in the rule calling dec_number it is because dec_number could
have (mis)matched with '.'

token dec_number {
:dba('decimal number')
[
[
| $ = [ '.' <frac=.decint> ] ?
| $ = [ <int=.decint> '.' <frac=.decint> ] ?
| $ = [ <int=.decint> ]
]
|| '.' <.malformed: 'decimal number'> # added line
]
}

See discussion at http://irclog.perlgeek.de/perl6/2013-01-04#i_6297572
Note: I don't know why the initial spaces are lost in this comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment