Skip to main content

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, false and null have 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 scriptIs colored as
service, routesA keyword: a call with a block.
replicas, uses, postA function: any other call.
"orders", "/orders"A string.
community, flock, paymentsA namespace.
PaymentClientA class.
3A number.
authA parameter.
trueA 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​