summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-06-19 16:22:39 +0200
committerAraq <rumpf_a@web.de>2011-06-19 16:22:39 +0200
commit54021471e40d2cc2ff8f178192ba83873e7f43e0 (patch)
treee4f3090fbf81f34a580df15d9adab639a8d7f769
parentd608e4d11589c7edcace93b731984b67cb26e2d1 (diff)
downloadNim-54021471e40d2cc2ff8f178192ba83873e7f43e0.tar.gz
nicer error messages for used keywords as identifiers
-rwxr-xr-xcompiler/lexer.nim4
-rwxr-xr-xcompiler/parser.nim6
-rwxr-xr-xtodo.txt1
3 files changed, 7 insertions, 4 deletions
diff --git a/compiler/lexer.nim b/compiler/lexer.nim
index 15f874bbd..b2932033d 100755
--- a/compiler/lexer.nim
+++ b/compiler/lexer.nim
@@ -165,6 +165,10 @@ proc tokToStr*(tok: TToken): string =
       InternalError("tokToStr")
       result = ""
   
+proc prettyTok*(tok: TToken): string =
+  if IsKeyword(tok.tokType): result = "keyword " & tok.ident.s
+  else: result = tokToStr(tok)
+  
 proc PrintTok*(tok: TToken) = 
   write(stdout, TokTypeToStr[tok.tokType])
   write(stdout, " ")
diff --git a/compiler/parser.nim b/compiler/parser.nim
index 677aa57ba..42dc0b64b 100755
--- a/compiler/parser.nim
+++ b/compiler/parser.nim
@@ -69,7 +69,7 @@ proc parMessage(p: TParser, msg: TMsgKind, arg: string = "") =
   lexMessage(p.lex, msg, arg)
 
 proc parMessage(p: TParser, msg: TMsgKind, tok: TToken) = 
-  lexMessage(p.lex, msg, tokToStr(tok))
+  lexMessage(p.lex, msg, prettyTok(tok))
 
 proc skipComment(p: var TParser, node: PNode) = 
   if p.tok.tokType == tkComment: 
@@ -92,11 +92,11 @@ proc optInd(p: var TParser, n: PNode) =
 
 proc expectIdentOrKeyw(p: TParser) = 
   if p.tok.tokType != tkSymbol and not isKeyword(p.tok.tokType): 
-    lexMessage(p.lex, errIdentifierExpected, tokToStr(p.tok))
+    lexMessage(p.lex, errIdentifierExpected, prettyTok(p.tok))
   
 proc ExpectIdent(p: TParser) = 
   if p.tok.tokType != tkSymbol: 
-    lexMessage(p.lex, errIdentifierExpected, tokToStr(p.tok))
+    lexMessage(p.lex, errIdentifierExpected, prettyTok(p.tok))
   
 proc Eat(p: var TParser, TokType: TTokType) = 
   if p.tok.TokType == TokType: getTok(p)
diff --git a/todo.txt b/todo.txt
index 2ccd48652..d8988d1a4 100755
--- a/todo.txt
+++ b/todo.txt
@@ -46,7 +46,6 @@ version 0.9.XX
 - generalized case statement (requires better transf)
 - tlastmod returns wrong results on BSD (Linux, MacOS X: works)
 - nested tuple unpacking
-- better error messages for used keywords as identifiers
 - case statement branches should support constant sets
 - 'nimrod def': does not always work
 - test branch coverage