';' now valid for parameter lists

This commit is contained in:
Araq 2012-07-11 18:17:39 +02:00
commit b4a9aca2d3
5 changed files with 20 additions and 12 deletions

View file

@ -629,7 +629,7 @@ proc parseTuple(p: var TParser): PNode =
while (p.tok.tokType == tkSymbol) or (p.tok.tokType == tkAccent): while (p.tok.tokType == tkSymbol) or (p.tok.tokType == tkAccent):
var a = parseIdentColonEquals(p, {}) var a = parseIdentColonEquals(p, {})
addSon(result, a) addSon(result, a)
if p.tok.tokType != tkComma: break if p.tok.tokType notin {tkComma, tkSemicolon}: break
getTok(p) getTok(p)
optInd(p, a) optInd(p, a)
optPar(p) optPar(p)
@ -652,7 +652,7 @@ proc parseParamList(p: var TParser, retColon = true): PNode =
parMessage(p, errTokenExpected, ")") parMessage(p, errTokenExpected, ")")
break break
addSon(result, a) addSon(result, a)
if p.tok.tokType != tkComma: break if p.tok.tokType notin {tkComma, tkSemicolon}: break
getTok(p) getTok(p)
optInd(p, a) optInd(p, a)
optPar(p) optPar(p)
@ -1135,7 +1135,7 @@ proc parseGenericParamList(p: var TParser): PNode =
while (p.tok.tokType == tkSymbol) or (p.tok.tokType == tkAccent): while (p.tok.tokType == tkSymbol) or (p.tok.tokType == tkAccent):
var a = parseGenericParam(p) var a = parseGenericParam(p)
addSon(result, a) addSon(result, a)
if p.tok.tokType != tkComma: break if p.tok.tokType notin {tkComma, tkSemicolon}: break
getTok(p) getTok(p)
optInd(p, a) optInd(p, a)
optPar(p) optPar(p)

View file

@ -485,14 +485,14 @@ proc putWithSpace(g: var TSrcGen, kind: TTokType, s: string) =
put(g, tkSpaces, Space) put(g, tkSpaces, Space)
proc gcommaAux(g: var TSrcGen, n: PNode, ind: int, start: int = 0, 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): for i in countup(start, sonsLen(n) + theEnd):
var c = i < sonsLen(n) + theEnd var c = i < sonsLen(n) + theEnd
var sublen = lsub(n.sons[i]) + ord(c) var sublen = lsub(n.sons[i]) + ord(c)
if not fits(g, sublen) and (ind + sublen < maxLineLen): optNL(g, ind) if not fits(g, sublen) and (ind + sublen < maxLineLen): optNL(g, ind)
gsub(g, n.sons[i]) gsub(g, n.sons[i])
if c: if c:
putWithSpace(g, tkComma, ",") putWithSpace(g, separator, TokTypeToStr[separator])
if hasCom(n.sons[i]): if hasCom(n.sons[i]):
gcoms(g) gcoms(g)
optNL(g, ind) 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 if ind > maxLineLen div 2: ind = g.indent + longIndentWid
gcommaAux(g, n, ind, start, theEnd) 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, proc gsons(g: var TSrcGen, n: PNode, c: TContext, start: int = 0,
theEnd: int = - 1) = theEnd: int = - 1) =
for i in countup(start, sonsLen(n) + theEnd): gsub(g, n.sons[i], c) 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) = proc doParamsAux(g: var TSrcGen, params: PNode) =
if params.len > 1: if params.len > 1:
put(g, tkParLe, "(") put(g, tkParLe, "(")
gcomma(g, params, 1) gsemicolon(g, params, 1)
put(g, tkParRi, ")") put(g, tkParRi, ")")
if params.sons[0].kind != nkEmpty: if params.sons[0].kind != nkEmpty:
@ -1159,7 +1164,7 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) =
put(g, tkBracketRi, "]") put(g, tkBracketRi, "]")
of nkFormalParams: of nkFormalParams:
put(g, tkParLe, "(") put(g, tkParLe, "(")
gcomma(g, n, 1) gsemicolon(g, n, 1)
put(g, tkParRi, ")") put(g, tkParRi, ")")
if n.sons[0].kind != nkEmpty: if n.sons[0].kind != nkEmpty:
putWithSpace(g, tkColon, ":") putWithSpace(g, tkColon, ":")

