File tree Expand file tree Collapse file tree 1 file changed +19
-7
lines changed Expand file tree Collapse file tree 1 file changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -12,20 +12,32 @@ struct ConvertToSExprEventHandler {
1212 }
1313}
1414struct ConvertToSExprListEventHandler {
15- bool multiple = false ;
15+ int [] nchildren ;
1616 string start (string text) {
17- if (multiple) {
17+ int current;
18+ if (nchildren.length) {
19+ nchildren[$- 1 ]++ ;
20+ current = nchildren[$- 1 ];
21+ } else {
22+ current = 0 ;
23+ }
24+ nchildren ~= 0 ;
25+ // If we are starting a list with more than one child, add 2 parens
26+ if (current == 1 ) {
1827 return " ((" ~ escape(text);
1928 } else {
20- multiple = true ;
21- return " (" ~ escape(text);
29+ return " (" ~ escape(text);
2230 }
2331 }
2432 string end () {
25- if (multiple) {
26- multiple = false ;
33+ // If we are ending a list with more than one child, add 2 parens
34+ if (nchildren.length > 0 && nchildren[$- 1 ] > 0 ) {
35+ nchildren.length-- ;
2736 return " ))" ;
28- } else return " ) " ;
37+ } else {
38+ nchildren.length-- ;
39+ return " )" ;
40+ }
2941 }
3042}
3143void main (string [] args) {
You can’t perform that action at this time.
0 commit comments