Feature: Comment support #171

Open
opened 2024-04-15 19:31:48 +01:00 by deavmi · 24 comments
Owner

Purpose ✍️

To add support for comments and have them attach to the nearest AST node.

Checklist 🗒️

  • A CommentParser that understands both /** (multi-line) and // (single-line) comments
  • The usage and attachment of Comments in the right places at the right times, within the Parser
  • Allow @<param> to span multiple lines till next 2 is encountered
  • Parser to maybe use previous-token checks rather than what is on stack, for checking for comments. We need to keep track of prevToken maybe, and then on-demand "Is there a SymbolType.COMMENT in prevToken?".
    • If so, then auto-construct a Comment, and return it
    • If not, then discard.
    • Implement proxying nextToken(), etc. methods (this will store this.prevToken for us)
    • Handle stars-and-bars even betters for multi-line comments
# Purpose ✍️ To add support for comments and have them attach to the nearest AST node. ## Checklist 🗒️ - [x] A `CommentParser` that understands both `/**` (multi-line) and `//` (single-line) comments - [ ] The usage and attachment of `Comment`s in the right places at the right times, within the `Parser` - [ ] Allow `@<param>` to span multiple lines **till next `2`** is encountered - [ ] `Parser` to maybe use previous-token checks rather than what is on stack, for checking for comments. We need to keep track of `prevToken` maybe, and then on-demand _"Is there a `SymbolType.COMMENT` in `prevToken`?"_. * If **so**, then auto-construct a `Comment`, and return it * If **not**, then discard. - [x] Implement proxying `nextToken()`, etc. methods (this will store `this.prevToken` for us) - [ ] Handle stars-and-bars even betters for **multi-line** comments
deavmi self-assigned this 2024-04-15 19:31:52 +01:00
deavmi added this to the Parser project 2024-04-15 19:31:56 +01:00
deavmi added this to the Basics milestone 2024-04-15 19:32:02 +01:00
deavmi added the
parser
qol
question
labels 2024-04-15 19:32:07 +01:00
deavmi added the due date 2024-04-30 2024-04-15 19:32:16 +01:00
deavmi started working 2024-04-15 19:39:01 +01:00
deavmi stopped working 2024-04-15 19:40:21 +01:00
1 minute 20 seconds
deavmi added reference feature/comments 2024-04-15 19:41:08 +01:00
deavmi started working 2024-04-15 20:39:08 +01:00
Author
Owner

Working on ther comment sdtack now

Working on ther comment sdtack now
Author
Owner

Will continue tomorrow

Will continue tomorrow
deavmi stopped working 2024-04-15 21:01:32 +01:00
22 minutes 23 seconds
deavmi started working 2024-04-16 07:18:54 +01:00
deavmi stopped working 2024-04-16 07:36:55 +01:00
18 minutes 1 second
deavmi started working 2024-04-16 09:44:33 +01:00
Author
Owner

Working on the CommentParser now...

Working on the `CommentParser` now...
Author
Owner

CommentParser looks like it is working for multi-line.
Now need to add singl-line support.

`CommentParser` looks like it is working for multi-line. Now need to add singl-line support.
deavmi stopped working 2024-04-16 11:36:54 +01:00
1 hour 52 minutes
deavmi started working 2024-04-16 11:37:18 +01:00
deavmi stopped working 2024-04-16 11:54:32 +01:00
17 minutes 14 seconds
deavmi started working 2024-04-16 16:21:09 +01:00
Author
Owner

Working on parsing things like @param i This is stuff

Working on parsing things like `@param i This is stuff`
Author
Owner

Damn man, why is this such a dogshit implementation. It is so ugly, let me do it propetly:

string buildUp;
        bool foundType = false;
        DocType dType;
        bool foundName;
        string paramName;
        bool inDescr;

        ulong i = 0;
        bool getch(ref char c)
        {
            if(i < line.length)
            {
                c = line[i];
                return true;
            }
            return false;
        }

        void prog()
        {
            i++;
        }

        char c;
        while(getch(c))
        {
            if(c == ' ' && !inDescr)
            {
                prog();
                continue;
            }
            else if(c == '@' && !foundType)
            {
                string paramType;
                prog();
                while(getch(c) && c != ' ')
                {
                    paramType ~= c;
                    prog();
                }

                // TODO: Now validate `name`
                if(paramType == "param")
                {
                    foundType = true;
                    dType = DocType.PARAM;
                }
            }
            else if(!foundName)
            {
                while(getch(c) && c != ' ')
                {
                    paramName ~= c;
                    prog();
                }

                // TODO: check name?
                foundName = true;
            }
            else
            {

            }
        }
Damn man, why is this such a dogshit implementation. It is so ugly, let me do it propetly: ```d string buildUp; bool foundType = false; DocType dType; bool foundName; string paramName; bool inDescr; ulong i = 0; bool getch(ref char c) { if(i < line.length) { c = line[i]; return true; } return false; } void prog() { i++; } char c; while(getch(c)) { if(c == ' ' && !inDescr) { prog(); continue; } else if(c == '@' && !foundType) { string paramType; prog(); while(getch(c) && c != ' ') { paramType ~= c; prog(); } // TODO: Now validate `name` if(paramType == "param") { foundType = true; dType = DocType.PARAM; } } else if(!foundName) { while(getch(c) && c != ' ') { paramName ~= c; prog(); } // TODO: check name? foundName = true; } else { } } ```
Author
Owner

Look at that, doc string parsing!

image

Look at that, doc string parsing! ![image](/attachments/9bbcfff1-f142-48ad-a4a3-69672c5e0d7b)
deavmi stopped working 2024-04-16 18:02:24 +01:00
1 hour 41 minutes
deavmi started working 2024-04-16 18:02:26 +01:00
deavmi stopped working 2024-04-16 19:12:03 +01:00
1 hour 9 minutes
deavmi started working 2024-04-16 19:30:40 +01:00
Author
Owner

Working on adding support for @returns parsing now...

Working on adding support for `@returns` parsing now...
Author
Owner

Working on adding support for @returns parsing now...

Added

> Working on adding support for `@returns` parsing now... Added ✅
Author
Owner

Working on adding support for @returns parsing now...

Added

Added some fixes here and there

> > Working on adding support for `@returns` parsing now... > > Added ✅ Added some fixes here and there
Author
Owner

Damn man, why is this such a dogshit implementation. It is so ugly, let me do it propetly:

string buildUp;
        bool foundType = false;
        DocType dType;
        bool foundName;
        string paramName;
        bool inDescr;

        ulong i = 0;
        bool getch(ref char c)
        {
            if(i < line.length)
            {
                c = line[i];
                return true;
            }
            return false;
        }

        void prog()
        {
            i++;
        }

        char c;
        while(getch(c))
        {
            if(c == ' ' && !inDescr)
            {
                prog();
                continue;
            }
            else if(c == '@' && !foundType)
            {
                string paramType;
                prog();
                while(getch(c) && c != ' ')
                {
                    paramType ~= c;
                    prog();
                }

                // TODO: Now validate `name`
                if(paramType == "param")
                {
                    foundType = true;
                    dType = DocType.PARAM;
                }
            }
            else if(!foundName)
            {
                while(getch(c) && c != ' ')
                {
                    paramName ~= c;
                    prog();
                }

                // TODO: check name?
                foundName = true;
            }
            else
            {

            }
        }

Tomorrow I will continue. I am also working on it in a nicer refactored parser for now and I am much happier with how the code is looking now.

> Damn man, why is this such a dogshit implementation. It is so ugly, let me do it propetly: > > ```d > string buildUp; > bool foundType = false; > DocType dType; > bool foundName; > string paramName; > bool inDescr; > > ulong i = 0; > bool getch(ref char c) > { > if(i < line.length) > { > c = line[i]; > return true; > } > return false; > } > > void prog() > { > i++; > } > > char c; > while(getch(c)) > { > if(c == ' ' && !inDescr) > { > prog(); > continue; > } > else if(c == '@' && !foundType) > { > string paramType; > prog(); > while(getch(c) && c != ' ') > { > paramType ~= c; > prog(); > } > > // TODO: Now validate `name` > if(paramType == "param") > { > foundType = true; > dType = DocType.PARAM; > } > } > else if(!foundName) > { > while(getch(c) && c != ' ') > { > paramName ~= c; > prog(); > } > > // TODO: check name? > foundName = true; > } > else > { > > } > } > ``` Tomorrow I will continue. I am also working on it in a nicer refactored parser for now and I am much happier with how the code is looking now.
deavmi stopped working 2024-04-16 20:23:16 +01:00
52 minutes 37 seconds
deavmi started working 2024-04-16 20:42:26 +01:00
deavmi stopped working 2024-04-16 20:42:29 +01:00
3 seconds
deavmi added spent time 2024-04-16 20:42:33 +01:00
3 minutes
deavmi started working 2024-04-16 20:42:35 +01:00
deavmi stopped working 2024-04-17 10:42:00 +01:00
13 hours 59 minutes
deavmi started working 2024-04-17 10:42:02 +01:00
Author
Owner

Neatening some things up

Neatening some things up
Author
Owner

Neatening some things up

Done

> Neatening some things up Done ✅
Author
Owner

Came up with a method to improve how comments are matched in the Parser.

Came up with a method to improve how comments are matched in the `Parser`.
deavmi stopped working 2024-04-17 11:00:40 +01:00
18 minutes 38 seconds
deavmi started working 2024-04-17 11:01:16 +01:00
Author
Owner

The this.prevToken won't necessarily work.

The `this.prevToken` won't necessarily work.
Author
Owner

The this.prevToken won't necessarily work.

Or it may, I could be wrong, it's just where you hoist the comment out from, or when

> The `this.prevToken` won't necessarily work. Or it may, I could be wrong, it's just where you hoist the comment out from, or _when_
Author
Owner

Fixing single line extraction...

Fixing single line extraction...
Author
Owner

Comments

  • Added single-line comment support
Comments - Added single-line comment support
Author
Owner

Parser

  • Added debug print
Parser - Added debug print
Author
Owner

Fixing single line extraction...

Fixed

> Fixing single line extraction... Fixed ✅
deavmi stopped working 2024-04-17 16:19:47 +01:00
5 hours 18 minutes
deavmi started working 2024-04-17 16:19:54 +01:00
deavmi stopped working 2024-04-17 16:26:28 +01:00
6 minutes 34 seconds
deavmi added spent time 2024-04-17 19:16:20 +01:00
3 minutes
deavmi started working 2024-04-17 19:34:30 +01:00
deavmi stopped working 2024-04-17 19:59:28 +01:00
24 minutes 58 seconds
deavmi started working 2024-04-17 20:13:17 +01:00
deavmi stopped working 2024-04-17 21:08:03 +01:00
54 minutes 46 seconds
deavmi started working 2024-04-17 21:09:57 +01:00
Author
Owner

Cleaned up more of the parsing to handle a lot of more edge cases and neatly return the doc s

Cleaned up more of the parsing to handle a lot of more edge cases and neatly return the doc s
Author
Owner

Done for tonight 😴

Done for tonight 😴
deavmi stopped working 2024-04-17 21:17:20 +01:00
7 minutes 23 seconds
deavmi started working 2024-04-18 10:52:45 +01:00
deavmi stopped working 2024-04-18 10:54:09 +01:00
1 minute 24 seconds
deavmi started working 2024-04-18 16:37:51 +01:00
deavmi stopped working 2024-04-18 16:39:45 +01:00
1 minute 54 seconds
deavmi started working 2024-04-20 20:10:03 +01:00
Author
Owner

Working now on unittests for the comment parsing. These will be placed within the parsing/core.d

Working now on unittests for the comment parsing. These will be placed within the `parsing/core.d`
deavmi stopped working 2024-04-20 20:34:47 +01:00
24 minutes 44 seconds
deavmi added spent time 2024-04-22 10:37:03 +01:00
2 minutes
deavmi started working 2024-04-22 10:38:22 +01:00
Author
Owner

I want to have this be an early commit. I know I have not yet implemented run-on-lines doc-strings but I am not so sure how urgent that is right now.

I want to have this be an early commit. I know I have not yet implemented run-on-lines doc-strings but I am not so sure how urgent that is right now.
deavmi stopped working 2024-04-22 10:48:37 +01:00
10 minutes 15 seconds
deavmi started working 2024-05-05 12:54:47 +01:00
deavmi stopped working 2024-05-05 12:55:42 +01:00
55 seconds
deavmi started working 2024-05-05 13:05:53 +01:00
deavmi removed the due date 2024-04-30 2024-05-05 13:05:56 +01:00
deavmi added the due date 2024-05-31 2024-05-05 13:06:02 +01:00
deavmi stopped working 2024-05-05 13:09:43 +01:00
3 minutes 50 seconds
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Total Time Spent: 1 day 4 hours
deavmi
1 day 4 hours
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

2024-05-31

Dependencies

No dependencies set.

Reference: tlang/tlang#171
No description provided.