Skip to content

[Langium Grammar] How best to implement section headings? #1592

Closed Answered by msujew
ym-han asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @ym-han,

sorry for the late response. You can use a parser rule like this to identify the end of section headings:

Section: 'SECTION' content=TEXT (EOL+ | EOF); // EOF is a builtin keyword that matches the end of a file

terminal EOL: /\r?\n/;
terminal TEXT: [^\n\r]+;

A general word of warning: Markdown like languages are very difficult to parse using LL based parsers (like Langium). Parsers for those languages are usually handwritten due to very specific behavior wrt to stuff like line endings, ambiguity detection and error recovery. It can work, but it's often a lot more effort than necessary.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ym-han
Comment options

Answer selected by ym-han
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants