rokucommunity / rokucommunity/brighterscript

Parse brs comment documentation

Open
#512 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
208
Forks
68
Avg merge
8h 39m
Merged PRs (30d)
39

Description

We should parse leading comments before all statements. This will allow us to gain more information about the statements, helping both brightscript and brighterscript. As a first step:

  • when parsing any statement, collect all sequential comments prior to the function and include them in a new documentation property on the Statement. Only one statement should "own" comments. Example:
    'Collect me
    ' 
    ' me too
    ' me three
    sub main()
    end sub
    
  • Many projects use the brightscript ' token but then also add /** jsdoc blocks to help integrate with existing jsdoc parsers. If /** is detected, scan through every comment and remove leading * and */ tokens. Only do this if EVERY comment starts with one of those. That way, our parser is more flexible and supports existing practices. Example:
    ' /**
    '  * Some jsdoc style comment
    '  */
    function DoSomething()
    end function
    
  • we should parse and collect tags which can be leveraged by our code, as well as any plugins that might find use for them. Tags are on their own line, and start with the @ symbol.
    ' Function that returns a name
    ' @param {string} firstName
    ' @return {string}
    function returnName(firstName as string)
        return firstName
    end function
    
  • needs to support the syntax of BrightScriptDoc explained here. I envision most of these just get included as "tags" related to the previous bullet point, but just keep them in mind.

I would imagine the documentation object on Statement would look something like this in typescript:

class Statement {
    //...existing stuff
    public documentation: DocumentationStatement;
}
class DocumentationStatement{
    public comment: Token; //contains the leading comment
    public tags: TagExpression[];
    public range: Range;
}
class DocumentationTagExpression {
    public tokens: {
        at: Token; //the "@" symbol
        name: Identifier; //the word "param" in "@param", or "return" in "@return"
        leadingTypeCurlyBrace: Token;
        type: Identifier;
        trailingTypeCurlyBrace: Token;
        comment: Token; //any remaining unparsed text
    }
    public range: Range;
}

This ASTExplorer from typescript is very helpful to use for reference.
image

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the TypeScript parser logic for Statement nodes and compare the proposed DocumentationStatement and DocumentationTagExpression shapes with the TypeScript ASTExplorer reference. Read the linked BrightScriptDoc syntax and determine how leading comments, jsdoc-style markers, and @ tags should be represented; done means statements expose the documented comments and tags with the specified ranges and tokens.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.