diff --git a/astprinter.d b/astprinter.d index e1bff6d..33c2165 100644 --- a/astprinter.d +++ b/astprinter.d @@ -592,7 +592,8 @@ class XMLPrinter : ASTVisitor { output.writeln(""); output.writeln(""); - visit(gotoStatement.expression); + if (gotoStatement.expression) + visit(gotoStatement.expression); output.writeln(""); output.writeln(""); } diff --git a/std/d/ast.d b/std/d/ast.d index 9e508bf..a44b473 100644 --- a/std/d/ast.d +++ b/std/d/ast.d @@ -2302,6 +2302,8 @@ public: mixin (visitIfNotNull!(expression)); } /** */ Expression expression; + /** */ size_t startLocation; + /** */ size_t endLocation; mixin OpEquals; } diff --git a/std/d/parser.d b/std/d/parser.d index c2b410f..65b21bd 100644 --- a/std/d/parser.d +++ b/std/d/parser.d @@ -4425,10 +4425,14 @@ q{(int a, ...) { mixin(traceEnterAndExit!(__FUNCTION__)); auto node = allocate!ReturnStatement; - if (expect(tok!"return") is null) return null; + auto start = expect(tok!"return"); + if (start is null) return null; + node.startLocation = start.index; if (!currentIs(tok!";")) node.expression = parseExpression(); - if (expect(tok!";") is null) return null; + auto semicolon = expect(tok!";"); + if (semicolon is null) return null; + node.endLocation = semicolon.index; return node; }