From 3db3c0e3827a9a9bd70a8f635b0e6650c89b2b7b Mon Sep 17 00:00:00 2001 From: flaviut Date: Tue, 3 Jun 2014 10:12:31 -0400 Subject: [PATCH] Generalize accent parsing --- compiler/parser.nim | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/compiler/parser.nim b/compiler/parser.nim index 2f9deb6b3..61816f443 100644 --- a/compiler/parser.nim +++ b/compiler/parser.nim @@ -147,8 +147,10 @@ proc expectIdent(p: TParser) = proc eat(p: var TParser, tokType: TTokType) = ## Move the parser to the next token if the current token is of type ## `tokType`, otherwise error. - if p.tok.tokType == tokType: getTok(p) - else: lexMessage(p.lex, errTokenExpected, TokTypeToStr[tokType]) + if p.tok.tokType == tokType: + getTok(p) + else: + lexMessage(p.lex, errTokenExpected, TokTypeToStr[tokType]) proc parLineInfo(p: TParser): TLineInfo = ## Retrieve the line information associated with the parser's current state. @@ -285,7 +287,7 @@ proc colcom(p: var TParser, n: PNode) = skipComment(p, n) proc parseSymbol(p: var TParser, allowNil = false): PNode = - #| symbol = '`' (KEYW|IDENT|operator|'(' ')'|'[' ']'|'{' '}'|'='|literal)+ '`' + #| symbol = '`' (KEYW|IDENT|operator|'('|')'|'['|']'|'{'|'}'|'='|literal)+ '`' #| | IDENT case p.tok.tokType of tkSymbol: @@ -296,29 +298,16 @@ proc parseSymbol(p: var TParser, allowNil = false): PNode = getTok(p) while true: case p.tok.tokType - of tkBracketLe: - add(result, newIdentNodeP(getIdent"[]", p)) + of tkIntLit..tkCharLit, tkBracketLe, tkBracketRi, tkParLe, tkParRi, + tkCurlyRi, tkCurlyLe, tkEquals: + add(result, newIdentNodeP(getIdent(tokToStr(p.tok)), p)) getTok(p) - eat(p, tkBracketRi) - of tkEquals: - add(result, newIdentNodeP(getIdent"=", p)) - getTok(p) - of tkParLe: - add(result, newIdentNodeP(getIdent"()", p)) - getTok(p) - eat(p, tkParRi) - of tkCurlyLe: - add(result, newIdentNodeP(getIdent"{}", p)) - getTok(p) - eat(p, tkCurlyRi) of tokKeywordLow..tokKeywordHigh, tkSymbol, tkOpr, tkDot, tkDotDot: add(result, newIdentNodeP(p.tok.ident, p)) getTok(p) - of tkIntLit..tkCharLit: - add(result, newIdentNodeP(getIdent(tokToStr(p.tok)), p)) - getTok(p) else: if result.len == 0: + echo repr p.tok parMessage(p, errIdentifierExpected, p.tok) break eat(p, tkAccent)