Fix more stupid bugs

This commit is contained in:
Hackerpilot 2015-02-18 00:47:32 -08:00
parent a124e2dfc9
commit 52d088d934
1 changed files with 35 additions and 39 deletions

View File

@ -176,30 +176,26 @@ private:
assert (index < tokens.length); assert (index < tokens.length);
if (current.type == tok!"comment") if (current.type == tok!"comment")
{ {
const i = index; if (index > 0)
if (i > 0)
{ {
if (tokens[i-1].line < current.line) if (tokens[index - 1].line + 1 < tokens[index].line)
{ newline();
if (tokens[i-1].type != tok!"comment" else if (tokens[index - 1].line == tokens[index].line)
&& tokens[i-1].type != tok!"{")
newline();
}
else
write(" "); write(" ");
} }
writeToken(); writeToken();
if (i >= tokens.length-1) if (tokens[index - 1].text[0 .. 2] == "//")
newline(); newline();
else if (tokens[i+1].line-1 > tokens[i].line) else if (index < tokens.length)
{ {
newline(); if (tokens[index - 1].line == tokens[index].line)
newline(); {
if (tokens[index].type != tok!"{")
write(" ");
}
else
newline();
} }
else if (tokens[i+1].line > tokens[i].line)
newline();
else if (tokens[i+1].type != tok!"{")
write(" ");
} }
else if (isStringLiteral(current.type) || isNumberLiteral(current.type) else if (isStringLiteral(current.type) || isNumberLiteral(current.type)
|| current.type == tok!"characterLiteral") || current.type == tok!"characterLiteral")
@ -274,7 +270,6 @@ private:
|| current.type == tok!"if" || current.type == tok!"out" || current.type == tok!"if" || current.type == tok!"out"
|| current.type == tok!"catch") || current.type == tok!"catch")
{ {
currentLineLength += currentTokenLength() + 1;
writeToken(); writeToken();
write(" "); write(" ");
writeParens(false); writeParens(false);
@ -507,7 +502,7 @@ private:
break; break;
case tok!")": case tok!")":
parenDepth--; parenDepth--;
if (parenDepth == 0) if (parenDepth <= 0)
break loop; break loop;
l++; l++;
i++; i++;
@ -517,8 +512,6 @@ private:
break loop; break loop;
default: default:
l += tokenLength(i); l += tokenLength(i);
if (isBasicType(tokens[i].type) || tokens[i].type == tok!"identifier")
l++;
i++; i++;
} }
return l; return l;
@ -727,6 +720,7 @@ private:
case tok!"stringLiteral": case tok!"stringLiteral":
case tok!"wstringLiteral": case tok!"wstringLiteral":
case tok!"dstringLiteral": case tok!"dstringLiteral":
// TODO: Unicode line breaks and old-Mac line endings
auto c = cast(int) tokens[i].text.countUntil('\n'); auto c = cast(int) tokens[i].text.countUntil('\n');
if (c == -1) if (c == -1)
return cast(int) tokens[i].text.length; return cast(int) tokens[i].text.length;
@ -749,24 +743,26 @@ private:
return tokenLength(i); return tokenLength(i);
} }
int distanceToNextPreferredBreak() pure @safe @nogc int distanceToNextPreferredBreak() pure @safe @nogc
{ {
size_t i = index + 1; size_t i = index + 1;
int l; int l;
loop: while (i < tokens.length) switch (tokens[i].type) loop: while (i < tokens.length) switch (tokens[i].type)
{ {
case tok!"||": case tok!"||":
case tok!"&&": case tok!"&&":
case tok!";": case tok!";":
case tok!")": case tok!")":
break loop; case tok!",":
default: case tok!"(":
l += tokenLength(i); break loop;
i++; default:
break; l += tokenLength(i);
} i++;
return l; break;
} }
return l;
}
ref current() const @property ref current() const @property
in in