Skip to content

feat(pampa): better diagnostic for line breaks in inline link destinations#207

Merged
cscheid merged 1 commit into
quarto-dev:mainfrom
rundel:bugfix/link-dest-linebreak-diag
May 15, 2026
Merged

feat(pampa): better diagnostic for line breaks in inline link destinations#207
cscheid merged 1 commit into
quarto-dev:mainfrom
rundel:bugfix/link-dest-linebreak-diag

Conversation

@rundel
Copy link
Copy Markdown
Contributor

@rundel rundel commented May 15, 2026

When an inline link destination contains a hard line break (e.g. [text](https://\nhost/path)), pampa rejected the input with a generic "unexpected character or token here" message. CommonMark forbids line breaks in inline link destinations, so the rejection is correct, but the message is unhelpful.

This adds a Q-2-37 corpus entry covering the (LR state, lookahead) pairs the parser hits when a newline appears inside a link destination (state 2619 with both shortcode_name and _close_block lookaheads). Pampa now emits a specific message naming the cause and a single hint.

Output:

  Error: [Q-2-37] Line break in link destination
     ╭─[ file.qmd:2:1 ]
     │
   2 │ allisonhorst.github.io/palmerpenguins/) dataset.
     │ ──────┬─────
     │       ╰─────── An inline link destination cannot contain a line break.
  ───╯
  ℹ Remove the line break inside the link's `(...)` destination and keep the URL on a single line.

A new regression test (tests/test_link_destination_linebreak.rs) covers the bug-report fixture plus three minimal variants (newline after the scheme, mid-destination, before the closing )). The existing test_error_corpus_* tests automatically exercise the three generated case files.

The error location seems not ideal but I was not able to fix that without subjecting the codebase to much more significant changes than seemed warranted so I will leave that up to you to address.

…tinations

When an inline link destination contains a hard line break
(e.g. `[text](https://\nhost/path)`), pampa rejected the input with a
generic "unexpected character or token here" message. CommonMark forbids
line breaks in inline link destinations, so the rejection is correct,
but the message was unhelpful.

This adds a Q-2-37 corpus entry covering the (LR state, lookahead) pairs
the parser hits when a newline appears inside a link destination
(state 2619 with both `shortcode_name` and `_close_block` lookaheads).
Pampa now emits a specific message naming the cause and a single hint.

Output:

  Error: [Q-2-37] Line break in link destination
     ╭─[ file.qmd:2:1 ]
     │
   2 │ allisonhorst.github.io/palmerpenguins/) dataset.
     │ ──────┬─────
     │       ╰─────── An inline link destination cannot contain a line break.
  ───╯
  ℹ Remove the line break inside the link's `(...)` destination and keep the URL on a single line.

A new regression test (`tests/test_link_destination_linebreak.rs`) covers
the bug-report fixture plus three minimal variants (newline after the
scheme, mid-destination, before the closing `)`). The existing
`test_error_corpus_*` tests automatically exercise the three generated
case files.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@rundel
Copy link
Copy Markdown
Contributor Author

rundel commented May 15, 2026

Also TIL about the Jeffery TOPLAS-2003 technique - super cool

@cscheid
Copy link
Copy Markdown
Member

cscheid commented May 15, 2026

Also TIL about the Jeffery TOPLAS-2003 technique - super cool

Yes, it truly is! I only know about it because of a PL prof friend of mine. We're currently running into the limits of the technique for error messages here because parsing Markdown is, well, hell. But it's super cool, super simple, and wild that we could make it work inside tree-sitter.

@cscheid cscheid merged commit 5312ba3 into quarto-dev:main May 15, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants