Open SamKomesarook opened 3 years ago
@kunstmusik @stekyne Hey ya'll, would be great to get a quick prelim opinion from you both about how I was going to go about this in regard to #21. This branch has a basic example of the first way formatting could work, whereby we (kinda hackishly) parse each line via string.contains
rules, and format them that way.
Alternatively, we could add a lexer/parser lib like ANTLR, create a csound grammar, tokenise each program, and programmatically style it. This would be far more accurate, but might be overkill and would be a lot more complex.
Am I good to build out functionality via the first method?
@SamKomesarook I think formatters are going to be difficult no matter which way you go (e.g., regexes, custom parsing, parser, etc). In particular, there's different styles of csound code and some of it is contextual (i.e., aligning comments that are to the right of text block). There's also code that spans multiple lines via \ or using function-call syntax like
opcode(1,
2,
3)
One thing you might look at is Nate Whetsell's linter-csound package for Atom:
https://github.com/nwhetsell/linter-csound
We've definitely reused a bit of his work in this project. Another might be to look at implementing a plugin for Prettier, but that might be difficult.