File tree Expand file tree Collapse file tree 3 files changed +101
-4
lines changed Expand file tree Collapse file tree 3 files changed +101
-4
lines changed Original file line number Diff line number Diff line change @@ -2110,12 +2110,28 @@ proc parseObjectCase(p: var Parser): PNode =
2110
2110
# | objectBranches = objectBranch (IND{=} objectBranch)*
2111
2111
# | (IND{=} 'elif' expr colcom objectPart)*
2112
2112
# | (IND{=} 'else' colcom objectPart)?
2113
- # | objectCase = 'case' declColonEquals ':'? COMMENT?
2113
+ # | objectCase = 'case' ( declColonEquals / pragma)? ':'? COMMENT?
2114
2114
# | (IND{>} objectBranches DED
2115
2115
# | | IND{=} objectBranches)
2116
2116
result = newNodeP(nkRecCase, p)
2117
- getTokNoInd(p)
2118
- var a = parseIdentColonEquals(p, {withPragma})
2117
+ getTok(p)
2118
+ if p.tok.tokType != tkOf:
2119
+ # of case will be handled later
2120
+ if p.tok.indent >= 0 : parMessage(p, errInvalidIndentation)
2121
+ var a: PNode
2122
+ if p.tok.tokType in {tkSymbol, tkAccent}:
2123
+ a = parseIdentColonEquals(p, {withPragma})
2124
+ else :
2125
+ a = newNodeP(nkIdentDefs, p)
2126
+ if p.tok.tokType == tkCurlyDotLe:
2127
+ var prag = newNodeP(nkPragmaExpr, p)
2128
+ prag.add(p.emptyNode)
2129
+ prag.add(parsePragma(p))
2130
+ a.add(prag)
2131
+ else :
2132
+ a.add(p.emptyNode)
2133
+ a.add(p.emptyNode)
2134
+ a.add(p.emptyNode)
2119
2135
result .add(a)
2120
2136
if p.tok.tokType == tkColon: getTok(p)
2121
2137
flexComment(p, result )
Original file line number Diff line number Diff line change @@ -181,7 +181,7 @@ objectBranch = 'of' exprList colcom objectPart
181
181
objectBranches = objectBranch (IND{=} objectBranch)*
182
182
(IND{=} 'elif' expr colcom objectPart)*
183
183
(IND{=} 'else' colcom objectPart)?
184
- objectCase = 'case' declColonEquals ':'? COMMENT?
184
+ objectCase = 'case' ( declColonEquals / pragma)? ':'? COMMENT?
185
185
(IND{>} objectBranches DED
186
186
| IND{=} objectBranches)
187
187
objectPart = IND{>} objectPart^+IND{=} DED
Original file line number Diff line number Diff line change
1
+ discard """
2
+ nimout: '''
3
+ StmtList
4
+ TypeSection
5
+ TypeDef
6
+ Ident "Node"
7
+ Empty
8
+ RefTy
9
+ ObjectTy
10
+ Empty
11
+ Empty
12
+ RecList
13
+ RecCase
14
+ IdentDefs
15
+ Empty
16
+ Empty
17
+ Empty
18
+ OfBranch
19
+ Ident "AddOpr"
20
+ Ident "SubOpr"
21
+ Ident "MulOpr"
22
+ Ident "DivOpr"
23
+ RecList
24
+ IdentDefs
25
+ Ident "a"
26
+ Ident "b"
27
+ Ident "Node"
28
+ Empty
29
+ OfBranch
30
+ Ident "Value"
31
+ RecList
32
+ NilLit
33
+ IdentDefs
34
+ Ident "info"
35
+ Ident "LineInfo"
36
+ Empty
37
+ RecCase
38
+ IdentDefs
39
+ PragmaExpr
40
+ Empty
41
+ Pragma
42
+ ExprColonExpr
43
+ Ident "size"
44
+ IntLit 1
45
+ Empty
46
+ Empty
47
+ OfBranch
48
+ Ident "Foo"
49
+ NilLit
50
+
51
+ type
52
+ Node = ref object
53
+ case
54
+ of AddOpr, SubOpr, MulOpr, DivOpr:
55
+ a, b: Node
56
+ of Value:
57
+ nil
58
+ info: LineInfo
59
+ case {.size: 1.}
60
+ of Foo:
61
+ nil
62
+ '''
63
+ """
64
+
65
+ import std/ macros
66
+
67
+ macro foo(x: untyped ) =
68
+ echo x.treeRepr
69
+ echo x.repr
70
+
71
+ foo:
72
+ type
73
+ Node = ref object
74
+ case
75
+ of AddOpr, SubOpr, MulOpr, DivOpr:
76
+ a, b: Node
77
+ of Value:
78
+ discard
79
+ info: LineInfo
80
+ case {.size: 1 .}
81
+ of Foo: discard
You can’t perform that action at this time.
0 commit comments