|
1 |
| -using System; |
| 1 | +using System; |
2 | 2 | using System.Collections.Generic;
|
3 | 3 | using System.Runtime.CompilerServices;
|
4 | 4 | using Ara3D.Utils;
|
@@ -100,13 +100,19 @@ public static HashSet<string> GatherFields(Rule r, HashSet<string> fields = null
|
100 | 100 | throw new NotImplementedException($"Unhandled type {r}");
|
101 | 101 | }
|
102 | 102 |
|
103 |
| - public static CodeBuilder OutputNodeClass(CodeBuilder cb, Grammar g, Rule r) |
| 103 | + public static CodeBuilder OutputNodeClass(CodeBuilder cb, Grammar g, Rule r, HashSet<Rule> generated = default) |
104 | 104 | {
|
| 105 | + if (generated is null) |
| 106 | + generated = new HashSet<Rule>(); |
| 107 | + if (generated.Contains(r)) |
| 108 | + return cb; |
| 109 | + generated.Add(r); |
| 110 | + |
105 | 111 | if (r is SequenceRule seq)
|
106 | 112 | {
|
107 | 113 | foreach (var child in seq.Rules)
|
108 | 114 | if (child is NodeRule nr2)
|
109 |
| - OutputNodeClass(cb, g, nr2); |
| 115 | + OutputNodeClass(cb, g, nr2, generated); |
110 | 116 | }
|
111 | 117 |
|
112 | 118 | if (!(r is NodeRule nr))
|
@@ -171,9 +177,10 @@ public static CodeBuilder OutputNodeClass(CodeBuilder cb, Grammar g, Rule r)
|
171 | 177 | public static void OutputCstClasses(CodeBuilder cb, Grammar g)
|
172 | 178 | {
|
173 | 179 | var rules = g.GetRules();
|
| 180 | + var generated = new HashSet<Rule>(); |
174 | 181 | foreach (var r in rules)
|
175 | 182 | {
|
176 |
| - OutputNodeClass(cb, g,r); |
| 183 | + OutputNodeClass(cb, g, r, generated); |
177 | 184 | }
|
178 | 185 | }
|
179 | 186 |
|
|
0 commit comments