mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-27 09:43:58 +00:00
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
This commit is contained in:
81
tests/parser/tparsenewcaseobject.nim
Normal file
81
tests/parser/tparsenewcaseobject.nim
Normal file
@@ -0,0 +1,81 @@
|
||||
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
|
||||
Reference in New Issue
Block a user