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

View File

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