Files
Nim/tests/parser/tparsenewcaseobject.nim
metagn 1227799b84 implement parser for new case objects (#24885)
refs https://github.com/nim-lang/RFCs/issues/559

Parses as an `nkIdentDefs` with an `nkEmpty` name. Pragma is allowed,
can remove this if necessary.

Fine to close and postpone for later

(cherry picked from commit 032da90ed1)
2025-04-18 12:50:19 +02:00

82 lines
1.6 KiB
Nim

discard """
nimout: '''
StmtList
TypeSection
TypeDef
Ident "Node"
Empty
RefTy
ObjectTy
Empty
Empty
RecList
RecCase
IdentDefs
Empty
Empty
Empty
OfBranch
Ident "AddOpr"
Ident "SubOpr"
Ident "MulOpr"
Ident "DivOpr"
RecList
IdentDefs
Ident "a"
Ident "b"
Ident "Node"
Empty
OfBranch
Ident "Value"
RecList
NilLit
IdentDefs
Ident "info"
Ident "LineInfo"
Empty
RecCase
IdentDefs
PragmaExpr
Empty
Pragma
ExprColonExpr
Ident "size"
IntLit 1
Empty
Empty
OfBranch
Ident "Foo"
NilLit
type
Node = ref object
case
of AddOpr, SubOpr, MulOpr, DivOpr:
a, b: Node
of Value:
nil
info: LineInfo
case {.size: 1.}
of Foo:
nil
'''
"""
import std/macros
macro foo(x: untyped) =
echo x.treeRepr
echo x.repr
foo:
type
Node = ref object
case
of AddOpr, SubOpr, MulOpr, DivOpr:
a, b: Node
of Value:
discard
info: LineInfo
case {.size: 1.}
of Foo: discard