rokucommunity / brighterscript

A superset of Roku's BrightScript language
MIT License
160 stars 46 forks source link

Parse brs comment documentation #512

Open TwitchBronBron opened 2 years ago

TwitchBronBron commented 2 years ago

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:

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

markwpearce commented 2 years ago

Nice!

My jsdocs plugin does a lot of this is more ad-hoc kind of way.

Maybe some of that code could be a little useful?

https://github.com/markwpearce/brighterscript-jsdocs-plugin/blob/master/convert-brighterscript-docs.js