View file

@ -1,6 +1,8 @@
module ::= ([COMMENT] [SAD] stmt)* module ::= ([COMMENT] [SAD] stmt)*
comma ::= ',' [COMMENT] [IND] comma ::= ',' [COMMENT] [IND]
semicolon ::= ';' [COMMENT] [IND]
operator ::= OP0 | OP1 | OP2 | OP3 | OP4 | OP5 | OP6 | OP7 | OP8 | OP9 operator ::= OP0 | OP1 | OP2 | OP3 | OP4 | OP5 | OP6 | OP7 | OP8 | OP9
| 'or' | 'xor' | 'and' | 'or' | 'xor' | 'and'
| 'is' | 'isnot' | 'in' | 'notin' | 'of' | 'is' | 'isnot' | 'in' | 'notin' | 'of'
@ -141,14 +143,14 @@ fromStmt ::= 'from' filename 'import' symbol (comma symbol)*
pragma ::= '{.' optInd (colonExpr [comma])* optPar ('.}' | '}') pragma ::= '{.' optInd (colonExpr [comma])* optPar ('.}' | '}')
param ::= symbol (comma symbol)* (':' typeDesc ['=' expr] | '=' expr) 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' genericConstraint ::= 'object' | 'tuple' | 'enum' | 'proc' | 'ref' | 'ptr'
| 'var' | 'distinct' | primary | 'var' | 'distinct' | primary
genericConstraints ::= genericConstraint ( '|' optInd genericConstraint )* genericConstraints ::= genericConstraint ( '|' optInd genericConstraint )*
genericParam ::= symbol [':' genericConstraints] ['=' expr] genericParam ::= symbol [':' genericConstraints] ['=' expr]
genericParams ::= '[' genericParam (comma genericParam)* optPar ']' genericParams ::= '[' genericParam (comma|semicolon genericParam)* optPar ']'
routineDecl := symbol ['*'] [genericParams] paramList [pragma] ['=' stmt] routineDecl := symbol ['*'] [genericParams] paramList [pragma] ['=' stmt]
@ -180,7 +182,7 @@ objectCase ::= 'case' expr ':' typeDesc [COMMENT]
objectPart ::= objectWhen | objectCase | objectIdentPart | 'nil' objectPart ::= objectWhen | objectCase | objectIdentPart | 'nil'
| indPush objectPart (SAD objectPart)* DED indPop | 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 objectDef ::= 'object' [pragma] ['of' typeDesc] objectPart
enumField ::= symbol ['=' expr] enumField ::= symbol ['=' expr]

View file

@ -15,7 +15,7 @@ New pragmas:
- document destructors - document destructors
- ``borrow`` needs to take type classes into account - ``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 - make use of ``tyIter`` to fix the implicit items/pairs issue
- ``=`` should be overloadable; requires specialization for ``=`` - ``=`` should be overloadable; requires specialization for ``=``
- optimize genericAssign in the code generator - 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 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 a full blown statement; a ``try`` expression might be a good idea to make
error handling more light-weight error handling more light-weight
people also want ``inc a; inc b``
Bugs Bugs

View file

@ -128,6 +128,8 @@ Language Additions
- Unsigned integer types have been added. - Unsigned integer types have been added.
- The integer promotion rules changed. - The integer promotion rules changed.
- Nimrod now tracks proper intervals for ``range`` over some built-in operators. - 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 2012-02-09 Version 0.8.14 released