Fixed an index out of bounds bug. Updated ddoc

This commit is contained in:
Hackerpilot 2013-07-12 16:17:14 +00:00
parent e91316cc9a
commit 50ddf8abf8
1 changed files with 69 additions and 45 deletions

View File

@ -90,8 +90,8 @@ Module parseModule(const(Token)[] tokens, string fileName)
parser.fileName = fileName; parser.fileName = fileName;
parser.tokens = tokens; parser.tokens = tokens;
auto mod = parser.parseModule(); auto mod = parser.parseModule();
writefln("Parsing finished with %d errors and %d warnings.", // writefln("Parsing finished with %d errors and %d warnings.",
parser.errorCount, parser.warningCount); // parser.errorCount, parser.warningCount);
return mod; return mod;
} }
@ -1774,6 +1774,7 @@ class ClassFour(A, B) if (someTest()) : Super {}}c;
break; break;
default: default:
error("Declaration expected"); error("Declaration expected");
if (moreTokens())
advance(); advance();
return null; return null;
} }
@ -1785,7 +1786,7 @@ class ClassFour(A, B) if (someTest()) : Super {}}c;
* *
* $(GRAMMAR $(RULEDEF declarationsAndStatements): * $(GRAMMAR $(RULEDEF declarationsAndStatements):
* $(RULE declarationOrStatement)+ * $(RULE declarationOrStatement)+
* ; * ;)
*/ */
DeclarationsAndStatements parseDeclarationsAndStatements() DeclarationsAndStatements parseDeclarationsAndStatements()
{ {
@ -3176,7 +3177,10 @@ invariant() foo();
* Parses a LambdaExpression * Parses a LambdaExpression
* *
* $(GRAMMAR $(RULEDEF lambdaExpression): * $(GRAMMAR $(RULEDEF lambdaExpression):
* ($(LITERAL Identifier) | $(RULE parameters) $(RULE functionAttribute)* ) $(LITERAL '=>') $(RULE assignExpression) * $(LITERAL Identifier) $(LITERAL '=>') $(RULE assignExpression)
* | $(LITERAL 'function') $(RULE parameters) $(RULE functionAttribute)* $(LITERAL '=>') $(RULE assignExpression)
* | $(LITERAL 'delegate') $(RULE parameters) $(RULE functionAttribute)* $(LITERAL '=>') $(RULE assignExpression)
* | $(RULE parameters) $(RULE functionAttribute)* $(LITERAL '=>') $(RULE assignExpression)
* ;) * ;)
*/ */
LambdaExpression parseLambdaExpression() LambdaExpression parseLambdaExpression()
@ -3301,8 +3305,13 @@ invariant() foo();
auto node = new MixinDeclaration; auto node = new MixinDeclaration;
if (peekIs(TokenType.identifier)) if (peekIs(TokenType.identifier))
node.templateMixinExpression = parseTemplateMixinExpression(); node.templateMixinExpression = parseTemplateMixinExpression();
else else if (peekIs(TokenType.lParen))
node.mixinExpression = parseMixinExpression(); node.mixinExpression = parseMixinExpression();
else
{
error(`"(" or identifier expected`);
return null;
}
expect(TokenType.semicolon); expect(TokenType.semicolon);
return node; return node;
} }
@ -4034,6 +4043,20 @@ q{(int a, ...)
break; break;
case function_: case function_:
case delegate_: case delegate_:
if (peekIs(lParen))
{
auto b = setBookmark();
advance(); // function | delegate
skipParens();
if (currentIs(goesTo))
{
goToBookmark(b);
goto lambda;
}
else
goToBookmark(b);
}
goto case;
case lBrace: case lBrace:
case in_: case in_:
case out_: case out_:
@ -4063,6 +4086,7 @@ q{(int a, ...)
if (currentIs(goesTo)) if (currentIs(goesTo))
{ {
goToBookmark(b); goToBookmark(b);
lambda:
node.lambdaExpression = parseLambdaExpression(); node.lambdaExpression = parseLambdaExpression();
} }
else if (currentIs(lBrace)) else if (currentIs(lBrace))
@ -6140,7 +6164,7 @@ private:
auto column = index < tokens.length ? tokens[index].column : 0; auto column = index < tokens.length ? tokens[index].column : 0;
auto line = index < tokens.length ? tokens[index].line : 0; auto line = index < tokens.length ? tokens[index].line : 0;
if (messageFunction is null) if (messageFunction is null)
writefln("^^ %s(%d:%d): %s", fileName, line, column, message); writefln("%s(%d:%d)[warn]: %s", fileName, line, column, message);
else else
messageFunction(fileName, line, column, message); messageFunction(fileName, line, column, message);
} }
@ -6155,7 +6179,7 @@ private:
column++; column++;
auto line = index < tokens.length ? tokens[index].line : 0; auto line = index < tokens.length ? tokens[index].line : 0;
if (messageFunction is null) if (messageFunction is null)
stderr.writefln("!! %s(%d:%d): %s", fileName, line, column, message); writefln("%s(%d:%d)[error]: %s", fileName, line, column, message);
else else
messageFunction(fileName, line, column, message); messageFunction(fileName, line, column, message);
} }
@ -6275,7 +6299,7 @@ private:
* Returns a token of the specified type if it was the next token, otherwise * Returns a token of the specified type if it was the next token, otherwise
* calls the error function and returns null. * calls the error function and returns null.
*/ */
const(Token)* expect(TokenType type, string loc = __PRETTY_FUNCTION__) const(Token)* expect(TokenType type)
{ {
if (index < tokens.length && tokens[index].type == type) if (index < tokens.length && tokens[index].type == type)
return &tokens[index++]; return &tokens[index++];
@ -6283,10 +6307,10 @@ private:
{ {
if (tokenValues[type] is null) if (tokenValues[type] is null)
error("Expected " ~ to!string(type) ~ " instead of " error("Expected " ~ to!string(type) ~ " instead of "
~ (index < tokens.length ? tokens[index].value : "EOF") ~ " at " ~ loc); ~ (index < tokens.length ? tokens[index].value : "EOF"));
else else
error("Expected " ~ tokenValues[type] ~ " instead of " error("Expected " ~ tokenValues[type] ~ " instead of "
~ (index < tokens.length ? tokens[index].value : "EOF") ~ " at " ~ loc); ~ (index < tokens.length ? tokens[index].value : "EOF"));
return null; return null;
} }
} }