fix(md-lex): ignore lang tag after opening code block#26
Open
ardnew wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug in the markdown lexer where language tags following opening code fence backticks were incorrectly included as part of the grammar definition, causing parse errors. The fix ensures that everything on the same line after the opening ``` is ignored (replaced with spaces) until the first newline character.
Key Changes:
- Added logic to skip language tags after opening code block fences in markdown files
- The fix allows markdown files to use standard fenced code blocks with language identifiers (e.g.,
```gogll)
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lexer/lexer.go | Added logic in loadMd function to skip content after opening backticks until newline, preventing language tags from being parsed as grammar |
| gen/golang/lexer/lexer.go | Applied identical fix to the generated lexer template, ensuring consistency across generated code |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Author
|
Resolved all review comments with test cases implemented in 5bce663 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When parsing rules from Markdown files, the language tag following the opening fence should not be included as part of the grammar definition (resulting in a syntax error). More on fenced code blocks.
For example, the
"gogll"at the top:Previously, this example would fail with an error like:
$ gogll -v grammar.md Parse Errors: Parse Error: GoGLL : ∙Package Rules I[0]=tokid (156,161) gogll at line 7 col 4 Expected one of: [package]With this PR, everything on the same line following the opening backticks is ignored (up until the first
\n). This means whitespace can be part of a language tag — which is apparently allowed.