Skip to content

Commit

Permalink
modify lexer to allow underscored idents in accent quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
Vindaar committed Sep 17, 2018
1 parent 9c6dde1 commit d047887
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions compiler/lexer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ type
# needs so much look-ahead
currLineIndent*: int
strongSpaces*, allowTabs*: bool
inAccent*: int # if this is 1, we're inside backticks. Used to
# allow underscored identifiers in accented
# quotes
cursor*: CursorPosition
errorHandler*: TErrorHandler
cache*: IdentCache
Expand Down Expand Up @@ -840,7 +843,8 @@ proc getSymbol(L: var TLexer, tok: var TToken) =
h = h !& ord(c)
inc(pos)
of '_':
if buf[pos+1] notin SymChars:
# trailing underscore allowed if we're within accents
if buf[pos+1] notin SymChars and L.inAccent == 0:
lexMessage(L, errGenerated, "invalid token: trailing underscore")
break
inc(pos)
Expand Down Expand Up @@ -1234,10 +1238,13 @@ proc rawGetTok*(L: var TLexer, tok: var TToken) =
inc(L.bufpos)
of '`':
tok.tokType = tkAccent
# toggle `inAccent` field. Used in the case where we are quoting
# some symbols and concating with `someIdent_ symbol`
L.inAccent = L.inAccent xor 1
inc(L.bufpos)
of '_':
inc(L.bufpos)
if L.buf[L.bufpos] notin SymChars+{'_'}:
if L.buf[L.bufpos] notin SymChars+{'_'} or L.inAccent == 1:
tok.tokType = tkSymbol
tok.ident = L.cache.getIdent("_")
else:
Expand Down

0 comments on commit d047887

Please sign in to comment.