Introduction
dsl-lang is a language server and a pair of libraries for .dsl files: domain-specific languages made of calls with
arguments and trailing blocks.
// Services and what they may use
service("orders") {
replicas(3)
uses("community.flock.payments.PaymentClient")
routes {
post("/orders", auth = true)
}
}
Nothing in it is about one DSL. The server knows no function names: it highlights, outlines and checks any file in this syntax, and what it knows of your DSL comes from a schema of it.
What an editor gets
- Semantic highlighting. It goes by the shape of a file, not by the names in it, so it works for any DSL:
- A call with a block is a keyword.
- Any other call is a function.
- In a string with a dotted name, every package is a namespace and every class is a class.
- Strings, numbers, comments, named arguments,
true,falseandnullhave their own colors.
- Syntax errors, such as a missing
),}or". - Checks against a schema of the DSL, when the project has one: a keyword the schema does not have, or one in a block where it does not belong, is an error.
- Completion of the keywords that fit at the cursor, from the same schema.
- An outline of the calls and their blocks, also used for breadcrumbs. A call with one string argument, such as
pkg("api") { }, is shown by that string. - Folding of blocks, argument lists and comments.
In the script above:
| In the script | Is colored as |
|---|---|
service, routes | A keyword: a call with a block. |
replicas, uses, post | A function: any other call. |
"orders", "/orders" | A string. |
community, flock, payments | A namespace. |
PaymentClient | A class. |
3 | A number. |
auth | A parameter. |
true | A keyword. |
The token types are the standard ones of the language server protocol (keyword, function, namespace, class,
string, comment, ...), so every theme colors them.
What an application gets
The libraries for Java and npm parse a .dsl file and give what is in it: the calls, their
arguments and their blocks. They use the parser of the language server, so an application reads a file exactly as
the editor does.
Where to go
- Getting started: a script, a schema and an editor, in a few minutes.
- The DSL: the syntax of a
.dslfile. - Schemas: tell the server which keywords your DSL has.
- Install the language server and set up your editor.
- Libraries: read a
.dslfile in your own tool.