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 {
12
12
}
13
13
}
14
14
struct ConvertToSExprListEventHandler {
15
- bool multiple = false ;
15
+ int [] nchildren ;
16
16
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 ) {
18
27
return " ((" ~ escape(text);
19
28
} else {
20
- multiple = true ;
21
- return " (" ~ escape(text);
29
+ return " (" ~ escape(text);
22
30
}
23
31
}
24
32
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-- ;
27
36
return " ))" ;
28
- } else return " ) " ;
37
+ } else {
38
+ nchildren.length-- ;
39
+ return " )" ;
40
+ }
29
41
}
30
42
}
31
43
void main (string [] args) {
You can’t perform that action at this time.
0 commit comments