summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2009-01-31 16:42:10 -0800
committerRob Pike <r@golang.org>2009-01-31 16:42:10 -0800
commit5bfbe0e397ca25decaccc880831623a39d0c9720 (patch)
treeb12e61147ab0c69914a655725384045a510df23b
parent273cf152a44cc32b63157b29b94fb5dea0237055 (diff)
downloadgolang-5bfbe0e397ca25decaccc880831623a39d0c9720.tar.gz
Complain about control characters that are not white space.
Bitten by invisible chars too many times. R=ken OCL=24024 CL=24024
-rw-r--r--src/cmd/gc/lex.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/cmd/gc/lex.c b/src/cmd/gc/lex.c
index 7e16fa927..a4f12313e 100644
--- a/src/cmd/gc/lex.c
+++ b/src/cmd/gc/lex.c
@@ -299,6 +299,21 @@ cannedimports(char *file, char *cp)
inimportsys = 1;
}
+int
+isfrog(int c) {
+ // complain about possibly invisible control characters
+ if(c < 0)
+ return 1;
+ if(c < ' ') {
+ if(c == ' ' || c == '\n' || c== '\r' || c == '\t') // good white space
+ return 0;
+ return 1;
+ }
+ if(0x80 <= c && c <=0xa0) // unicode block including unbreakable space.
+ return 1;
+ return 0;
+}
+
int32
yylex(void)
{
@@ -645,6 +660,10 @@ lx:
DBG("%L lex: TOKEN %s\n", lineno, lexname(c));
else
DBG("%L lex: TOKEN '%c'\n", lineno, c);
+ if(isfrog(c)) {
+ yyerror("illegal character 0x%ux", c);
+ goto l0;
+ }
return c;
asop:
@@ -661,8 +680,14 @@ talph:
if(c >= Runeself) {
for(c1=0;;) {
cp[c1++] = c;
- if(fullrune(cp, c1))
+ if(fullrune(cp, c1)) {
+ chartorune(&rune, cp);
+ if(isfrog(rune)) {
+ yyerror("illegal character 0x%ux", rune);
+ goto l0;
+ }
break;
+ }
c = getc();
}
cp += c1;