DSL are implemented with the preprocessor operating directly on the text of the code. Languages are structured text. By manipulating the text through code, the structure is lost. This means things like syntax highlighting, formatting and indentation, documentation look, auto complete, and others, will fail. It is also currently very difficult to have multiple DSL at once.
I’m proposing we should make DSLs structured, a token in the parser that the tooling doesn’t look into (like a string), or when an appropriate DSL class is given, can be used to highlight and validate the DSL code.
Here are some initial ideas how this could look syntactically.
// DSL class
DrumL {
highlight {}
parse {}
}
// delimited
DrumL #( ... dsl code ... )#
// until semi colon
DrumL #> .... dsl code ....;
The dsl code would basically be a string.
var str = #> ... dsl code ...;
str.postln;
DrumL(str)
Some other ideas for DSL delimiters…
DSLRegister(1, DrumL);
DSLRegister(2, SomeOtherLanguage);
#1 ... dsl code ... ;
~result_of_drum_l = #1 ...dsl code...;
~result_of_someother = #2 ... dsl code ...;
// multiline
#1 ... dsl code ...
... more dsl code ...
... etc. ...
;
// or
#1 ... dsl code ...
#1 ... more dsl code ...
#1 ... etc. ...
;
@jamshark70 has already raised the point about brevity and need to be able to type this quickly, is this new suggestion better? If people have other ideas, do say!
I don’t want to talk about parsing/DSL implementation here, only how it can be scoped. Later it is definitively worth discussing LSP & IDE integration, but lets wait on that.