eclipse-langium / langium

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

Regenerating grammar doesn't seem to work #629

Closed RobertWalterU3d closed 2 years ago

RobertWalterU3d commented 2 years ago

I tried Langium today for the first time. I followed the "Getting Started" guide and was able to debug the default "Hello World" example. Next, I changed the grammar to this:

grammar LangiumTest

entry Model:
    'Keyword' name=ID; 

hidden terminal WS: /\s+/;
terminal ID: /[_a-zA-Z][\w_]*/;
terminal INT returns number: /[0-9]+/;
terminal STRING: /"[^"]*"|'[^']*'/;

hidden terminal ML_COMMENT: /\/\*[\s\S]*?\*\//;
hidden terminal SL_COMMENT: /\/\/[^\n\r]*/;

and ran npm run langium:generate successfully. However, when I start another Code instance now, I'm getting this error:

image

While the syntax (highlighting) has been updated successfully, the parser seems to have issues with this grammar. Any ideas why this is the case?

Langium version: 0.4.0 Package name:

Steps To Reproduce

  1. Follow the getting started guide
  2. Change the grammar to above example and spawn a new Code instance
msujew commented 2 years ago

Hey @RobertWalterU3d,

npm run langium:generate only perform the Langium code generation (in TypeScript). These files then need to be compiled to JavaScript in order to run. Did you run npm run build or npm run watch afterwards?

RobertWalterU3d commented 2 years ago

Hi Mark, I did not run those, I wasn't aware of that necessary additional step, thanks. Trying to run those gives me some errors in src/cli/generator.ts and src/language-server/nano-validator.ts. I assume these files are defaults that have been generated as part of running yo langium and they depend on stuff that is generated from the original grammar (which I changed).

I think I can fix those easily by removing these generator/validator examples, thanks for your help.

My recommendation would be to consider adding a sentence or two to the end of the "getting started" guide that playing around with the grammar, as suggested there, also requires to run the build command and that those files depend on the grammar.