rokucommunity / brightscript-formatter

This project is no longer maintained. Its successor is brighterscript-formatter
https://github.com/RokuCommunity/brighterscript-formatter
Apache License 2.0
5 stars 5 forks source link

Create a BrightScript parser to allow for better insight into the source files #7

Closed TwitchBronBron closed 4 years ago

TwitchBronBron commented 6 years ago

The current implementation of brightscript-formatter is quite basic, which presents a number of issues when trying to do more complicated formatting.

distinguising between single-line and multi-line if statments is very hard without a parser.

Take this code snippet for example.

if true and getSomeBoolean() and 1=1 and (1+2 / 3 * 4) * getSomeNumber() = 12
    doSomething
end if

Without a parser, it's quite difficult to know whether the if statement is a single-line statment or the start of a multi-line if statement. A formal parser would allow us to boil all of that down into a simple AST node that we could better reason about.

nishtahir commented 6 years ago

We've created a rather accurate Brightscript grammar which we use to generate a lexer and parser in our linter project that might be useful in improving the quality of your code formatter.

Would you consider porting your code over to use our AST? This will make it super easy to integrate into our language server and atom plugin

TwitchBronBron commented 6 years ago

Yes, I would definitely consider porting the code to use your project's lexer and parser. Your project is exactly what I was looking for! I just don't have a ton of time right now. I would welcome a pull request with the fixes (as long as the library's public API remains the same). Otherwise, I'll try to get to it in the next few months as time allows.

TwitchBronBron commented 6 years ago

I've got some free time the next few weeks so I'm going to try and get to this.

nishtahir commented 6 years ago

I tried migrating your code to use our AST but because it started looking like I was going to end up rewriting most of it, I found it easier to build it into some experimental work we were already doing. This is the relevant branch.

I also created an issue in order to describe a specification for the formatter here.

TwitchBronBron commented 4 years ago

Closing this issue because the BrighterScript parser now exists and will satisfy the needs of this project.