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.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);

View File

@ -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

View File

@ -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;
}
}

View File

@ -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,

View File

@ -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')
{