diff --git a/compiler/parser.nim b/compiler/parser.nim index df31a7df8..194b61f2a 100755 --- a/compiler/parser.nim +++ b/compiler/parser.nim @@ -629,7 +629,7 @@ proc parseTuple(p: var TParser): PNode = while (p.tok.tokType == tkSymbol) or (p.tok.tokType == tkAccent): var a = parseIdentColonEquals(p, {}) addSon(result, a) - if p.tok.tokType != tkComma: break + if p.tok.tokType notin {tkComma, tkSemicolon}: break getTok(p) optInd(p, a) optPar(p) @@ -652,7 +652,7 @@ proc parseParamList(p: var TParser, retColon = true): PNode = parMessage(p, errTokenExpected, ")") break addSon(result, a) - if p.tok.tokType != tkComma: break + if p.tok.tokType notin {tkComma, tkSemicolon}: break getTok(p) optInd(p, a) optPar(p) @@ -1135,7 +1135,7 @@ proc parseGenericParamList(p: var TParser): PNode = while (p.tok.tokType == tkSymbol) or (p.tok.tokType == tkAccent): var a = parseGenericParam(p) addSon(result, a) - if p.tok.tokType != tkComma: break + if p.tok.tokType notin {tkComma, tkSemicolon}: break getTok(p) optInd(p, a) optPar(p) diff --git a/compiler/renderer.nim b/compiler/renderer.nim index 58c60834f..5d8a04198 100755 --- a/compiler/renderer.nim +++ b/compiler/renderer.nim @@ -485,14 +485,14 @@ proc putWithSpace(g: var TSrcGen, kind: TTokType, s: string) = put(g, tkSpaces, Space) proc gcommaAux(g: var TSrcGen, n: PNode, ind: int, start: int = 0, - theEnd: int = - 1) = + theEnd: int = - 1, separator = tkComma) = for i in countup(start, sonsLen(n) + theEnd): var c = i < sonsLen(n) + theEnd var sublen = lsub(n.sons[i]) + ord(c) if not fits(g, sublen) and (ind + sublen < maxLineLen): optNL(g, ind) gsub(g, n.sons[i]) if c: - putWithSpace(g, tkComma, ",") + putWithSpace(g, separator, TokTypeToStr[separator]) if hasCom(n.sons[i]): gcoms(g) optNL(g, ind) @@ -512,6 +512,11 @@ proc gcomma(g: var TSrcGen, n: PNode, start: int = 0, theEnd: int = - 1) = if ind > maxLineLen div 2: ind = g.indent + longIndentWid gcommaAux(g, n, ind, start, theEnd) +proc gsemicolon(g: var TSrcGen, n: PNode, start: int = 0, theEnd: int = - 1) = + var ind = g.lineLen + if ind > maxLineLen div 2: ind = g.indent + longIndentWid + gcommaAux(g, n, ind, start, theEnd, tkSemicolon) + proc gsons(g: var TSrcGen, n: PNode, c: TContext, start: int = 0, theEnd: int = - 1) = for i in countup(start, sonsLen(n) + theEnd): gsub(g, n.sons[i], c) @@ -719,7 +724,7 @@ proc gident(g: var TSrcGen, n: PNode) = proc doParamsAux(g: var TSrcGen, params: PNode) = if params.len > 1: put(g, tkParLe, "(") - gcomma(g, params, 1) + gsemicolon(g, params, 1) put(g, tkParRi, ")") if params.sons[0].kind != nkEmpty: @@ -1159,7 +1164,7 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) = put(g, tkBracketRi, "]") of nkFormalParams: put(g, tkParLe, "(") - gcomma(g, n, 1) + gsemicolon(g, n, 1) put(g, tkParRi, ")") if n.sons[0].kind != nkEmpty: putWithSpace(g, tkColon, ":") diff --git a/doc/grammar.txt b/doc/grammar.txt index 4dcb2d3f8..f378cd140 100755 --- a/doc/grammar.txt +++ b/doc/grammar.txt @@ -1,6 +1,8 @@ module ::= ([COMMENT] [SAD] stmt)* comma ::= ',' [COMMENT] [IND] +semicolon ::= ';' [COMMENT] [IND] + operator ::= OP0 | OP1 | OP2 | OP3 | OP4 | OP5 | OP6 | OP7 | OP8 | OP9 | 'or' | 'xor' | 'and' | 'is' | 'isnot' | 'in' | 'notin' | 'of' @@ -141,14 +143,14 @@ fromStmt ::= 'from' filename 'import' symbol (comma symbol)* pragma ::= '{.' optInd (colonExpr [comma])* optPar ('.}' | '}') param ::= symbol (comma symbol)* (':' typeDesc ['=' expr] | '=' expr) -paramList ::= ['(' [param (comma param)*] optPar ')'] [':' typeDesc] +paramList ::= ['(' [param (comma|semicolon param)*] optPar ')'] [':' typeDesc] genericConstraint ::= 'object' | 'tuple' | 'enum' | 'proc' | 'ref' | 'ptr' | 'var' | 'distinct' | primary genericConstraints ::= genericConstraint ( '|' optInd genericConstraint )* genericParam ::= symbol [':' genericConstraints] ['=' expr] -genericParams ::= '[' genericParam (comma genericParam)* optPar ']' +genericParams ::= '[' genericParam (comma|semicolon genericParam)* optPar ']' routineDecl := symbol ['*'] [genericParams] paramList [pragma] ['=' stmt] @@ -180,7 +182,7 @@ objectCase ::= 'case' expr ':' typeDesc [COMMENT] objectPart ::= objectWhen | objectCase | objectIdentPart | 'nil' | indPush objectPart (SAD objectPart)* DED indPop -tupleDesc ::= '[' optInd [param (comma param)*] optPar ']' +tupleDesc ::= '[' optInd [param (comma|semicolon param)*] optPar ']' objectDef ::= 'object' [pragma] ['of' typeDesc] objectPart enumField ::= symbol ['=' expr] diff --git a/todo.txt b/todo.txt index 2b58fc17f..53bdbb53d 100755 --- a/todo.txt +++ b/todo.txt @@ -15,7 +15,7 @@ New pragmas: - document destructors - ``borrow`` needs to take type classes into account -- introduce ``;`` to the parser +- introduce ``;`` to the parser: inc a; inc b - make use of ``tyIter`` to fix the implicit items/pairs issue - ``=`` should be overloadable; requires specialization for ``=`` - optimize genericAssign in the code generator @@ -31,7 +31,6 @@ New pragmas: is that often the scope of ``try`` is wrong and apart from that ``try`` is a full blown statement; a ``try`` expression might be a good idea to make error handling more light-weight - people also want ``inc a; inc b`` Bugs diff --git a/web/news.txt b/web/news.txt index 5529a9e33..9a46a9f04 100755 --- a/web/news.txt +++ b/web/news.txt @@ -128,6 +128,8 @@ Language Additions - Unsigned integer types have been added. - The integer promotion rules changed. - Nimrod now tracks proper intervals for ``range`` over some built-in operators. +- In parameter lists a semicolon instead of a comma can be used to improve + readability: ``proc divmod(a, b: int; resA, resB: var int)``. 2012-02-09 Version 0.8.14 released