Questions about indentation-aware parsing for YAML #1653
Replies: 3 comments 32 replies
-
cc @aabounegm Since you've worked quite a bit in this area, can you help? :) |
Beta Was this translation helpful? Give feedback.
-
Hi @martin-fleck-at, let me try to answer the questions one by one:
Hope this helps, let me know if you have any follow-up questions! |
Beta Was this translation helpful? Give feedback.
-
@msujew About the interface Person extends AstNode {
$type: 'Person';
name: string;
} then, let's say in my hover provider, I have: if (isPerson(node)) {
const range = ?? // How can I extract the range of just the `name` property, not the whole node?
return { contents: `A human named ${node.name}`, range };
} I would like the hover range to be only on the name, how can I get this information easily? It would be great if there was an associated |
Beta Was this translation helpful? Give feedback.
-
Hi everyone,
First, thank you for the fantastic work you're doing! I have experience using Xtext in multiple projects and have recently started applying Langium, and I'm really impressed with its architecture and codebase. I really appreciate it.
In one of those projects, CrossModel, we use Langium as the foundation for a model management server handling YAML-based models. For this, we developed a basic indentation-based YAML lexer that ignores list item markers (
-
), treating them as part of the whitespace for indentation.I was happy to see the latest master branch includes an indentation-aware lexer that's more in line with Langium’s architecture and offers customization options. I attempted to apply it to our grammar using the following custom class to handle the indentation regex while ignoring the '- ' character:
However, I encountered an error: "unexpected character: ->\n<- at offset: 7, skipped 1 characters." for example for this file:
This error breaks syntax highlighting. Interestingly, when I test it with a simplified version of the grammar in indentation-aware.test.ts, the error does not appear.
Given this, I have several questions:
Is this approach the right way to customize the lexer in this scenario, or is there a simpler method? If customization is needed, I’d be happy to propose a PR to make this easier.
Why might syntax highlighting be broken? Could it be related to the parsing error?
Any insights on why the "unexpected character" error occurs or suggestions for debugging this effectively? Are there any visualization tools available that could help here?
Is there a nightly build of Langium? I didn't find one on npm under the next tag, so I manually copied the indentation-aware.ts file. Could missing other updates cause these issues?
It seems that
whitespaceTokenName
overrides the token with a token defined bywhitespaceRegExp
. Does this conflict with existing WS rules?Does Langium discourage PRs for typos? I noticed a typo in
ignoreIndentationDelimeters
(should beignoreIndentationDelimiters
). I'm aware of backward compatibility concerns once the new release is out with the type, so I'd like to contribute a fix but wasn't sure as some projects do not like that.Any help or insight (even on a single question) would be greatly appreciated! If YAML is an interesting use case for Langium, we're also open to contributing this work via a PR.
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions