diff --git a/std/d/ast.d b/std/d/ast.d index 6059a9d..be46bee 100755 --- a/std/d/ast.d +++ b/std/d/ast.d @@ -567,6 +567,17 @@ class BlockStatement : ASTNode { public: mixin(DEFAULT_ACCEPT); + + /** + * Byte position of the opening brace + */ + size_t startLocation; + + /** + * Byte position of the closing brace + */ + size_t endLocation; + /** */ DeclarationsAndStatements declarationsAndStatements; } @@ -1740,6 +1751,15 @@ class StructBody : ASTNode { public: mixin(DEFAULT_ACCEPT); + /** + * Byte position of the opening brace + */ + size_t startLocation; + + /** + * Byte position of the closing brace + */ + size_t endLocation; /** */ Declaration[] declarations; } diff --git a/std/d/parser.d b/std/d/parser.d index f277fc5..9c6945a 100755 --- a/std/d/parser.d +++ b/std/d/parser.d @@ -848,10 +848,14 @@ alias core.sys.posix.stdio.fileno fileno; { mixin(traceEnterAndExit!(__FUNCTION__)); auto node = new BlockStatement(); - if (expect(TokenType.lBrace) is null) return null; + auto openBrace = expect(TokenType.lBrace); + if (openBrace is null) return null; + node.startLocation = openBrace.startIndex; if (!currentIs(TokenType.rBrace)) node.declarationsAndStatements = parseDeclarationsAndStatements(); - if (expect(TokenType.rBrace) is null) return null; + auto closeBrace = expect(TokenType.rBrace); + if (closeBrace is null) return null; + node.endLocation = closeBrace.startIndex; return node; } @@ -4539,10 +4543,10 @@ q{(int a, ...) { mixin(traceEnterAndExit!(__FUNCTION__)); auto node = new StructBody; - expect(TokenType.lBrace); + node.startLocation = expect(TokenType.lBrace).startIndex; while (!currentIs(TokenType.rBrace) && moreTokens()) node.declarations ~= parseDeclaration(); - expect(TokenType.rBrace); + node.endLocation = expect(TokenType.rBrace).startIndex; return node; }