Fixed filtering of comments, whitespace, etc.
This commit is contained in:
parent
bd97d1b393
commit
f4b001f623
|
@ -206,10 +206,39 @@ class TokenRange(R) : InputRange!(Token)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override void popFront()
|
||||||
|
{
|
||||||
|
// Filter out tokens we don't care about
|
||||||
|
loop: do
|
||||||
|
{
|
||||||
|
advance();
|
||||||
|
switch (current.type)
|
||||||
|
{
|
||||||
|
case TokenType.Comment:
|
||||||
|
if (iterStyle & IterationStyle.IncludeComments)
|
||||||
|
break loop;
|
||||||
|
break;
|
||||||
|
case TokenType.Whitespace:
|
||||||
|
if (iterStyle & IterationStyle.IncludeWhitespace)
|
||||||
|
break loop;
|
||||||
|
break;
|
||||||
|
case TokenType.SpecialTokenSequence:
|
||||||
|
if (iterStyle & IterationStyle.IncludeSpecialTokens)
|
||||||
|
break loop;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break loop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (!empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the current token from the range
|
* Advances the range to the next token
|
||||||
*/
|
*/
|
||||||
override void popFront()
|
void advance()
|
||||||
{
|
{
|
||||||
if (range.empty)
|
if (range.empty)
|
||||||
{
|
{
|
||||||
|
@ -221,15 +250,10 @@ class TokenRange(R) : InputRange!(Token)
|
||||||
current.lineNumber = lineNumber;
|
current.lineNumber = lineNumber;
|
||||||
current.startIndex = index;
|
current.startIndex = index;
|
||||||
|
|
||||||
while (std.uni.isWhite(range.front))
|
if (std.uni.isWhite(range.front))
|
||||||
{
|
{
|
||||||
if (iterStyle == IterationStyle.Everything)
|
current = lexWhitespace(range, index, lineNumber);
|
||||||
{
|
return;
|
||||||
current = lexWhitespace(range, index, lineNumber);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
lexWhitespace(range, index, lineNumber);
|
|
||||||
}
|
}
|
||||||
outer: switch (range.front)
|
outer: switch (range.front)
|
||||||
{
|
{
|
||||||
|
@ -338,15 +362,6 @@ class TokenRange(R) : InputRange!(Token)
|
||||||
case '*':
|
case '*':
|
||||||
case '+':
|
case '+':
|
||||||
current = lexComment(range, index, lineNumber);
|
current = lexComment(range, index, lineNumber);
|
||||||
if (!(iterStyle & IterationStyle.IncludeComments))
|
|
||||||
{
|
|
||||||
if (range.empty)
|
|
||||||
{
|
|
||||||
_empty = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
popFront();
|
|
||||||
}
|
|
||||||
break outer;
|
break outer;
|
||||||
case '=':
|
case '=':
|
||||||
current.type = TokenType.DivEquals;
|
current.type = TokenType.DivEquals;
|
||||||
|
@ -388,15 +403,6 @@ class TokenRange(R) : InputRange!(Token)
|
||||||
{
|
{
|
||||||
current.type = TokenType.SpecialTokenSequence;
|
current.type = TokenType.SpecialTokenSequence;
|
||||||
current.value = special;
|
current.value = special;
|
||||||
if (!(iterStyle & IterationStyle.IncludeSpecialTokens))
|
|
||||||
{
|
|
||||||
if (range.empty)
|
|
||||||
{
|
|
||||||
_empty = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
popFront();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -421,7 +427,6 @@ class TokenRange(R) : InputRange!(Token)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
Token current;
|
Token current;
|
||||||
uint lineNumber;
|
uint lineNumber;
|
||||||
uint index;
|
uint index;
|
||||||
|
@ -1520,6 +1525,7 @@ body
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
|
import std.stdio;
|
||||||
uint i;
|
uint i;
|
||||||
uint l;
|
uint l;
|
||||||
auto a = "q{import std.stdio;} abcd";
|
auto a = "q{import std.stdio;} abcd";
|
||||||
|
@ -2510,5 +2516,3 @@ string generateCaseTrie(string[] args ...)
|
||||||
}
|
}
|
||||||
return printCaseStatements(t, "");
|
return printCaseStatements(t, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {}
|
|
||||||
|
|
Loading…
Reference in New Issue