more implementation work

This commit is contained in:
Hackerpilot 2013-06-15 23:37:37 -07:00
parent 6dc1e4c2ff
commit 3a66f01405
3 changed files with 51 additions and 9 deletions

View File

@ -238,8 +238,7 @@ interface ASTNode
/** */ void accept(ASTVisitor visitor);
}
immutable string DEFAULT_ACCEPT = q{void accept(ASTVisitor visitor) { visitor.visit(this); }};
immutable string DEFAULT_ACCEPT = q{void accept(ASTVisitor visitor) {}};
immutable string SHIFT_SHIFT_BODY = q{
/** */ Token operator;
@ -577,7 +576,16 @@ public:
class AttributedDeclaration : ASTNode
{
public:
mixin(DEFAULT_ACCEPT);
override void accept(ASTVisitor visitor)
{
if (attribute !is null)
visitor.visit(attribute);
foreach (dec; declarations)
{
if (dec !is null)
visitor.visit(dec);
}
}
/** */Attribute attribute;
/** */Declaration[] declarations;
}
@ -848,6 +856,7 @@ public:
if (sharedStaticConstructor !is null) visitor.visit(sharedStaticConstructor);
if (conditionalDeclaration !is null) visitor.visit(conditionalDeclaration);
if (pragmaDeclaration !is null) visitor.visit(pragmaDeclaration);
if (versionSpecification !is null) visitor.visit(versionSpecification);
}
/** */ AttributedDeclaration attributedDeclaration;
@ -873,6 +882,7 @@ public:
/** */ SharedStaticConstructor sharedStaticConstructor;
/** */ ConditionalDeclaration conditionalDeclaration;
/** */ PragmaDeclaration pragmaDeclaration;
/** */ VersionSpecification versionSpecification;
}
///

View File

@ -1344,7 +1344,7 @@ class ClassFour(A, B) if (someTest()) : Super {}};
ConditionalDeclaration parseConditionalDeclaration()
{
auto node = new ConditionalDeclaration;
// TODO
node.compileCondition = parseCompileCondition();
return node;
}
@ -1586,6 +1586,16 @@ class ClassFour(A, B) if (someTest()) : Super {}};
node.variableDeclaration = parseVariableDeclaration(type);
break;
case TokenType.version_:
if (peekIs(TokenType.lParen))
node.conditionalDeclaration = parseConditionalDeclaration();
else if (peekIs(TokenType.assign))
node.versionSpecification = parseVersionSpecification();
else
{
error(`"=" or "(" expected following "version"`);
return null;
}
break;
case TokenType.debug_:
node.conditionalDeclaration = parseConditionalDeclaration();
break;
@ -2982,6 +2992,12 @@ interface "Four"
{
auto node = new NonVoidInitializer;
// TODO
if (curentIs(TokenType.lBrace))
node.structInitializer = parseStructInitializer()
else if (currentIs(TokenType.lBracket))
node.arrayInitializer = parseArrayInitializer()
else
node.assignExpression = parseAssignExpression();
return node;
}
@ -3025,7 +3041,8 @@ interface "Four"
OrOrExpression parseOrOrExpression()
{
auto node = new OrOrExpression;
// TODO
node.andAndExpression = parseAndAndExpression();
return node;
}
@ -3525,8 +3542,12 @@ interface "Four"
{
auto node = new StructBody;
expect(TokenType.lBrace);
while (tokens[index] != TokenType.rBrace && moreTokens())
node.structBodyItems ~= parseStructBodyItem();
version (development)
skipBraceContent();
else
assert (0);
//while (tokens[index] != TokenType.rBrace && moreTokens())
// node.structBodyItems ~= parseStructBodyItem();
expect(TokenType.rBrace);
return node;
}
@ -3967,9 +3988,9 @@ interface "Four"
{
auto node = new TernaryExpression;
node.orOrExpression = parseOrOrExpression();
if (tokens[index] == TokenType.ternary)
if (currentIs(TokenType.ternary))
{
++index;
advance();
node.expression = parseExpression();
expect(TokenType.colon);
node.ternaryExpression = parseTernaryExpression();

View File

@ -33,6 +33,17 @@ class TestVisitor : ASTVisitor
writeln("import declaration found");
}
override void visit(InterfaceDeclaration intDec)
{
writeln("Interface ", intDec.identifier.value,
" on line ", intDec.identifier.line);
}
override void visit(VersionSpecification verSpec)
{
writeln("Version specification");
}
alias ASTVisitor.visit visit;
}