This commit is contained in:
Hackerpilot 2014-05-06 16:10:16 -07:00
parent 867f8b426c
commit 258aa066f7
4 changed files with 28 additions and 3 deletions

View File

@ -1314,8 +1314,9 @@ class XMLPrinter : ASTVisitor
case tok!"stringLiteral": tagName = "stringLiteral"; break;
case tok!"dstringLiteral": tagName = "dstringLiteral"; break;
case tok!"wstringLiteral": tagName = "wstringLiteral"; break;
case tok!"scriptLine": tagName = "scriptLine"; break;
case tok!"$": output.writeln("<dollar/>"); return;
default: output.writeln("<", str(token.type), "/>"); return;
default: tagName = "token"; break;
}
output.writeln("<", tagName, ">", xmlEscape(token.text), "</", tagName, ">");
}

View File

@ -1956,8 +1956,9 @@ final class Module : ASTNode
public:
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(moduleDeclaration, declarations));
mixin (visitIfNotNull!(scriptLine, moduleDeclaration, declarations));
}
/** */ Token scriptLine;
/** */ ModuleDeclaration moduleDeclaration;
/** */ Declaration[] declarations;
mixin OpEquals;

View File

@ -119,6 +119,18 @@ public enum WhitespaceBehavior : ubyte
/// Whitespace is treated as a token
include
}
/**
* Configure special token handling behavior
*/
public enum SpecialTokenBehavior : ubyte
{
/// Special tokens are skipped
skip,
/// Special tokens are treated as a token
include
}
/**
* Configure comment handling behavior
*/
@ -136,6 +148,7 @@ public struct LexerConfig
StringBehavior stringBehavior;
WhitespaceBehavior whitespaceBehavior;
CommentBehavior commentBehavior;
SpecialTokenBehavior specialTokenBehavior;
}
public bool isBasicType(IdType type) nothrow pure @safe
@ -434,6 +447,7 @@ public struct DLexer
}
do _popFront(); while (front == tok!"comment");
if (front == tok!"whitespace") goto case tok!"whitespace";
if (front == tok!"specialTokenSequence") goto case tok!"specialTokenSequence";
}
break;
case tok!"whitespace":
@ -441,6 +455,15 @@ public struct DLexer
{
do _popFront(); while (front == tok!"whitespace");
if (front == tok!"comment") goto case tok!"comment";
if (front == tok!"specialTokenSequence") goto case tok!"specialTokenSequence";
}
break;
case tok!"specialTokenSequence":
if (config.specialTokenBehavior == SpecialTokenBehavior.skip)
{
do _popFront(); while (front == tok!"specialTokenSequence");
if (front == tok!"comment") goto case tok!"comment";
if (front == tok!"whitespace") goto case tok!"whitespace";
}
break;
default:

View File

@ -3561,7 +3561,7 @@ invariant() foo();
mixin(traceEnterAndExit!(__FUNCTION__));
Module m = allocate!Module;
if (currentIs(tok!"scriptLine"))
advance();
m.scriptLine = advance();
if (currentIs(tok!"module"))
m.moduleDeclaration = parseModuleDeclaration();
while (moreTokens())