custom integer literals (#17489)
* user defined integer literals; refs #17020 * updated renderer.nim * use mlexerutils helper * imported all test cases from https://github.com/nim-lang/Nim/pull/17020 * final grammar updated
This commit is contained in:
parent
7366a3da37
commit
5f5a92379f
12 changed files with 409 additions and 218 deletions
|
|
@ -942,7 +942,7 @@ proc skipHiddenNodes(n: PNode): PNode =
|
|||
else: break
|
||||
|
||||
proc accentedName(g: var TSrcGen, n: PNode) =
|
||||
const backticksNeeded = OpChars + {'[', '{'}
|
||||
const backticksNeeded = OpChars + {'[', '{', '\''}
|
||||
if n == nil: return
|
||||
let isOperator =
|
||||
if n.kind == nkIdent and n.ident.s.len > 0 and n.ident.s[0] in backticksNeeded: true
|
||||
|
|
@ -976,6 +976,11 @@ proc infixArgument(g: var TSrcGen, n: PNode, i: int) =
|
|||
if needsParenthesis:
|
||||
put(g, tkParRi, ")")
|
||||
|
||||
proc isCustomLit(n: PNode): bool =
|
||||
n.len == 2 and n[0].kind == nkRStrLit and
|
||||
(n[1].kind == nkIdent and n[1].ident.s.startsWith('\'')) or
|
||||
(n[1].kind == nkSym and n[1].sym.name.s.startsWith('\''))
|
||||
|
||||
proc gsub(g: var TSrcGen, n: PNode, c: TContext) =
|
||||
if isNil(n): return
|
||||
var
|
||||
|
|
@ -1195,9 +1200,14 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) =
|
|||
gcomma(g, n, c)
|
||||
put(g, tkBracketRi, "]")
|
||||
of nkDotExpr:
|
||||
gsub(g, n, 0)
|
||||
put(g, tkDot, ".")
|
||||
gsub(g, n, 1)
|
||||
if isCustomLit(n):
|
||||
put(g, tkCustomLit, n[0].strVal)
|
||||
gsub(g, n, 1)
|
||||
else:
|
||||
gsub(g, n, 0)
|
||||
put(g, tkDot, ".")
|
||||
if n.len > 1:
|
||||
accentedName(g, n[1])
|
||||
of nkBind:
|
||||
putWithSpace(g, tkBind, "bind")
|
||||
gsub(g, n, 0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue