@@ -334,13 +334,23 @@ struct ParseTree
334334 return "Success";
335335 }
336336
337- ParseTree dup() @property
337+ ParseTree dup() const @property
338338 {
339- ParseTree result = this;
340- result.matches = result.matches.dup;
341- result.children = map!(p => p.dup)(result.children).array();
339+ ParseTree result;
340+ result.name = name;
341+ result.successful = successful;
342+ result.matches = matches.dup;
343+ result.input = input;
344+ result.begin = begin;
345+ result.end = end;
346+ result.children = map!(p => p.dup)(children).array();
342347 return result;
343348 }
349+
350+ immutable(ParseTree) idup() const @property
351+ {
352+ return cast(immutable)dup();
353+ }
344354}
345355
346356
@@ -372,6 +382,10 @@ unittest // ParseTree testing
372382 p.children = null;
373383 assert(q.children != p.children);
374384
385+ immutable iq = p.idup;
386+ q = iq.dup;
387+ assert(p == q, "Dupping to/from immutable creates equal trees.");
388+
375389 q.children = [p,p];
376390 assert(p != q, "Tree with different children are not equal.");
377391
@@ -387,7 +401,7 @@ unittest // ParseTree testing
387401
388402/// To compare two trees for content (not bothering with node names)
389403/// That's useful to compare the results from two different grammars.
390- bool softCompare(ParseTree p1, ParseTree p2)
404+ bool softCompare(const ParseTree p1, const ParseTree p2)
391405{
392406 return p1.successful == p2.successful
393407 && p1.matches == p2.matches
0 commit comments