[update] Implement skipping comments.

This commit is contained in:
falsycat 2019-10-04 00:00:00 +00:00
parent 53295526b3
commit f5df2c9aab
2 changed files with 9 additions and 2 deletions

View File

@ -12,11 +12,11 @@ unittest {
import std; import std;
with (TokenType) { with (TokenType) {
assert("0 0.1 _hoge0_ $hoge". assert("0 0.1 _hoge0_ $hoge // hoge".
Tokenize!TokenType. Tokenize!TokenType.
map!"a.type". map!"a.type".
filter!(x => x != Whitespace). filter!(x => x != Whitespace).
equal([Number, Number, Ident, PreprocessCommand])); equal([Number, Number, Ident, PreprocessCommand, Comment]));
} }
} }
@ -80,6 +80,12 @@ enum TokenType {
@TextCompleteMatcher!"/" Div, @TextCompleteMatcher!"/" Div,
@TextAllMatcher!isWhite Whitespace, @TextAllMatcher!isWhite Whitespace,
@TextFuncMatcher!((string text) {
if (text.length < 2 || text[0..2] != "//") return 0;
const index = text.countUntil('\n');
return index >= 0? index.to!size_t: text.length;
}) Comment,
End, End,
} }

View File

@ -20,6 +20,7 @@ ParametersBlock[] CreateScriptAst(string src) {
return src. return src.
Tokenize!TokenType(). Tokenize!TokenType().
filter!(x => x.type != TokenType.Whitespace). filter!(x => x.type != TokenType.Whitespace).
filter!(x => x.type != TokenType.Comment).
Preprocess(). Preprocess().
Parse(); Parse();
} }