@@ -334,13 +334,23 @@ struct ParseTree
334
334
return "Success";
335
335
}
336
336
337
- ParseTree dup() @property
337
+ ParseTree dup() const @property
338
338
{
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();
342
347
return result;
343
348
}
349
+
350
+ immutable(ParseTree) idup() const @property
351
+ {
352
+ return cast(immutable)dup();
353
+ }
344
354
}
345
355
346
356
@@ -372,6 +382,10 @@ unittest // ParseTree testing
372
382
p.children = null;
373
383
assert(q.children != p.children);
374
384
385
+ immutable iq = p.idup;
386
+ q = iq.dup;
387
+ assert(p == q, "Dupping to/from immutable creates equal trees.");
388
+
375
389
q.children = [p,p];
376
390
assert(p != q, "Tree with different children are not equal.");
377
391
@@ -387,7 +401,7 @@ unittest // ParseTree testing
387
401
388
402
/// To compare two trees for content (not bothering with node names)
389
403
/// 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)
391
405
{
392
406
return p1.successful == p2.successful
393
407
&& p1.matches == p2.matches
0 commit comments