'iterator' as type description

This commit is contained in:
Araq
2012-11-22 08:31:40 +01:00
parent 476f6fc8ee
commit f610d2d221
2 changed files with 9 additions and 3 deletions

View File

@@ -731,7 +731,8 @@ proc parseProcExpr(p: var TParser, isExpr: bool): PNode =
proc isExprStart(p: TParser): bool =
case p.tok.tokType
of tkSymbol, tkAccent, tkOpr, tkNot, tkNil, tkCast, tkIf, tkProc, tkBind,
of tkSymbol, tkAccent, tkOpr, tkNot, tkNil, tkCast, tkIf,
tkProc, tkIterator, tkBind,
tkParLe, tkBracketLe, tkCurlyLe, tkIntLit..tkCharLit, tkVar, tkRef, tkPtr,
tkTuple, tkType, tkWhen, tkCase:
result = true
@@ -811,6 +812,9 @@ proc primary(p: var TParser, skipSuffix = false): PNode =
proc parseTypeDesc(p: var TParser): PNode =
if p.tok.toktype == tkProc: result = parseProcExpr(p, false)
elif p.tok.toktype == tkIterator:
result = parseProcExpr(p, false)
result.kind = nkIteratorTy
else: result = parseExpr(p)
proc parseExprStmt(p: var TParser): PNode =

View File

@@ -70,7 +70,8 @@ exprOrType ::= lowestExpr
| 'tuple' tupleDesc
expr ::= exprOrType
| 'proc' paramList [pragma] ['=' stmt]
| 'proc' paramList [pragma] ['=' stmt]
| 'iterator' paramList [pragma] ['=' stmt]
exprList ::= [expr (comma expr)* [comma]]
@@ -79,6 +80,7 @@ qualifiedIdent ::= symbol ['.' symbol]
typeDesc ::= exprOrType
| 'proc' paramList [pragma]
| 'iterator' paramList [pragma]
macroStmt ::= ':' [stmt] ('of' [exprList] ':' stmt
|'elif' expr ':' stmt
@@ -146,7 +148,7 @@ param ::= symbol (comma symbol)* (':' typeDesc ['=' expr] | '=' expr)
paramList ::= ['(' [param (comma|semicolon param)*] optPar ')'] [':' typeDesc]
genericConstraint ::= 'object' | 'tuple' | 'enum' | 'proc' | 'ref' | 'ptr'
| 'var' | 'distinct' | primary
| 'var' | 'distinct' | 'iterator' | primary
genericConstraints ::= genericConstraint ( '|' optInd genericConstraint )*
genericParam ::= symbol [':' genericConstraints] ['=' expr]