Skip to main content

Getting started

This page takes a project from nothing to a .dsl script that the editor highlights, checks and completes.

1. Set up your editor​

The extension for VS Code and the plugin for the IDEs of JetBrains come with the language server, so there is nothing else to install.

  • VS Code: install dsl-lang from the Marketplace, or from a terminal:

    code --install-extension dsl-lang.dsl-language
  • IntelliJ IDEA and other JetBrains IDEs: install dsl-lang from Settings > Plugins > Marketplace.

For Neovim and every other editor, install the language server and tell the editor to start it for .dsl files. Editors has the details of each.

2. Write a script​

Make a file byterails.dsl. The name of the file is the name of its DSL: the schema of step 3 is found by it.

byterails.dsl
byterails {
kotlin()
pkg("api") {
allow("org.slf4j")
}
}

The editor colors it, shows it in the outline and folds its blocks. Remove a } and the editor shows where it is missing. So far every name is allowed: without a schema, a script is checked for syntax errors only.

3. Add a schema​

A schema says which keywords the DSL has, and which of them go in the block of which. Put it in a .dsl folder at the root of the project, under the name of the script:

my-project/
.dsl/
byterails.json the schema
byterails.dsl checked against it
.dsl/byterails.json
{
"root": ["byterails"],
"keywords": {
"byterails": { "block": ["kotlin", "pkg"] },
"kotlin": { "description": "Allows what compiled Kotlin uses everywhere.", "arguments": [] },
"pkg": { "description": "A package, and what it may use.", "arguments": ["string"], "block": ["flat", "allow"] },
"flat": { "arguments": [] },
"allow": { "arguments": ["string"] }
}
}

Open the script again. Now a keyword the schema does not have is an error, and so is one in a block where it does not belong:

byterails.dsl
byterails {
kotlin()
package("api") { } // Unknown keyword 'package'. Allowed here: kotlin, pkg
pkg("api") {
allow("org.slf4j")
}
}

Ask for completion in a block, and the editor offers the keywords that fit there, each with its description. Choose pkg and it writes pkg("") { } with the cursor between the quotes, because the schema says in arguments that pkg takes a string.

4. Read the script in your tool​

The tool that the script is for reads it with one of the libraries, with the same parser as the editor:

import { readFileSync } from 'node:fs';
import { allCalls, argument, parseOrThrow } from '@flock/dsl-lang';

const file = parseOrThrow(readFileSync('byterails.dsl', 'utf8'));

for (const pkg of allCalls(file, 'pkg')) {
console.log(argument(pkg, 0).value); // "api"
}

Next​