nicer error messages for used keywords as identifiers
This commit is contained in:
parent
d608e4d115
commit
54021471e4
3 changed files with 7 additions and 4 deletions
|
|
@ -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, " ")
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue