Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
Merge pull request #6 from L2Program/dev
Browse files Browse the repository at this point in the history
Fixed tokenizer #include path bug, where <...> would not be parsed as a string literal
  • Loading branch information
JossWhittle committed May 4, 2014
2 parents f32479e + ba83609 commit cf06a34
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
12 changes: 0 additions & 12 deletions flint/Checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -922,20 +922,8 @@ namespace flint {
TK_IDENTIFIER, TK_DECREMENT
};

const vector<TokenType> includeStatement = {
TK_INCLUDE, TK_LESS
};

for (size_t pos = 0; pos < tokens.size(); ++pos) {

if (atSequence(tokens, pos, includeStatement)) {
// Skip to closing angle
if (!skipToToken(tokens, pos, TK_GREATER)) {
return;
}
continue;
}

if (atSequence(tokens, pos, iteratorPlus) || atSequence(tokens, pos, iteratorMinus)) {
lintAdvice(errors, tokens[pos],
"Use prefix notation '" + tokens[pos + 1].value_ + tokens[pos].value_ + "'.",
Expand Down
21 changes: 18 additions & 3 deletions flint/Tokenizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,14 @@ namespace flint {
* it from pc and returns it. A reference to line is passed in order
* to track multiline strings correctly.
*/
static string munchString(string &pc, size_t &line) {
assert(pc[0] == '"');
static string munchString(string &pc, size_t &line, bool isIncludeLiteral = false) {
char stringStart = (isIncludeLiteral ? '<' : '"');
char stringEnd = (isIncludeLiteral ? '>' : '"');

assert(pc[0] == stringStart);
for (size_t i = 1;; ++i) {
auto const c = pc[i];
if (c == '"') {
if (c == stringEnd) {
// That's about it
return munchChars(pc, i + 1);
}
Expand Down Expand Up @@ -250,6 +253,18 @@ namespace flint {
while (1) {
const char c = pc[0];

// Special case for parseing #include <...>
// Previously the include path would not be captured as a string literal
if (c == '<') {
if (output.size() > 0 && output.back().type_ == TK_INCLUDE) {
auto str = munchString(pc, line, true);
output.push_back(Token(TK_STRING_LITERAL, str, file, line,
whitespace));
whitespace = "";
continue;
}
}

switch (c) {
// *** One-character tokens that don't require lookahead (comma,
// *** semicolon etc.)
Expand Down

0 comments on commit cf06a34

Please sign in to comment.