From: Claes Jacobsson Date: Sat, 4 Aug 2007 16:00:19 +0000 (+0200) Subject: Re: [PATCH] Adding more information to "Unrecognized character" error in toke.c X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=356c7adf53ddf6b2b7f62f53bc2d999b974db873;p=p5sagit%2Fp5-mst-13.2.git Re: [PATCH] Adding more information to "Unrecognized character" error in toke.c Message-Id: <57CEC660-0020-48DF-A72A-931BCADC2AEE@surfar.nu> p4raw-id: //depot/perl@31699 --- diff --git a/pod/perldiag.pod b/pod/perldiag.pod index 42fcabc..6ebcb64 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -4410,11 +4410,11 @@ reserved word. It's best to put such a word in quotes, or capitalize it somehow, or insert an underbar into it. You might also declare it as a subroutine. -=item Unrecognized character %s +=item Unrecognized character %s in column %d (F) The Perl parser has no idea what to do with the specified character -in your Perl script (or eval). Perhaps you tried to run a compressed -script, a binary program, or a directory as a Perl program. +in your Perl script (or eval) at the specified column. Perhaps you tried +to run a compressed script, a binary program, or a directory as a Perl program. =item Unrecognized escape \\%c in character class passed through in regex; marked by <-- HERE in m/%s/ diff --git a/t/base/lex.t b/t/base/lex.t index 464e68b..f45e56c 100755 --- a/t/base/lex.t +++ b/t/base/lex.t @@ -1,6 +1,6 @@ #!./perl -print "1..55\n"; +print "1..56\n"; $x = 'x'; @@ -263,3 +263,7 @@ print ((exists $str{xyz::bar} ? "" : "not ")."ok $test\n"); ++$test; sub foo::::::bar { print "ok $test\n"; $test++ } foo::::::bar; + +eval "\$x =\xE2foo"; +if ($@ =~ /Unrecognized character \\xE2 in column 5/) { print "ok $test\n"; } else { print "not ok $test\n"; } +$test++; diff --git a/toke.c b/toke.c index ead6806..889e7ec 100644 --- a/toke.c +++ b/toke.c @@ -3561,7 +3561,8 @@ Perl_yylex(pTHX) default: if (isIDFIRST_lazy_if(s,UTF)) goto keylookup; - Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255); + len = UTF ? Perl_utf8_length((U8 *) PL_linestart, (U8 *) s) : (STRLEN) (s - PL_linestart); + Perl_croak(aTHX_ "Unrecognized character \\x%02X in column %d", *s & 255, (int) len + 1); case 4: case 26: goto fake_eof; /* emulate EOF on ^D or ^Z */