eclipse-langium / langium

Next-gen language engineering / DSL framework
https://langium.org/
MIT License
711 stars 65 forks source link

The strict mode for types inference #385

Open pluralia opened 2 years ago

pluralia commented 2 years ago

In Langium 0.2.0 types are inferred from rules names implicitly. For example, the following 2 examples will infer a type MyRule with the attribute name.

MyRule:
    name=ID;
MyRule returns MyRule:
    name=ID;

When we add types, type inference like described above will still be allowed by default.

This feature issue proposes to add the strict mode, when implicit type inference is forbidden. So, the way to specify a type of MyRule in the strict mode is:

type MyRule = {
    name: string
}

MyRule returns MyRule:
    name=ID;
pluralia commented 2 years ago

We can generate "a type system template" automatically in the strict mode. So, we just infer types like in the "default" mode and put them in separate .langium file. As the result:

  1. The strict mode works out of box
  2. A user develops the type system by adding and modifying types instead of creating everything from zero

@danieldietrich proposed to add that functionality to the CLI.

spoenemann commented 2 years ago

This will be considerably easier to implement with #438 and #440.