Skip to content

fix(grammar): use fixed-length look-behind in FunC function definitions - #344

Merged
i582 merged 1 commit into
ton-blockchain:mainfrom
0xnirapod:fix-func-tmlanguage-lookbehind
Jun 22, 2026
Merged

fix(grammar): use fixed-length look-behind in FunC function definitions#344
i582 merged 1 commit into
ton-blockchain:mainfrom
0xnirapod:fix-func-tmlanguage-lookbehind

Conversation

@0xnirapod

Copy link
Copy Markdown
Contributor

What

The FunC TextMate grammar's function-definition rule uses a variable-length look-behind:

(?<=^|[;{]\s*)

Why

Oniguruma (used by VS Code) accepts this, so editor highlighting is unaffected. But regex engines that require fixed-length look-behind reject it. GitHub Linguist's grammar compiler, for instance, fails with:

lookbehind assertion is not fixed length

That blocks func.tmLanguage.json (and with it the rest of the ton-language-server grammars, which compile as a set) from being reused for syntax highlighting on GitHub.

Fix

Split the assertion into two fixed-length look-behinds and move \s* into the match:

(?:(?<=^)|(?<=[;{])\s*)

Behavior is unchanged: a function name is matched at the start of a line, or after ; or { with optional whitespace. Verified locally by compiling the grammars with Linguist's grammar compiler. All five now compile cleanly.

The function-definition rule used a variable-length look-behind,
`(?<=^|[;{]\s*)`. Oniguruma accepts it, so VS Code highlighting is
unaffected, but engines that require fixed-length look-behind reject it
(for example the grammar compiler GitHub Linguist uses), which prevents
the grammar from being reused there.

Split the assertion into two fixed-length look-behinds, `(?<=^)` and
`(?<=[;{])`, and move `\s*` into the match. Behavior is unchanged: a
function name is still matched at the start of a line, or after `;` or `{`
with optional whitespace.
@0xnirapod
0xnirapod requested a review from i582 as a code owner June 21, 2026 11:14
@i582

i582 commented Jun 22, 2026

Copy link
Copy Markdown
Member

Hey! Sounds great, thank you!

@0xnirapod

Copy link
Copy Markdown
Contributor Author

Thanks! Glad it helps.

@i582
i582 merged commit f28fe36 into ton-blockchain:main Jun 22, 2026
4 of 5 checks passed
0xnirapod added a commit to 0xnirapod/linguist that referenced this pull request Jun 22, 2026
Switch the vendored grammar from the archived tolk-vscode to TON's maintained ton-language-server, which tracks current Tolk syntax. It became usable in Linguist once the FunC grammar's variable-length look-behind was made fixed-length upstream (ton-blockchain/ton-language-server#344).
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