diff --git a/sjscript/src/sjscript/Token.d b/sjscript/src/sjscript/Token.d index ebae53e..529d3d9 100644 --- a/sjscript/src/sjscript/Token.d +++ b/sjscript/src/sjscript/Token.d @@ -12,11 +12,11 @@ unittest { import std; with (TokenType) { - assert("0 0.1 _hoge0_ $hoge". + assert("0 0.1 _hoge0_ $hoge // hoge". Tokenize!TokenType. map!"a.type". filter!(x => x != Whitespace). - equal([Number, Number, Ident, PreprocessCommand])); + equal([Number, Number, Ident, PreprocessCommand, Comment])); } } @@ -80,6 +80,12 @@ enum TokenType { @TextCompleteMatcher!"/" Div, @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, } diff --git a/sjscript/src/sjscript/package.d b/sjscript/src/sjscript/package.d index 4946b9c..c063b59 100644 --- a/sjscript/src/sjscript/package.d +++ b/sjscript/src/sjscript/package.d @@ -20,6 +20,7 @@ ParametersBlock[] CreateScriptAst(string src) { return src. Tokenize!TokenType(). filter!(x => x.type != TokenType.Whitespace). + filter!(x => x.type != TokenType.Comment). Preprocess(). Parse(); }