Fixed bug with decimal lexing. Fixed autocomplete bugs

This commit is contained in:
Hackerpilot 2012-05-24 13:30:52 -07:00
parent cb719a9c36
commit 50f4660a74
5 changed files with 19 additions and 15 deletions

View File

@ -72,14 +72,20 @@ size_t findBeginningOfExpression(const Token[] tokens, const size_t index)
case TokenType.RParen: case TokenType.RParen:
case TokenType.RBracket: case TokenType.RBracket:
case TokenType.Semicolon: case TokenType.Semicolon:
break loop; return i + 1;
case TokenType.LBrace: case TokenType.LBrace:
if (i == 0)
break loop;
skipBraces(tokens, i); skipBraces(tokens, i);
break; break;
case TokenType.LParen: case TokenType.LParen:
if (i == 0)
break loop;
skipParens(tokens, i); skipParens(tokens, i);
break; break;
case TokenType.LBracket: case TokenType.LBracket:
if (i == 0)
break loop;
skipBrackets(tokens, i); skipBrackets(tokens, i);
break; break;
default: 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.LBracket) skipBrackets(tokens, i);
while (i < tokens.length && tokens[i] == TokenType.Dot) ++i; while (i < tokens.length && tokens[i] == TokenType.Dot) ++i;
} }
writeln(app.data);
return app.data; return app.data;
} }
@ -125,9 +130,11 @@ struct AutoComplete
string getTypeOfExpression(const(Token)[] expression, const Token[] tokens, size_t cursor) string getTypeOfExpression(const(Token)[] expression, const Token[] tokens, size_t cursor)
{ {
if (expression.length == 0)
return "void";
auto type = typeOfVariable(expression[0], cursor); auto type = typeOfVariable(expression[0], cursor);
if (type is null) if (type is null)
return null; return "void";
size_t index = 1; size_t index = 1;
while (index < expression.length) while (index < expression.length)
{ {
@ -234,8 +241,6 @@ struct AutoComplete
{ {
auto index = assumeSorted(tokens).lowerBound(cursor).length - 2; auto index = assumeSorted(tokens).lowerBound(cursor).length - 2;
Token t = tokens[index]; Token t = tokens[index];
if (t.startIndex + t.value.length + 1 != cursor)
return "";
switch (tokens[index].type) switch (tokens[index].type)
{ {
case TokenType.Version: case TokenType.Version:
@ -250,19 +255,17 @@ struct AutoComplete
case TokenType.Switch: case TokenType.Switch:
return ""; return "";
default: default:
size_t startIndex = findBeginningOfExpression(tokens, index); // size_t startIndex = findBeginningOfExpression(tokens, index);
auto expressionType = getTypeOfExpression(tokens[startIndex .. index], // auto expressionType = getTypeOfExpression(tokens[startIndex .. index],
tokens, index); // tokens, index);
return ""; return "";
} }
} }
string dotComplete(size_t cursor) 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]; Token t = tokens[index];
if (t.startIndex + t.value.length + 1 != cursor)
return "";
size_t startIndex = findBeginningOfExpression(tokens, index); size_t startIndex = findBeginningOfExpression(tokens, index);
auto expressionType = getTypeOfExpression( auto expressionType = getTypeOfExpression(
splitCallChain(tokens[startIndex .. index]), tokens, index); splitCallChain(tokens[startIndex .. index]), tokens, index);

View File

@ -1,2 +1,2 @@
#dmd *.d -release -noboundscheck -O -w -wi -m64 -property -ofdscanner #-inline #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

View File

@ -416,8 +416,8 @@ struct Token
bool opEquals(TokenType t) const { return type == t; } bool opEquals(TokenType t) const { return type == t; }
int opCmp(size_t i) const int opCmp(size_t i) const
{ {
if (i > startIndex) return -1; if (startIndex < i) return -1;
if (i < startIndex) return 1; if (startIndex > i) return 1;
return 0; return 0;
} }
} }

View File

@ -440,7 +440,7 @@ Module parseModule(const Token[] tokens, string protection = "public", string[]
break; break;
case TokenType.This: case TokenType.This:
name ~= tokens[index++].value; name ~= tokens[index++].value;
if (tokens[index] == TokenType.LParen) if (index < tokens.length && tokens[index] == TokenType.LParen)
{ {
mod.functions ~= parseFunction(tokens, index, "", name, mod.functions ~= parseFunction(tokens, index, "", name,
tokens[index - 1].lineNumber, tokens[index - 1].lineNumber,

View File

@ -246,6 +246,7 @@ pure nothrow Token lexNumber(S)(ref S inputString, ref size_t endIndex)
if (isSomeString!S) if (isSomeString!S)
{ {
Token token; Token token;
token.startIndex = endIndex;
size_t startIndex = endIndex; size_t startIndex = endIndex;
if (inputString[endIndex] == '0') if (inputString[endIndex] == '0')
{ {