💻 Lab: designing and implementing the Dialogue DSL abstract syntax
In all the following lab sessions we will design an implement a DSL named the Dialogue DSL. The proposed specifications of this DSL is available on a dedicated page: 🗒️ Resource: Dialogue DSL specifications.
| We will simulate an iterative process for the DSL design and implementation, hence the specifications describe different versions of the DSL. To make sure you can progress on different versions in parallel, you will have to create one separate Langium project per version. |
1. Abstract syntax for the Dialogue DSL V1
In this first part we focus on the V1 of the Dialogue DSL.
1.2. Abstract syntax implementation
1.2.1. Generate the Dialogue DSL project
Using Yeoman, initialize a Langium project for your own Dialogue DSL with the following choices:
-
Your extension name:
dialogue-dsl-v1 -
Your language name:
Dialogue DSL V1 -
File extensions:
.dialogv1 -
Your grammar entry rule name: here put the name of the root concept of your abstract syntax design
-
Include VSCode extension?: Yes
-
Generate example project?: No
-
Include CLI?: Yes
-
Include language tests?: No
1.2.2. Implement the abstract syntax
-
Implement your abstract syntax in a separate file
packages/language/src/dialogue-dsl-v1.abstractsyntax.langium, -
Import this new file at the beginning of the existing file
packages/language/src/dialogue-dsl-v1.langium, -
Call the Langium Generator and compile the project.
| Do not touch the grammar yet, we will work on it in the next chapter! |
1.2.3. Testing the abstract syntax by manually constructing ASTs
-
Create a file
packages/language/src/ast-test.ts, and write a program that creates an AST for the very first V1 dialogue tree shown in the specifications. -
Open a JavaScript Debug Terminal and using a breakpoint and the debugger check that your constructer AST is correct.
2. Abstract syntax for the Dialogue DSL V2
In this first part we focus on the V2 of the Dialogue DSL.
2.1. Abstract syntax design
Using the metamodel prepared for the V1 of the Dialogue DSL as a starting point, propose an abstract syntax design for the V2.
2.2. Abstract syntax implementation
-
Generate a new separate Langium project for the V2 of the DSL named
dialogue-dsl-v2, withDialogue DSL V2as language name and.dialogv2as file extension. -
Using the implementation of the abstract syntax of the V1 of the Dialogue DSL as a starting point, implement the abstract syntax of the V2.
2.2.1. Testing the abstract syntax by manually constructing ASTs
-
Create a file
packages/language/src/ast-test.ts, and write a program that creates an AST for the very first V2 dialogue tree shown in the specifications. -
Open a JavaScript Debug Terminal and using a breakpoint and the debugger check that your constructer AST is correct.