Replies: 2 comments 4 replies
-
We do have an API for generating text, see here. It's optimized for generating formatted code. Otherwise, most things related to code generation depend so much on the actual semantics of the language, that there's very little in common between generators. Most generators in our experience are very similar to tree-walking interpreters. I.e. you walk through your AST, and transform it into another representation. This works well for source to target transformations where the paradigm doesn't change, but can become more complex in case it does. |
Beta Was this translation helpful? Give feedback.
-
We recently published a blog post about this, and two more posts are going to follow soon: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Are there any recommended or existing patterns to use for code generators? Namely, any classes to extend from or APIs to use? Or is this area you're-on-your-own?
The code that I'm wondering about is, for example, the code that a Langium user would continue writing to expand the CLI generator (generate command) bootstrapped from the hello-world template.
I believe this is probably where things get the most custom, depending on the user's language, but I want to know if there is at least a list of things recommended to keep in mind so that we are on Langium's best practices path.
So far, this is what ByteScript's generator is looking like (very naive at the moment):
https://github.com/bytescript/bytescript/blob/wasm-output-foundation-construction/src/cli/generator.ts
(Permalink at time of writing)
The command
npm install && npm test
while on this (temporary)wasm-output-foundation-construction
branch will compile thepoc1.ts
file to apoc1.wasm
WebAssembly file, and run it in Node.js and Chrome headless.Beta Was this translation helpful? Give feedback.
All reactions