parsing of user defined type classes
This commit is contained in:
parent
56d75bd23b
commit
037a1a3e0f
3 changed files with 35 additions and 2 deletions
|
|
@ -190,6 +190,7 @@ type
|
||||||
nkTypeOfExpr, # type(1+2)
|
nkTypeOfExpr, # type(1+2)
|
||||||
nkObjectTy, # object body
|
nkObjectTy, # object body
|
||||||
nkTupleTy, # tuple body
|
nkTupleTy, # tuple body
|
||||||
|
nkTypeClassTy, # user-defined type class
|
||||||
nkRecList, # list of object parts
|
nkRecList, # list of object parts
|
||||||
nkRecCase, # case section of object
|
nkRecCase, # case section of object
|
||||||
nkRecWhen, # when section of object
|
nkRecWhen, # when section of object
|
||||||
|
|
|
||||||
|
|
@ -927,9 +927,10 @@ proc parseExpr(p: var TParser): PNode =
|
||||||
of tkTry: result = parseTry(p)
|
of tkTry: result = parseTry(p)
|
||||||
else: result = simpleExpr(p)
|
else: result = simpleExpr(p)
|
||||||
|
|
||||||
|
proc parseEnum(p: var TParser): PNode
|
||||||
proc parseObject(p: var TParser): PNode
|
proc parseObject(p: var TParser): PNode
|
||||||
proc parseDistinct(p: var TParser): PNode
|
proc parseDistinct(p: var TParser): PNode
|
||||||
proc parseEnum(p: var TParser): PNode
|
proc parseTypeClass(p: var TParser): PNode
|
||||||
|
|
||||||
proc primary(p: var TParser, mode: TPrimaryMode): PNode =
|
proc primary(p: var TParser, mode: TPrimaryMode): PNode =
|
||||||
#| typeKeyw = 'var' | 'ref' | 'ptr' | 'shared' | 'type' | 'tuple'
|
#| typeKeyw = 'var' | 'ref' | 'ptr' | 'shared' | 'type' | 'tuple'
|
||||||
|
|
@ -983,6 +984,11 @@ proc primary(p: var TParser, mode: TPrimaryMode): PNode =
|
||||||
else:
|
else:
|
||||||
result = newNodeP(nkObjectTy, p)
|
result = newNodeP(nkObjectTy, p)
|
||||||
getTok(p)
|
getTok(p)
|
||||||
|
of tkGeneric:
|
||||||
|
if mode == pmTypeDef:
|
||||||
|
result = parseTypeClass(p)
|
||||||
|
else:
|
||||||
|
parMessage(p, errInvalidToken, p.tok)
|
||||||
of tkDistinct:
|
of tkDistinct:
|
||||||
if mode == pmTypeDef:
|
if mode == pmTypeDef:
|
||||||
result = parseDistinct(p)
|
result = parseDistinct(p)
|
||||||
|
|
@ -1613,6 +1619,32 @@ proc parseObject(p: var TParser): PNode =
|
||||||
return
|
return
|
||||||
addSon(result, parseObjectPart(p))
|
addSon(result, parseObjectPart(p))
|
||||||
|
|
||||||
|
proc parseTypeClass(p: var TParser): PNode =
|
||||||
|
result = newNodeP(nkTypeClassTy, p)
|
||||||
|
getTok(p)
|
||||||
|
addSon(result, p.parseSymbol)
|
||||||
|
if p.tok.tokType == tkCurlyDotLe and p.validInd:
|
||||||
|
addSon(result, parsePragma(p))
|
||||||
|
else:
|
||||||
|
addSon(result, ast.emptyNode)
|
||||||
|
if p.tok.tokType == tkOf and p.tok.indent < 0:
|
||||||
|
var a = newNodeP(nkOfInherit, p)
|
||||||
|
getTok(p)
|
||||||
|
while true:
|
||||||
|
addSon(a, parseTypeDesc(p))
|
||||||
|
if p.tok.tokType != tkComma: break
|
||||||
|
getTok(p)
|
||||||
|
addSon(result, a)
|
||||||
|
else:
|
||||||
|
addSon(result, ast.emptyNode)
|
||||||
|
if p.tok.tokType == tkComment:
|
||||||
|
skipComment(p, result)
|
||||||
|
# an initial IND{>} HAS to follow:
|
||||||
|
if not realInd(p):
|
||||||
|
addSon(result, emptyNode)
|
||||||
|
else:
|
||||||
|
addSon(result, parseStmt(p))
|
||||||
|
|
||||||
proc parseDistinct(p: var TParser): PNode =
|
proc parseDistinct(p: var TParser): PNode =
|
||||||
#| distinct = 'distinct' optInd typeDesc
|
#| distinct = 'distinct' optInd typeDesc
|
||||||
result = newNodeP(nkDistinctTy, p)
|
result = newNodeP(nkDistinctTy, p)
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ type
|
||||||
nnkBindStmt, nnkMixinStmt,
|
nnkBindStmt, nnkMixinStmt,
|
||||||
nnkCommentStmt, nnkStmtListExpr, nnkBlockExpr,
|
nnkCommentStmt, nnkStmtListExpr, nnkBlockExpr,
|
||||||
nnkStmtListType, nnkBlockType, nnkTypeOfExpr, nnkObjectTy,
|
nnkStmtListType, nnkBlockType, nnkTypeOfExpr, nnkObjectTy,
|
||||||
nnkTupleTy, nnkRecList, nnkRecCase, nnkRecWhen,
|
nnkTupleTy, nnkTypeClassTy, nnkRecList, nnkRecCase, nnkRecWhen,
|
||||||
nnkRefTy, nnkPtrTy, nnkVarTy,
|
nnkRefTy, nnkPtrTy, nnkVarTy,
|
||||||
nnkConstTy, nnkMutableTy,
|
nnkConstTy, nnkMutableTy,
|
||||||
nnkDistinctTy,
|
nnkDistinctTy,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue