ID:2374856
 
Hello, In the past I tried to make BYOND grammar for Intellij Editor but failed to create proper grammar and spent a lot of time debugging and trying to make my grammar unambigous.

Few weeks ago I started using ANTLR4 in Daedalus compiler project (scripting language for modding game Gothic by Piranha Bytes) and was shocked how easy it was, and how the grammar magically worked.

WithANTLR4 I was able to write grammar for BYOND's file format (I used ANTLR4 Python's grammar as a reference). It's not complete but it successfully parsed every file from some of my old BYOND projects. I currently do not support separating instructions by ';' and having blocks inside '{' and '}' because I thought it would make the grammar much less readable. I also ignore all spaces but BYOND sometimes doesn't:
mob/Login()
is correct in BYOND, but
mob/ Login()
isn't. My grammar accept both. There are also some kind of super weird constructs that BYOND accapets but I chose that my grammar shouldn't. For example:
mob/var/var/tmp/tmp/tmp = 5

mob/Login()
..........
..........
..........

mob/Login()
if(1) if(2) if(3) world << 3



I guess there is a lot of things missing in the grammar but it's a good start.
It could be used to create some kind of linter, code auto formatter or BYOND plugin for Intellij since it's possible to use ANTLR4 grammars there: https://intellij-support.jetbrains.com/hc/en-us/community/ posts/206103369-Using-ANTLR-v4-to-lex-parse-custom-file-form ats

However I guess that using it in the Intellij would be pain in the ass, and it would be better to write PEG-based BNF grammar like they expect. I would love to do it sometime in the future but currently don't have skillset to do so.

If anybody want to help or give me some hints or feedback, please do.

Grammar: https://github.com/Kisioj/BYOND-ANTLR4