parser: concept of (#25878)

Co-authored-by: Gerke Max Preussner <gmpreussner@headcrash.industries>
This commit is contained in:
Andreas Rumpf
2026-06-08 11:32:04 +02:00
committed by GitHub
parent c84764a097
commit d9e28aac8e
2 changed files with 9 additions and 5 deletions

View File

@@ -2241,14 +2241,17 @@ proc parseTypeClassParam(p: var Parser): PNode =
proc parseTypeClass(p: var Parser): PNode =
#| conceptParam = ('var' | 'out' | 'ptr' | 'ref' | 'static' | 'type')? symbol
#| conceptDecl = 'concept' conceptParam ^* ',' (pragma)? ('of' typeDesc ^* ',')?
#| conceptDecl = 'concept' (conceptParam ^* ',' (pragma)?)? ('of' typeDesc ^* ',')?
#| &IND{>} stmt
result = newNodeP(nkTypeClassTy, p)
getTok(p)
if p.tok.tokType == tkComment:
skipComment(p, result)
if p.tok.indent < 0:
if p.tok.tokType == tkOf and p.tok.indent < 0:
# new-styled `concept of A, B` on the same line as `concept`
result.add(p.emptyNode)
elif p.tok.indent < 0:
var args = newNodeP(nkArgList, p)
result.add(args)
args.add(p.parseTypeClassParam)
@@ -2274,9 +2277,10 @@ proc parseTypeClass(p: var Parser): PNode =
result.add(p.emptyNode)
if p.tok.tokType == tkComment:
skipComment(p, result)
# an initial IND{>} HAS to follow:
# an initial IND{>} HAS to follow, unless this concept inherits requirements:
if not realInd(p):
if result.isNewStyleConcept:
let hasParents = result[2].kind != nkEmpty
if result.isNewStyleConcept and not hasParents:
parMessage(p, "routine expected, but found '$1' (empty new-styled concepts are not allowed)", p.tok)
result.add(p.emptyNode)
else:

View File

@@ -188,7 +188,7 @@ objectPart = IND{>} objectPart^+IND{=} DED
/ objectWhen / objectCase / 'nil' / 'discard' / declColonEquals
objectDecl = 'object' ('of' typeDesc)? COMMENT? objectPart
conceptParam = ('var' | 'out' | 'ptr' | 'ref' | 'static' | 'type')? symbol
conceptDecl = 'concept' conceptParam ^* ',' (pragma)? ('of' typeDesc ^* ',')?
conceptDecl = 'concept' (conceptParam ^* ',' (pragma)?)? ('of' typeDesc ^* ',')?
&IND{>} stmt
typeDef = identVisDot genericParamList? pragma '=' optInd typeDefValue
indAndComment?