From ad67ce63091284b7872f0d7786dfb5bca10c4ecc Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Tue, 16 Apr 2024 20:11:59 +0200 Subject: [PATCH] Parser - Use the new `Comment` API --- source/tlang/compiler/parsing/core.d | 37 ++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/source/tlang/compiler/parsing/core.d b/source/tlang/compiler/parsing/core.d index 328f677d..3dd21046 100644 --- a/source/tlang/compiler/parsing/core.d +++ b/source/tlang/compiler/parsing/core.d @@ -445,6 +445,23 @@ public final class Parser { Statement ret; + /* If there are any comments available then pop them off now */ + // TODO: Check if we should pop anything off of the comment + // stack here + Comment potComment; + if(hasCommentsOnStack()) + { + potComment = popComment(); + } + + scope(exit) + { + if(potComment) + { + ret.setComment(potComment); + } + } + /* Save the name or type */ string nameTYpe = lexer.getCurrentToken().getToken(); DEBUG("parseName(): Current token: "~lexer.getCurrentToken().toString()); @@ -2181,7 +2198,8 @@ public final class Parser } import std.container.slist : SList; - private SList!(Token) commentStack; + import tlang.compiler.symbols.comments; + private SList!(Comment) commentStack; private void pushComment(Token commentToken) { // Sanity check @@ -2190,7 +2208,7 @@ public final class Parser ); // Push it onto top of stack - commentStack.insertFront(commentToken); + commentStack.insertFront(Comment.fromToken(commentToken)); } //TODO: Add a popToken() (also think if we want a stack-based mechanism) private bool hasCommentsOnStack() @@ -2204,6 +2222,13 @@ public final class Parser return walkLength(commentStack[]); } + private Comment popComment() + { + Comment popped = commentStack.front(); + commentStack.removeFront(); + return popped; + } + private void parseComment() { WARN("parseComment(): Enter"); @@ -2396,6 +2421,14 @@ public final class Parser expect("parseStatement(): Unknown symbol: " ~ lexer.getCurrentToken().getToken()); } + // // TODO: Check if we should pop anything off of the comment + // // stack here + // if(hasCommentsOnStack()) + // { + // statement.setComment(popComment()); + // } + + WARN("parseStatement(): Leave"); return statement;