Phase 8.4: const func syntax — compile-time function declarations

This commit is contained in:
2026-05-31 13:50:25 +03:00
parent 98d1354b7a
commit f6f122b4e4
5 changed files with 9 additions and 2 deletions
+8 -2
View File
@@ -889,7 +889,7 @@ proc parseParamList(p: var Parser, allowVariadic: bool = false): seq[Param] =
discard p.advance()
discard p.expect(tkRParen, "expected ')' to close parameter list")
proc parseFuncDecl(p: var Parser, isPublic: bool, isAsm: bool, attrs: ParsedAttrs): Decl =
proc parseFuncDecl(p: var Parser, isPublic: bool, isAsm: bool, attrs: ParsedAttrs, isConst: bool = false): Decl =
let loc = p.currentLoc
discard p.expect(tkFunc, "expected 'func'")
let name = p.expect(tkIdent, "expected function name").text
@@ -909,6 +909,7 @@ proc parseFuncDecl(p: var Parser, isPublic: bool, isAsm: bool, attrs: ParsedAttr
return Decl(kind: dkFunc, loc: loc, isPublic: isPublic,
declAttrs: declAttrs,
declFuncAsm: isAsm, declFuncCallConv: attrs.callConv,
declFuncConst: isConst,
declFuncName: name, declFuncTypeParams: typeParams,
declFuncParams: params, declFuncReturnType: retType,
declFuncBody: body)
@@ -1186,9 +1187,14 @@ proc parseDecl(p: var Parser): Decl =
if p.check(tkAt):
attrs = p.parseAttrs()
var isConst = false
if p.check(tkConst) and p.peek(1) == tkFunc:
isConst = true
discard p.advance()
case p.peek()
of tkFunc:
return p.parseFuncDecl(isPublic, false, attrs)
return p.parseFuncDecl(isPublic, false, attrs, isConst)
of tkStruct:
return p.parseStructDecl(isPublic)
of tkEnum: