36/57 files in Phobos parse.

This commit is contained in:
Hackerpilot 2013-07-03 14:26:14 -07:00
parent 7c744a07f6
commit 8492a39b09
2 changed files with 83 additions and 63 deletions

View File

@ -141,6 +141,7 @@ abstract class ASTVisitor
/** */ void visit(MemberFunctionAttribute memberFunctionAttribute) { memberFunctionAttribute.accept(this); } /** */ void visit(MemberFunctionAttribute memberFunctionAttribute) { memberFunctionAttribute.accept(this); }
/** */ void visit(MixinDeclaration mixinDeclaration) { mixinDeclaration.accept(this); } /** */ void visit(MixinDeclaration mixinDeclaration) { mixinDeclaration.accept(this); }
/** */ void visit(MixinExpression mixinExpression) { mixinExpression.accept(this); } /** */ void visit(MixinExpression mixinExpression) { mixinExpression.accept(this); }
/** */ void visit(MixinTemplateDeclaration mixinTemplateDeclaration) { mixinTemplateDeclaration.accept(this); }
/** */ void visit(MixinTemplateName mixinTemplateName) { mixinTemplateName.accept(this); } /** */ void visit(MixinTemplateName mixinTemplateName) { mixinTemplateName.accept(this); }
/** */ void visit(Module module_) { module_.accept(this); } /** */ void visit(Module module_) { module_.accept(this); }
/** */ void visit(ModuleDeclaration moduleDeclaration) { moduleDeclaration.accept(this); } /** */ void visit(ModuleDeclaration moduleDeclaration) { moduleDeclaration.accept(this); }
@ -195,7 +196,7 @@ abstract class ASTVisitor
/** */ void visit(TemplateArguments templateArguments) { templateArguments.accept(this); } /** */ void visit(TemplateArguments templateArguments) { templateArguments.accept(this); }
/** */ void visit(TemplateDeclaration templateDeclaration) { templateDeclaration.accept(this); } /** */ void visit(TemplateDeclaration templateDeclaration) { templateDeclaration.accept(this); }
/** */ void visit(TemplateInstance templateInstance) { templateInstance.accept(this); } /** */ void visit(TemplateInstance templateInstance) { templateInstance.accept(this); }
/** */ void visit(TemplateMixinStatement templateMixinStatement) { templateMixinStatement.accept(this); } /** */ void visit(TemplateMixinExpression templateMixinExpression) { templateMixinExpression.accept(this); }
/** */ void visit(TemplateParameter templateParameter) { templateParameter.accept(this); } /** */ void visit(TemplateParameter templateParameter) { templateParameter.accept(this); }
/** */ void visit(TemplateParameterList templateParameterList) { templateParameterList.accept(this); } /** */ void visit(TemplateParameterList templateParameterList) { templateParameterList.accept(this); }
/** */ void visit(TemplateParameters templateParameters) { templateParameters.accept(this); } /** */ void visit(TemplateParameters templateParameters) { templateParameters.accept(this); }
@ -812,6 +813,7 @@ public:
if (enumDeclaration !is null) visitor.visit(enumDeclaration); if (enumDeclaration !is null) visitor.visit(enumDeclaration);
if (aliasDeclaration !is null) visitor.visit(aliasDeclaration); if (aliasDeclaration !is null) visitor.visit(aliasDeclaration);
if (mixinDeclaration !is null) visitor.visit(mixinDeclaration); if (mixinDeclaration !is null) visitor.visit(mixinDeclaration);
if (mixinTemplateDeclaration !is null) visitor.visit(mixinTemplateDeclaration);
if (unittest_ !is null) visitor.visit(unittest_); if (unittest_ !is null) visitor.visit(unittest_);
if (staticAssertDeclaration !is null) visitor.visit(staticAssertDeclaration); if (staticAssertDeclaration !is null) visitor.visit(staticAssertDeclaration);
if (templateDeclaration !is null) visitor.visit(templateDeclaration); if (templateDeclaration !is null) visitor.visit(templateDeclaration);
@ -838,6 +840,7 @@ public:
/** */ EnumDeclaration enumDeclaration; /** */ EnumDeclaration enumDeclaration;
/** */ AliasDeclaration aliasDeclaration; /** */ AliasDeclaration aliasDeclaration;
/** */ MixinDeclaration mixinDeclaration; /** */ MixinDeclaration mixinDeclaration;
/** */ MixinTemplateDeclaration mixinTemplateDeclaration;
/** */ Unittest unittest_; /** */ Unittest unittest_;
/** */ StaticAssertDeclaration staticAssertDeclaration; /** */ StaticAssertDeclaration staticAssertDeclaration;
/** */ TemplateDeclaration templateDeclaration; /** */ TemplateDeclaration templateDeclaration;
@ -1363,6 +1366,7 @@ class MixinDeclaration : ASTNode
public: public:
mixin(DEFAULT_ACCEPT); mixin(DEFAULT_ACCEPT);
/** */ MixinExpression mixinExpression; /** */ MixinExpression mixinExpression;
/** */ TemplateMixinExpression templateMixinExpression;
} }
/// ///
@ -1373,6 +1377,14 @@ public:
/** */ AssignExpression assignExpression; /** */ AssignExpression assignExpression;
} }
///
class MixinTemplateDeclaration : ASTNode
{
public:
mixin(DEFAULT_ACCEPT);
/** */ TemplateDeclaration templateDeclaration;
}
/// ///
class MixinTemplateName : ASTNode class MixinTemplateName : ASTNode
{ {
@ -1466,7 +1478,6 @@ public:
/** */ AsmStatement asmStatement; /** */ AsmStatement asmStatement;
/** */ ConditionalStatement conditionalStatement; /** */ ConditionalStatement conditionalStatement;
/** */ StaticAssertStatement staticAssertStatement; /** */ StaticAssertStatement staticAssertStatement;
/** */ TemplateMixinStatement templateMixinStatement;
/** */ VersionSpecification versionSpecification; /** */ VersionSpecification versionSpecification;
/** */ DebugSpecification debugSpecification; /** */ DebugSpecification debugSpecification;
/** */ FunctionCallStatement functionCallStatement; /** */ FunctionCallStatement functionCallStatement;
@ -1605,6 +1616,7 @@ class PrimaryExpression : ASTNode
{ {
public: public:
mixin(DEFAULT_ACCEPT); mixin(DEFAULT_ACCEPT);
/** */ bool hasDot;
/** */ Token primary; /** */ Token primary;
/** */ IdentifierOrTemplateInstance identifierOrTemplateInstance; /** */ IdentifierOrTemplateInstance identifierOrTemplateInstance;
/** */ TokenType basicType; /** */ TokenType basicType;
@ -1915,7 +1927,7 @@ public:
} }
/// ///
class TemplateMixinStatement : ASTNode class TemplateMixinExpression : ASTNode
{ {
public: public:
mixin(DEFAULT_ACCEPT); mixin(DEFAULT_ACCEPT);

View File

@ -255,10 +255,10 @@ alias core.sys.posix.stdio.fileno fileno;
* $(RULE assignExpression) ($(LITERAL ',') $(RULE assignExpression)?)* * $(RULE assignExpression) ($(LITERAL ',') $(RULE assignExpression)?)*
* ;) * ;)
*/ */
ArgumentList parseArgumentList() ArgumentList parseArgumentList(bool allowTrailingComma = false)
{ {
mixin(traceEnterAndExit!(__FUNCTION__)); mixin(traceEnterAndExit!(__FUNCTION__));
return parseCommaSeparatedRule!(ArgumentList, AssignExpression)(); return parseCommaSeparatedRule!(ArgumentList, AssignExpression)(allowTrailingComma);
} }
/** /**
@ -284,7 +284,7 @@ alias core.sys.posix.stdio.fileno fileno;
* *
* $(GRAMMAR $(RULEDEF arrayInitializer): * $(GRAMMAR $(RULEDEF arrayInitializer):
* $(LITERAL '[') $(LITERAL ']') * $(LITERAL '[') $(LITERAL ']')
* | $(LITERAL '[') $(RULE arrayMemberInitialization) ($(LITERAL ',') $(RULE arrayMemberInitialization))* $(LITERAL ']') * | $(LITERAL '[') $(RULE arrayMemberInitialization) ($(LITERAL ',') $(RULE arrayMemberInitialization)?)* $(LITERAL ']')
* ;) * ;)
*/ */
ArrayInitializer parseArrayInitializer() ArrayInitializer parseArrayInitializer()
@ -298,7 +298,10 @@ alias core.sys.posix.stdio.fileno fileno;
if (currentIs(TokenType.comma)) if (currentIs(TokenType.comma))
{ {
advance(); advance();
continue; if (currentIs(TokenType.rBracket))
break;
else
continue;
} }
else else
break; break;
@ -312,7 +315,7 @@ alias core.sys.posix.stdio.fileno fileno;
* Parses an ArrayLiteral * Parses an ArrayLiteral
* *
* $(GRAMMAR $(RULEDEF arrayLiteral): * $(GRAMMAR $(RULEDEF arrayLiteral):
* $(LITERAL '[') $(RULE argumentList) $(LITERAL ']') * $(LITERAL '[') ($(RULE assignExpression) ($(LITERAL ',') $(RULE assignExpression))*)? $(LITERAL ']')
* ;) * ;)
*/ */
ArrayLiteral parseArrayLiteral() ArrayLiteral parseArrayLiteral()
@ -320,7 +323,7 @@ alias core.sys.posix.stdio.fileno fileno;
mixin(traceEnterAndExit!(__FUNCTION__)); mixin(traceEnterAndExit!(__FUNCTION__));
auto node = new ArrayLiteral; auto node = new ArrayLiteral;
if (expect(TokenType.lBracket) is null) return null; if (expect(TokenType.lBracket) is null) return null;
node.argumentList = parseArgumentList(); node.argumentList = parseArgumentList(true);
if (expect(TokenType.rBracket) is null) return null; if (expect(TokenType.rBracket) is null) return null;
return node; return node;
} }
@ -1458,52 +1461,19 @@ class ClassFour(A, B) if (someTest()) : Super {}}c;
mixin(traceEnterAndExit!(__FUNCTION__)); mixin(traceEnterAndExit!(__FUNCTION__));
auto node = new ConditionalDeclaration; auto node = new ConditionalDeclaration;
node.compileCondition = parseCompileCondition(); node.compileCondition = parseCompileCondition();
if (currentIs(TokenType.lBrace))
{ auto dec = parseDeclaration();
advance(); if (dec is null) return null;
do node.trueDeclarations ~= dec;
{
auto dec = parseDeclaration();
if (dec is null) return null;
node.trueDeclarations ~= dec;
if (!moreTokens() || currentIs(TokenType.rBrace))
break;
}
while (true);
if (expect(TokenType.rBrace) is null) return null;
}
else
{
auto dec = parseDeclaration();
if (dec is null) return null;
node.trueDeclarations ~= dec;
}
if(currentIs(TokenType.else_)) if(currentIs(TokenType.else_))
advance(); advance();
else else
return node; return node;
if (currentIs(TokenType.lBrace)) auto elseDec = parseDeclaration();
{ if (elseDec is null) return null;
advance(); node.falseDeclarations ~= elseDec;
do
{
auto dec = parseDeclaration();
if (dec is null) return null;
node.falseDeclarations ~= dec;
if (!moreTokens() || currentIs(TokenType.rBrace))
break;
}
while (true);
if (expect(TokenType.rBrace) is null) return null;
}
else
{
auto dec = parseDeclaration();
if (dec is null) return null;
node.falseDeclarations ~= dec;
}
return node; return node;
} }
@ -1682,6 +1652,7 @@ class ClassFour(A, B) if (someTest()) : Super {}}c;
* | $(RULE importDeclaration) * | $(RULE importDeclaration)
* | $(RULE interfaceDeclaration) * | $(RULE interfaceDeclaration)
* | $(RULE mixinDeclaration) * | $(RULE mixinDeclaration)
* | $(RULE mixinTemplateDeclaration)
* | $(RULE pragmaDeclaration) * | $(RULE pragmaDeclaration)
* | $(RULE sharedStaticConstructor) * | $(RULE sharedStaticConstructor)
* | $(RULE sharedStaticDestructor) * | $(RULE sharedStaticDestructor)
@ -1769,7 +1740,10 @@ class ClassFour(A, B) if (someTest()) : Super {}}c;
node.interfaceDeclaration = parseInterfaceDeclaration(); node.interfaceDeclaration = parseInterfaceDeclaration();
break; break;
case mixin_: case mixin_:
node.mixinDeclaration = parseMixinDeclaration(); if (peekIs(TokenType.template_))
node.mixinTemplateDeclaration = parseMixinTemplateDeclaration();
else
node.mixinDeclaration = parseMixinDeclaration();
break; break;
case pragma_: case pragma_:
node.pragmaDeclaration = parsePragmaDeclaration(); node.pragmaDeclaration = parsePragmaDeclaration();
@ -3391,14 +3365,18 @@ invariant() foo();
* Parses a MixinDeclaration * Parses a MixinDeclaration
* *
* $(GRAMMAR $(RULEDEF mixinDeclaration): * $(GRAMMAR $(RULEDEF mixinDeclaration):
* $(RULE mixinExpression) $(LITERAL ';') * $(RULE mixinExpression) $(LITERAL ';')
* | $(RULE templateMixinStatement) $(LITERAL ';')
* ;) * ;)
*/ */
MixinDeclaration parseMixinDeclaration() MixinDeclaration parseMixinDeclaration()
{ {
mixin(traceEnterAndExit!(__FUNCTION__)); mixin(traceEnterAndExit!(__FUNCTION__));
auto node = new MixinDeclaration; auto node = new MixinDeclaration;
node.mixinExpression = parseMixinExpression(); if (peekIs(TokenType.identifier))
node.templateMixinExpression = parseTemplateMixinExpression();
else
node.mixinExpression = parseMixinExpression();
expect(TokenType.semicolon); expect(TokenType.semicolon);
return node; return node;
} }
@ -3421,6 +3399,23 @@ invariant() foo();
return node; return node;
} }
/**
* Parses a MixinTemplateDeclaration
*
* $(GRAMMAR $(RULEDEF mixinTemplateDeclaration):
* $(LITERAL 'mixin') $RULE templateDeclaration
* ;)
*/
MixinTemplateDeclaration parseMixinTemplateDeclaration()
{
mixin(traceEnterAndExit!(__FUNCTION__));
auto node = new MixinTemplateDeclaration;
if (expect(TokenType.mixin_) is null) return null;
node.templateDeclaration = parseTemplateDeclaration();
if (node.templateDeclaration is null) return null;
return node;
}
/** /**
* Parses a MixinTemplateName * Parses a MixinTemplateName
* *
@ -4023,6 +4018,7 @@ q{(int a, ...)
* *
* $(GRAMMAR $(RULEDEF primaryExpression): * $(GRAMMAR $(RULEDEF primaryExpression):
* $(RULE identifierOrTemplateInstance) * $(RULE identifierOrTemplateInstance)
* | $(LITERAL '.') $(RULE identifierOrTemplateInstance)
* | $(RULE basicType) $(LITERAL '.') $(LITERAL Identifier) * | $(RULE basicType) $(LITERAL '.') $(LITERAL Identifier)
* | $(RULE typeofExpression) * | $(RULE typeofExpression)
* | $(RULE typeidExpression) * | $(RULE typeidExpression)
@ -4064,6 +4060,10 @@ q{(int a, ...)
auto node = new PrimaryExpression; auto node = new PrimaryExpression;
with (TokenType) switch (current.type) with (TokenType) switch (current.type)
{ {
case dot:
node.hasDot = true;
advance();
goto case;
case identifier: case identifier:
if (peekIs(TokenType.goesTo)) if (peekIs(TokenType.goesTo))
node.lambdaExpression = parseLambdaExpression(); node.lambdaExpression = parseLambdaExpression();
@ -4209,10 +4209,10 @@ q{(int a, ...)
{ {
mixin(traceEnterAndExit!(__FUNCTION__)); mixin(traceEnterAndExit!(__FUNCTION__));
auto node = new ReturnStatement; auto node = new ReturnStatement;
expect(TokenType.return_); if (expect(TokenType.return_) is null) return null;
if (tokens[index] != TokenType.semicolon) if (!currentIs(TokenType.semicolon))
node.expression = parseExpression(); node.expression = parseExpression();
expect(TokenType.semicolon); if (expect(TokenType.semicolon) is null) return null;
return node; return node;
} }
@ -4890,23 +4890,22 @@ q{(int a, ...)
} }
/** /**
* Parses a TemplateMixinStatement * Parses a TemplateMixinExpression
* *
* $(GRAMMAR $(RULEDEF templateMixinStatement): * $(GRAMMAR $(RULEDEF templateMixinExpression):
* $(LITERAL 'mixin') $(RULE mixinTemplateName) $(RULE templateArguments)? $(LITERAL Identifier)? $(LITERAL ';') * $(LITERAL 'mixin') $(RULE mixinTemplateName) $(RULE templateArguments)? $(LITERAL Identifier)?
* ;) * ;)
*/ */
TemplateMixinStatement parseTemplateMixinStatement() TemplateMixinExpression parseTemplateMixinExpression()
{ {
mixin(traceEnterAndExit!(__FUNCTION__)); mixin(traceEnterAndExit!(__FUNCTION__));
auto node = new TemplateMixinStatement; auto node = new TemplateMixinExpression;
expect(TokenType.mixin_); if (expect(TokenType.mixin_) is null) return null;
node.mixinTemplateName = parseMixinTemplateName(); node.mixinTemplateName = parseMixinTemplateName();
if (currentIs(TokenType.not)) if (currentIs(TokenType.not))
node.templateArguments = parseTemplateArguments(); node.templateArguments = parseTemplateArguments();
if (currentIs(TokenType.identifier)) if (currentIs(TokenType.identifier))
node.identifier = advance(); node.identifier = advance();
expect(TokenType.semicolon);
return node; return node;
} }
@ -6007,14 +6006,23 @@ private:
return node; return node;
} }
ListType parseCommaSeparatedRule(alias ListType, alias ItemType)() ListType parseCommaSeparatedRule(alias ListType, alias ItemType)(bool allowTrailingComma = false)
{ {
auto node = new ListType; auto node = new ListType;
while (true) while (true)
{ {
mixin ("node.items ~= parse" ~ ItemType.stringof ~ "();"); mixin ("node.items ~= parse" ~ ItemType.stringof ~ "();");
if (currentIs(TokenType.comma)) if (currentIs(TokenType.comma))
{
advance(); advance();
if (allowTrailingComma && currentIsOneOf(TokenType.rParen,
TokenType.rBrace, TokenType.rBracket))
{
break;
}
else
continue;
}
else else
break; break;
} }