Skip to content

Conversation

@modulovalue
Copy link
Contributor

Summary

Dart supports multi-line raw strings using triple quotes:

  • r'''...'''
  • r"""..."""

The existing rules only handled single-quoted raw strings (r'...' and r"..."), causing triple-quoted variants to be incorrectly tokenized.

The problem

When Rouge encounters r'''...''', the existing rule r'[^']*' matches r'' as an empty raw string, leaving '...' to be parsed incorrectly as a regular string.

The fix

Add rules for triple-quoted raw strings before the single-quoted rules. Order matters because Rouge matches the first matching rule, and we need to match the longer triple-quote pattern before the shorter one.

rule %r/r""".*?"""/m, Str::Other
rule %r/r'''.*?'''/m, Str::Other
rule %r/r"[^"]*"/, Str::Other
rule %r/r'[^']*'/, Str::Other

Test case

var pattern = r'''[<>"']''';  // Was broken, now works

Dart supports multi-line raw strings using triple quotes:
- r'''...'''
- r"""..."""

The existing rules only handled single-quoted raw strings,
causing triple-quoted variants to be incorrectly tokenized.

The new rules must come before the single-quoted rules because
Rouge matches the first matching rule, and we need to match
the longer triple-quote pattern before the shorter one.
@modulovalue
Copy link
Contributor Author

@tancnle are you the right person to ping? Could you take a look?

@tancnle
Copy link
Collaborator

tancnle commented Jan 9, 2026

Thanks, @modulovalue. LGTM 🚀

@tancnle tancnle added this pull request to the merge queue Jan 9, 2026
Merged via the queue into rouge-ruby:master with commit 7fb26a2 Jan 9, 2026
10 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