-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add @mermaid-js/parser
separate package
#4450
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
@Yokozuna59 I've made parse in Diagram async and added pie back into mermaid. I'd also avoid using |
Also, I think we should move the code from mermaid-lint into |
Thanks! I'll try figuring out how to resolve this. I haven't seen any based langium to be used as parser without LSP. So I'm sure if I'm doing the best approach yet.
It's appear it's not, I tried without and it throws exceptions.
Will do asap. |
Should it be |
@Yokozuna59 FYI, in your case, you don't need to perform the workspace initialization, making it unnecessary to make the whole function createParserServices() {
const services = createMermaidServices(EmptyFileSystem).Mermaid;
const parser = services.parser.LangiumParser;
const parse = (input: string) => {
return parser.parse<PieChart>(input);
};
return { services, parse };
} If you turn Langium into nothing but a parser, most things in the framework become very much obsolete. However, since the service initialization needs to bootstrap the grammar from a json format, internal dependencies from Langium such as It really depends on how much you guys are interested in having full LSP or advanced diagnostics reporting for the language, but it seems to me like using Langium is a bit of overkill for the parsing aspect of mermaid. It basically turns Langium into a glorified EBNF to Chevrotain code transformer, with a lot of unnecessary overhead. As much as I'd love to see it used in here - we are avid users of mermaid ourselves, much of our documentation is rendered with it - I think a much slimmer solution using Chevrotain directly would benefit this effort greatly. Just my 2 cents. |
@msujew I did a POC with Chevrotain few months back, but discovered Langium when using Zenstack. Eventhough I loved writing the grammar in TS for Chevrotain, I feel the langium syntax is a less disruptive and easier to read one.
There's 2 aspects we need to handle.
We can't maintain both jison and langium grammars as they're guaranteed to diverge, and jison is a source of some of our problems. So, is there any way we can have both from the same grammar file? @Yokozuna59 |
@msujew Thank you so much!
I guess one of the reasons for making @sidharthv96 suggest Langium is because it supports LSP. It can be used (and mostly will be used if it is stable enough) in So currently, it might be better to support the grammar of the current diagrams without affecting other parts, then support LSP with other services for enhancement. If we put all the effort into one diagram (supporting validation, format, completion, etc.), it would take forever instead of full migration, then support other features. |
@sidharthv96 I'm currently having some issues for adding the files from the original repo, the I have updated |
We shouldn't go back to node. #4213
Yes, our plan should be to introduce langium in the easiest and least disruptive way, and then build the cool features on top afterwards. |
That's my main gripe with Chevrotain as well: Grammars become really difficult to read/maintain once they reach a certain size and complexity, especially with embedded actions in the mix.
Ok, with that in mind, I can see why you would want to use Langium. Editor support for web/vscode/cli/linters is the core use case we've been going for after all. And yes, I agree, having two sources of truth in regards to the grammar will always lead to problems. I'll think about the idea of splitting of some of the Langium features into separate packages, so that features such as the grammar-to-chevrotain transformer can be consumed independently of the rest of the framework. The main issue here is that everything in Langium is bootstrapped, i.e. our own grammar language is written in the grammar language. This has some implications on what we can extract from the framework. Anyway, glad to hear you're still trying to go forward with Langium! I'm always available if you want some input from my side or have any other questions :) |
I suppose if it's a valid scenario, we could add a flag to the langium generator to add
@Yokozuna59 Installing |
This comment was marked as resolved.
This comment was marked as resolved.
@sidharthv96 I have pushed files from |
mermaid-parser
for pie chartmermaid-parser
separate package
Okay, I'll give it a try.
Is it possible to stub more than that? If we could stub the language server related stuff then it should render diagrams in browsers. |
I guess you could stub any dependency required. As long as the stubbed dependencies are not used in runtime, it shouldn't be a problem. You could simply stub with an empty object most probably. |
Then should we try stubbing instead of esbuild? I guess stubbing would resolve two issues at the same time, whereas esbuild may resolve one. |
Finally! After using esbuild from #4109 |
Hi there, @msujew. Thanks for your consistent support while helping us work on the new parser. We currently plan to support two diagrams within that parser, |
@Yokozuna59 I think the method suggested is the same that we are already doing. Testing the diagram text with a regex and using the corresponding object. The only difference is that, in our case (currently), the testing will occur inside the mermaid part, and the parser will be called with the detected type and the text to parse. |
@msujew I tried using the
The Should I push those changes into a separate repo? |
@Yokozuna59 Please do. Having a small example repo would be great :) |
@msujew Sure, here it is https://github.com/Yokozuna59/mermaid-service-regitry-example. To build:
To serve:
|
@Yokozuna59 There were a few issues in how you create the shared services, mainly, you're not allowed to override any property; I believe the underlying proxy doesn't even care that you "overwrote" a property. It will just ignore the assignment. Also, I'm not sure how well you can reuse a service container that already has another shared container. I think the I additionally noticed an issue in my own advice: Since the documents factory requires the services (and vice versa), we need a quick way to identify the document type before going to the service registry. I've made a working version here. |
@msujew I see, then we'll need to use
So it would behave similar to
Thanks! It's kind of weird; some parts of the grammar aren't supported; in this case, it's And it's stopped suggesting according to context; here it should suggest |
Yeah, the completion for whitespace/newline sensitive languages can sometimes be very weird. We're looking into improving that on the framework level.
You're using an invalid monarch grammar (i.e.
Right, exactly :)
Isn't the keyword |
Awesome! But I'm not sure if the problem is because of whitespace/newline sensitive languages or because of
So that's why highlighting isn't working. I'll try figuring out how to resolve it later on. But I removed all unnecessary rules but it keeps throwing and syntax highlighting isn't working.
Oh, sorry :) |
This PR is great! Do you have any plans to merge? |
@EchoZhaoH No, we don’t plan to merge it.
The new package has already been merged into the In case you’re wondering why this PR is still open, it's because we haven't created PRs for each existing parser yet.
|
i see, thx @Yokozuna59 |
📑 Summary
Add
@mermaid-js/parser
separate package.langium
instead ofjison
#4401related issues:
📏 Design Decisions
Common:
Diagrams:
📋 Tasks
Make sure you
🔖 targeteddevelop
branch