Skip to content

Conversation

@modulovalue
Copy link

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.
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.

1 participant