diff --git a/autocomplete.d b/autocomplete.d index 26ba6dd..2b31512 100644 --- a/autocomplete.d +++ b/autocomplete.d @@ -72,14 +72,20 @@ size_t findBeginningOfExpression(const Token[] tokens, const size_t index) case TokenType.RParen: case TokenType.RBracket: case TokenType.Semicolon: - break loop; + return i + 1; case TokenType.LBrace: + if (i == 0) + break loop; skipBraces(tokens, i); break; case TokenType.LParen: + if (i == 0) + break loop; skipParens(tokens, i); break; case TokenType.LBracket: + if (i == 0) + break loop; skipBrackets(tokens, i); break; default: @@ -103,7 +109,6 @@ const(Token)[] splitCallChain(const(Token)[] tokens) while (i < tokens.length && tokens[i] == TokenType.LBracket) skipBrackets(tokens, i); while (i < tokens.length && tokens[i] == TokenType.Dot) ++i; } - writeln(app.data); return app.data; } @@ -125,9 +130,11 @@ struct AutoComplete string getTypeOfExpression(const(Token)[] expression, const Token[] tokens, size_t cursor) { + if (expression.length == 0) + return "void"; auto type = typeOfVariable(expression[0], cursor); if (type is null) - return null; + return "void"; size_t index = 1; while (index < expression.length) { @@ -234,8 +241,6 @@ struct AutoComplete { auto index = assumeSorted(tokens).lowerBound(cursor).length - 2; Token t = tokens[index]; - if (t.startIndex + t.value.length + 1 != cursor) - return ""; switch (tokens[index].type) { case TokenType.Version: @@ -250,19 +255,17 @@ struct AutoComplete case TokenType.Switch: return ""; default: - size_t startIndex = findBeginningOfExpression(tokens, index); - auto expressionType = getTypeOfExpression(tokens[startIndex .. index], - tokens, index); +// size_t startIndex = findBeginningOfExpression(tokens, index); +// auto expressionType = getTypeOfExpression(tokens[startIndex .. index], +// tokens, index); return ""; } } string dotComplete(size_t cursor) { - auto index = assumeSorted(tokens).lowerBound(cursor).length - 2; + auto index = assumeSorted(tokens).lowerBound(cursor).length - 1; Token t = tokens[index]; - if (t.startIndex + t.value.length + 1 != cursor) - return ""; size_t startIndex = findBeginningOfExpression(tokens, index); auto expressionType = getTypeOfExpression( splitCallChain(tokens[startIndex .. index]), tokens, index); diff --git a/build.sh b/build.sh index 8a65715..c976e38 100755 --- a/build.sh +++ b/build.sh @@ -1,2 +1,2 @@ #dmd *.d -release -noboundscheck -O -w -wi -m64 -property -ofdscanner #-inline -dmd *.d -g -unittest -m64 -w -wi -property -ofdscanner +dmd *.d -g -m64 -w -wi -property -ofdscanner diff --git a/langutils.d b/langutils.d index 6ded5e4..23e3d3b 100644 --- a/langutils.d +++ b/langutils.d @@ -416,8 +416,8 @@ struct Token bool opEquals(TokenType t) const { return type == t; } int opCmp(size_t i) const { - if (i > startIndex) return -1; - if (i < startIndex) return 1; + if (startIndex < i) return -1; + if (startIndex > i) return 1; return 0; } } diff --git a/parser.d b/parser.d index 982ec7f..c3b52ba 100644 --- a/parser.d +++ b/parser.d @@ -440,7 +440,7 @@ Module parseModule(const Token[] tokens, string protection = "public", string[] break; case TokenType.This: name ~= tokens[index++].value; - if (tokens[index] == TokenType.LParen) + if (index < tokens.length && tokens[index] == TokenType.LParen) { mod.functions ~= parseFunction(tokens, index, "", name, tokens[index - 1].lineNumber, diff --git a/tokenizer.d b/tokenizer.d index 7d7121a..9731074 100644 --- a/tokenizer.d +++ b/tokenizer.d @@ -246,6 +246,7 @@ pure nothrow Token lexNumber(S)(ref S inputString, ref size_t endIndex) if (isSomeString!S) { Token token; + token.startIndex = endIndex; size_t startIndex = endIndex; if (inputString[endIndex] == '0') {