From f593299623ccc5b4872f3491938fbde71d1808ff Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Tue, 29 Oct 2013 13:54:22 -0700 Subject: [PATCH] Fix #68 --- astprinter.d | 26 ++++++++++++++++++-------- stdx/d/ast.d | 4 ++-- stdx/d/parser.d | 26 ++++++++++++++------------ 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/astprinter.d b/astprinter.d index a110b9f..eb4a69c 100644 --- a/astprinter.d +++ b/astprinter.d @@ -493,6 +493,20 @@ class XMLPrinter : ASTVisitor { output.writeln(""); + if (foreachStatement.foreachType !is null) + visit(foreachStatement.foreachType); + if (foreachStatement.foreachTypeList !is null) + visit(foreachStatement.foreachTypeList); + output.writeln(""); + visit(foreachStatement.low); + output.writeln(""); + if (foreachStatement.high !is null) + { + output.writeln(""); + visit(foreachStatement.high); + output.writeln(""); + } + visit(foreachStatement.declarationOrStatement); output.writeln(""); } @@ -571,18 +585,14 @@ class XMLPrinter : ASTVisitor } } - override void visit(IdentifierChain chain) + override void visit(IdentifierChain identifierChain) { - output.writeln(""); - chain.accept(this); - output.writeln(""); + mixin (tagAndAccept!"identifierChain"); } - override void visit(IdentifierList list) + override void visit(IdentifierList identifierList) { - output.writeln(""); - list.accept(this); - output.writeln(""); + mixin (tagAndAccept!"identifierList"); } override void visit(IdentifierOrTemplateChain identifierOrTemplateChain) diff --git a/stdx/d/ast.d b/stdx/d/ast.d index 33277e8..babb016 100644 --- a/stdx/d/ast.d +++ b/stdx/d/ast.d @@ -1205,14 +1205,14 @@ public: override void accept(ASTVisitor visitor) { mixin (visitIfNotNull!(foreachType, foreachTypeList, low, high, - statementNoCaseNoDefault)); + declarationOrStatement)); } /** */ TokenType type; /** */ ForeachTypeList foreachTypeList; /** */ ForeachType foreachType; /** */ Expression low; /** */ Expression high; - /** */ StatementNoCaseNoDefault statementNoCaseNoDefault; + /** */ DeclarationOrStatement declarationOrStatement; /** */ size_t startIndex; } diff --git a/stdx/d/parser.d b/stdx/d/parser.d index ad619a0..31ff081 100644 --- a/stdx/d/parser.d +++ b/stdx/d/parser.d @@ -1815,12 +1815,12 @@ class ClassFour(A, B) if (someTest()) : Super {}}c; // Declarations are resolved by the declarations taking precedence." if (isDeclaration()) { - trace("+++ parsing declaration"); + trace("\033[01;36mparsing declaration"); node.declaration = parseDeclaration(); } else { - trace("+++ parsing statement"); + trace("\033[01;36mparsing statement"); node.statement = parseStatement(); } @@ -2232,13 +2232,13 @@ class ClassFour(A, B) if (someTest()) : Super {}}c; node.foreachTypeList = feType; } if (expect(TokenType.rParen) is null) return null; - if (currentIs(TokenType.rBrace)) - { - error("Statement expected", false); - return node; // this line makes DCD better - } - node.statementNoCaseNoDefault = parseStatementNoCaseNoDefault(); - if (node.statementNoCaseNoDefault is null) return null; + if (currentIs(TokenType.rBrace)) + { + error("Statement expected", false); + return node; // this line makes DCD better + } + node.declarationOrStatement = parseDeclarationOrStatement(); + if (node.declarationOrStatement is null) return null; return node; } @@ -2256,7 +2256,7 @@ class ClassFour(A, B) if (someTest()) : Super {}}c; if (currentIsOneOf(TokenType.ref_, TokenType.const_, TokenType.immutable_, TokenType.shared_, TokenType.inout_)) { - trace("+++ Type constructor"); + trace("\033[01;36mType constructor"); if ((node.typeConstructors = parseTypeConstructors()) is null) return null; } @@ -6507,8 +6507,10 @@ protected: template traceEnterAndExit(string fun) { - enum traceEnterAndExit = `version (std_parser_verbose) trace(">>> ` ~ fun ~ ` ");` - ~ `version (std_parser_verbose) scope(exit) trace("<<< ` ~ fun ~ ` ");`; + enum traceEnterAndExit = `version (std_parser_verbose) trace("` + ~ "\033[01;32m" ~ fun ~ "\033[0m" ~ ` ");` + ~ `version (std_parser_verbose) scope(exit) trace("` + ~ "\033[01;31m" ~ fun ~ "\033[0m" ~ ` ");`; } version (std_parser_verbose)