Skip to content

Commit

Permalink
'with' and 'without' are not keywords anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
Araq committed Sep 30, 2017
1 parent 5cf789a commit 3ccc9c4
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 15 deletions.
4 changes: 2 additions & 2 deletions compiler/lexer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type
tkShl, tkShr, tkStatic,
tkTemplate,
tkTry, tkTuple, tkType, tkUsing,
tkVar, tkWhen, tkWhile, tkWith, tkWithout, tkXor,
tkVar, tkWhen, tkWhile, tkXor,
tkYield, # end of keywords
tkIntLit, tkInt8Lit, tkInt16Lit, tkInt32Lit, tkInt64Lit,
tkUIntLit, tkUInt8Lit, tkUInt16Lit, tkUInt32Lit, tkUInt64Lit,
Expand Down Expand Up @@ -89,7 +89,7 @@ const
"shl", "shr", "static",
"template",
"try", "tuple", "type", "using",
"var", "when", "while", "with", "without", "xor",
"var", "when", "while", "xor",
"yield",
"tkIntLit", "tkInt8Lit", "tkInt16Lit", "tkInt32Lit", "tkInt64Lit",
"tkUIntLit", "tkUInt8Lit", "tkUInt16Lit", "tkUInt32Lit", "tkUInt64Lit",
Expand Down
12 changes: 9 additions & 3 deletions compiler/parser.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1038,9 +1038,15 @@ proc parseTypeDescKAux(p: var TParser, kind: TNodeKind,
optInd(p, result)
if not isOperator(p.tok) and isExprStart(p):
addSon(result, primary(p, mode))
if kind == nkDistinctTy and p.tok.tokType in {tkWith, tkWithout}:
let nodeKind = if p.tok.tokType == tkWith: nkWith
else: nkWithout
if kind == nkDistinctTy and p.tok.tokType == tkSymbol:
# XXX document this feature!
var nodeKind: TNodeKind
if p.tok.ident.s == "with":
nodeKind = nkWith
elif p.tok.ident.s == "without":
nodeKind = nkWithout
else:
return result
getTok(p)
let list = newNodeP(nodeKind, p)
result.addSon list
Expand Down
11 changes: 8 additions & 3 deletions compiler/pbraces.nim
Original file line number Diff line number Diff line change
Expand Up @@ -906,9 +906,14 @@ proc parseTypeDescKAux(p: var TParser, kind: TNodeKind,
optInd(p, result)
if not isOperator(p.tok) and isExprStart(p):
addSon(result, primary(p, mode))
if kind == nkDistinctTy and p.tok.tokType in {tkWith, tkWithout}:
let nodeKind = if p.tok.tokType == tkWith: nkWith
else: nkWithout
if kind == nkDistinctTy and p.tok.tokType == tkSymbol:
var nodeKind: TNodeKind
if p.tok.ident.s == "with":
nodeKind = nkWith
elif p.tok.ident.s == "without":
nodeKind = nkWithout
else:
return result
getTok(p)
let list = newNodeP(nodeKind, p)
result.addSon list
Expand Down
4 changes: 2 additions & 2 deletions compiler/renderer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1079,9 +1079,9 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) =
gsub(g, n.sons[0])
if n.len > 1:
if n[1].kind == nkWith:
putWithSpace(g, tkWith, " with")
putWithSpace(g, tkSymbol, " with")
else:
putWithSpace(g, tkWithout, " without")
putWithSpace(g, tkSymbol, " without")
gcomma(g, n[1])
else:
put(g, tkDistinct, "distinct")
Expand Down
4 changes: 2 additions & 2 deletions compiler/wordrecg.nim
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type
wMacro, wMethod, wMixin, wMod, wNil,
wNot, wNotin, wObject, wOf, wOr, wOut, wProc, wPtr, wRaise, wRef, wReturn,
wShl, wShr, wStatic, wTemplate, wTry, wTuple, wType, wUsing, wVar,
wWhen, wWhile, wWith, wWithout, wXor, wYield,
wWhen, wWhile, wXor, wYield,

wColon, wColonColon, wEquals, wDot, wDotDot,
wStar, wMinus,
Expand Down Expand Up @@ -116,7 +116,7 @@ const
"out", "proc", "ptr", "raise", "ref", "return",
"shl", "shr", "static",
"template", "try", "tuple", "type", "using", "var",
"when", "while", "with", "without", "xor",
"when", "while", "xor",
"yield",

":", "::", "=", ".", "..",
Expand Down
2 changes: 1 addition & 1 deletion doc/keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ shl shr static
template try tuple type
using
var
when while with without
when while
xor
yield
4 changes: 2 additions & 2 deletions lib/packages/docutils/highlite.nim
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ const
"interface", "is", "isnot", "iterator", "let", "macro", "method",
"mixin", "mod", "nil", "not", "notin", "object", "of", "or", "out", "proc",
"ptr", "raise", "ref", "return", "shl", "shr", "static",
"template", "try", "tuple", "type", "using", "var", "when", "while", "with",
"without", "xor", "yield"]
"template", "try", "tuple", "type", "using", "var", "when", "while",
"xor", "yield"]

proc getSourceLanguage*(name: string): SourceLanguage =
for i in countup(succ(low(SourceLanguage)), high(SourceLanguage)):
Expand Down

0 comments on commit 3ccc9c4

Please sign in to comment.