Skip to content

fix: make TextMate grammar regexes compatible with Joni/TM4E#113

Open
jgsuess wants to merge 1 commit intoFHIR:masterfrom
jgsuess:fix/joni-compatible-regexes
Open

fix: make TextMate grammar regexes compatible with Joni/TM4E#113
jgsuess wants to merge 1 commit intoFHIR:masterfrom
jgsuess:fix/joni-compatible-regexes

Conversation

@jgsuess
Copy link
Copy Markdown

@jgsuess jgsuess commented Mar 19, 2026

Summary

The FSH TextMate grammar uses several regex patterns that are incompatible with the Joni regex engine (Java port of Oniguruma) used by Eclipse TM4E. These patterns work in VS Code's Oniguruma but fail silently in Joni, causing syntax highlighting to break entirely or miss tokens at end-of-line.

Changes (5 patterns, 5 lines changed)

  1. keywords — removed nested variable-length lookbehind (?<=\bfrom\s*); system is now a plain reserved keyword
  2. keywords(?=\s)\b(?=\s|$) so tokens like MS at end-of-line are matched
  3. insert brackets — moved \s* outside lookbehind (variable-length content inside (?<=...) not supported)
  4. booleans(?=\s)\b(?=\s|$) for end-of-line matching
  5. numbers (decimals)(?=[\s,])\b(?=[\s,]|$) for end-of-line matching
  6. numbers (cardinality)\b(?=\s|$) because \b fails after non-word char * (e.g. 1..*)

Compatibility

All patterns now use only fixed-length lookbehinds — the common subset supported by:

  • Oniguruma (VS Code) — superset, no behavior change
  • Joni (Eclipse TM4E) — now works correctly
  • JetBrains regex engine — now works correctly

Testing

Tested in Eclipse 2026-03 with TM4E 0.17.2. Before: no syntax highlighting (regex parse errors on every line). After: full keyword, string, comment, number, and cardinality highlighting.

No change in VS Code behavior — Oniguruma is a superset of the patterns used here.

The FSH TextMate grammar uses several regex patterns that are
incompatible with the Joni regex engine (Java port of Oniguruma) used
by Eclipse TM4E. These patterns work in VS Code's Oniguruma but fail
silently in Joni, causing syntax highlighting to break.

Fixes:
- Remove nested variable-length lookbehind (?<=\bfrom\s*) in keywords
  pattern — `system` is now matched as a plain reserved keyword
- Replace (?=\s)\b with (?=\s|$) in keywords, booleans patterns so
  tokens at end-of-line are matched (e.g. `* name 1..* MS`)
- Replace (?=[\s,])\b with (?=[\s,]|$) in numbers pattern for same
  reason
- Replace \b with (?=\s|$) in cardinality pattern — \b fails after
  non-word char `*` (e.g. `1..*` was not highlighted)
- Move \s* outside lookbehind in insert RuleSet bracket pattern —
  variable-length content inside (?<=...) is not supported

All patterns now use only fixed-length lookbehinds, which is the
common subset supported by Oniguruma (VS Code), Joni (Eclipse TM4E),
and JetBrains regex engines. No change in VS Code behavior.
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