@@ -300,8 +300,7 @@ private:
300300 writeToken(); // switch
301301 write(" " );
302302 }
303- else if ((currentIs(tok! " version" ) || currentIs(tok! " extern" ))
304- && peekIs(tok! " (" ))
303+ else if (currentIs(tok! " extern" ) && peekIs(tok! " (" ))
305304 {
306305 writeToken();
307306 write(" " );
@@ -326,13 +325,13 @@ private:
326325 if (currentIs(tok! " if" ) || (currentIs(tok! " static" ) && peekIs(tok! " if" ))
327326 || currentIs(tok! " version" ))
328327 {
329- if (indents.top() == tok! " if" )
328+ if (indents.top() == tok! " if" || indents.top == tok ! " version " )
330329 indents.pop();
331330 write(" " );
332331 }
333332 else if (! currentIs(tok! " {" ) && ! currentIs(tok! " comment" ))
334333 {
335- if (indents.top() == tok! " if" )
334+ if (indents.top() == tok! " if" || indents.top == tok ! " version " )
336335 indents.pop();
337336 indents.push(tok! " else" );
338337 newline();
@@ -941,13 +940,14 @@ private:
941940 auto t = tokens[i + index].type;
942941 return t == tok! " for" || t == tok! " foreach"
943942 || t == tok! " foreach_reverse" || t == tok! " while"
944- || t == tok! " if" || t == tok! " out"
943+ || t == tok! " if" || t == tok! " out" || t == tok ! " version "
945944 || t == tok! " catch" || t == tok! " with" ;
946945 }
947946
948947 void newline ()
949948 {
950949 import std.range : assumeSorted;
950+ import std.algorithm : max;
951951
952952 if (currentIs(tok! " comment" ) && current.line == tokenEndLine(tokens[index - 1 ]))
953953 return ;
@@ -976,9 +976,11 @@ private:
976976 bool switchLabel = false ;
977977 if (currentIs(tok! " else" ))
978978 {
979- auto l = indents.indentToMostRecent(tok! " if" );
980- if (l != - 1 )
981- indentLevel = l;
979+ auto i = indents.indentToMostRecent(tok! " if" );
980+ auto v = indents.indentToMostRecent(tok! " version" );
981+ auto mostRecent = max(i, v);
982+ if (mostRecent != - 1 )
983+ indentLevel = mostRecent;
982984 }
983985 else if (currentIs(tok! " identifier" ) && peekIs(tok! " :" ))
984986 {
@@ -1037,7 +1039,8 @@ private:
10371039 indents.pop();
10381040 }
10391041 while (indents.length && isTempIndent(indents.top)
1040- && (indents.top != tok! " if" || ! peekIs(tok! " else" )))
1042+ && ((indents.top != tok! " if" && indents.top != tok! " version" )
1043+ || ! peekIs(tok! " else" )))
10411044 {
10421045 indents.pop();
10431046 }
0 commit comments