Skip to content

Commit

Permalink
don't allow identifiers to start with a digit
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Masak committed Jan 19, 2015
1 parent 5bf62a2 commit 662d9bf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/_007/Parser.pm
Expand Up @@ -47,9 +47,13 @@ class Parser {
'' [<statement><.eat_terminator> ]*
}

method panic($what) {
die X::Syntax::Missing.new(:$what);
}

proto token statement {*}
rule statement:my {
my <identifier>
my [<identifier> || <.panic "identifier">]
{
my $symbol = $<identifier>.Str;
my $block = $*runtime.current-frame();
Expand Down Expand Up @@ -198,7 +202,7 @@ class Parser {
}

token identifier {
<[\w:]>+
<!before \d> <[\w:]>+
}

rule arguments {
Expand Down
8 changes: 8 additions & 0 deletions t/syntax/corner-cases.t
Expand Up @@ -280,4 +280,12 @@ use _007::Test;
parse-error $program, X::Redeclaration::Outer, "...same thing, but with an inner macro";
}

{
my $program = q:to/./;
my 5 = "five";
.

parse-error $program, X::Syntax::Missing, "an identifier can not start with a digit";
}

done;

0 comments on commit 662d9bf

Please sign in to comment.