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

Tokenizer anomalies #3

Closed crwecker closed 6 years ago

crwecker commented 6 years ago

So, ran the rest of my code through the formatter this morning, and two more issues cropped up (both in obsolete code, but thought I'd make you aware).

  1. Something in this breaks the keyword count. Seems like it has to do with the "] at the end of the statement

    function test()
    asdf = "asdf: " + anytostring(m.asdf["asdf"])
    end function
  2. A single line if statement, like this from the documentation, messes up the indentation after it

    sub test()
    if x > 127 then print "out of range"
    end sub

Regards! -Carl

crwecker commented 6 years ago

Oh, just spotted another that is possibly related to item 1. Indentation messed up.

  if (m.externalAuth) then
    jsonData["Access Type"] = "Accessible"
    else
      jsonData["Access Type"] = "Link Required"
      end if
crwecker commented 6 years ago

Sorry, didn't mean to close the issue, I clicked on the close button thinking it would close the window (:

TwitchBronBron commented 6 years ago

Haha. I was confused there for a second.

I'll take a look at these tonight and see what I come up with. Great finds again. This just just goes to show how valuable the whole open source concept is. It only makes the product better. I love it!

Thanks for your help! I'll let you know what I find.

crwecker commented 6 years ago

Probably the same issue: new indents after each of these lines:

  lineups_index["audio"] = CreateObject("roAssociativeArray")
    lineups_index["video"] = CreateObject("roAssociativeArray")
      ci = 0
TwitchBronBron commented 6 years ago

I fixed these issues. Fun stuff! The way that I implemented the formatter, I'm not doing any type of code validation (i.e. parsing). It's much more primitive.

The brightscript spec says that the "then" in an if statement is optional. https://sdkdocs.roku.com/display/sdkdoc/Program+Statements#ProgramStatements-IFexpressionTHENstatements[ELSEstatements]

For the one-line if statements, I don't have a nice way of figuring out when the logical expression ends and the operation begins. So things like this will probably still cause issues

sub test()
    if 1=1 and 2=2 return 12
end sub

Until I can write a full brightscript parser, I'll probably not be able to support that particular format.

Anyway, try out the latest npm package and let me know if that solves your issue.

crwecker commented 6 years ago

Worked great. Thanks!