Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/dparse/lexer.d
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public struct LexerConfig
{
string fileName;
StringBehavior stringBehavior;
WhitespaceBehavior whitespaceBehavior;
WhitespaceBehavior whitespaceBehavior = WhitespaceBehavior.skip;
CommentBehavior commentBehavior = CommentBehavior.intern;
}

Expand Down Expand Up @@ -384,9 +384,10 @@ public bool isLiteral(IdType type) pure nothrow @safe @nogc
}

/**
* Returns: an array of tokens lexed from the given source code to the output range. All
* whitespace tokens are skipped and comments are attached to the token nearest
* to them.
* Returns: an array of tokens lexed from the given source code to the output range.
* Whitespace token are skipped by default, except `WhitespaceBehavior.include`
* has been set explicitly.
* comments are attached to the token nearest to them.
*/
const(Token)[] getTokensForParser(ubyte[] sourceCode, LexerConfig config,
StringCache* cache)
Expand All @@ -409,7 +410,6 @@ const(Token)[] getTokensForParser(ubyte[] sourceCode, LexerConfig config,
return CommentType.notDoc;
}

config.whitespaceBehavior = WhitespaceBehavior.skip;
config.commentBehavior = CommentBehavior.noIntern;

auto leadingCommentAppender = appender!(char[])();
Expand All @@ -425,6 +425,9 @@ const(Token)[] getTokensForParser(ubyte[] sourceCode, LexerConfig config,
{
case tok!"specialTokenSequence":
case tok!"whitespace":
if (config.whitespaceBehavior == WhitespaceBehavior.include)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The (unchanged) doc comment specifically states that this won't happen.

output.put(lexer.front);

lexer.popFront();
break;
case tok!"comment":
Expand Down