From d5851e995363e6f637a5f35cafe3ddaf8934705a Mon Sep 17 00:00:00 2001 From: _ov4 Date: Wed, 14 Oct 2026 02:52:07 +0000 Subject: feat(plugin): highlight exception keywords with C++ scopes Reuse C++ try, catch and throw scopes for exception keywords, with ENDTRY sharing the TRY scope. Add an example and verify keyword boundaries, case sensitivity, comments and strings with TextMate tokenization. Co-Authored-By: Claude Fable 5.1 --- plugin/ThirdPartyNotices.md | 5 ++++- plugin/examples/highlighting.cps | 6 ++++++ plugin/syntaxes/cie-pseudocode.tmLanguage.json | 12 ++++++++++++ plugin/test/highlighting.test.js | 16 ++++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) (limited to 'plugin') diff --git a/plugin/ThirdPartyNotices.md b/plugin/ThirdPartyNotices.md index d21d67a..72c3190 100644 --- a/plugin/ThirdPartyNotices.md +++ b/plugin/ThirdPartyNotices.md @@ -1,7 +1,10 @@ # Third-party notices Language configuration and comment/string grammar structures are adapted from -Microsoft VS Code’s built-in C++ extension: +Microsoft VS Code’s built-in C++ extension. Exception keywords reuse its +`keyword.control.try.cpp`, `keyword.control.catch.cpp` and +`keyword.control.throw.cpp` scopes; ENDTRY uses the TRY scope. + https://github.com/microsoft/vscode/tree/main/extensions/cpp MIT License diff --git a/plugin/examples/highlighting.cps b/plugin/examples/highlighting.cps index 9925bf3..7b30bb7 100644 --- a/plugin/examples/highlighting.cps +++ b/plugin/examples/highlighting.cps @@ -39,3 +39,9 @@ ENDPROCEDURE OPENFILE "example.txt" FOR WRITE WRITEFILE "example.txt", Text CLOSEFILE "example.txt" + +TRY + THROW +CATCH + OUTPUT "Caught an exception" +ENDTRY diff --git a/plugin/syntaxes/cie-pseudocode.tmLanguage.json b/plugin/syntaxes/cie-pseudocode.tmLanguage.json index cf1957f..fe3582c 100644 --- a/plugin/syntaxes/cie-pseudocode.tmLanguage.json +++ b/plugin/syntaxes/cie-pseudocode.tmLanguage.json @@ -8,6 +8,18 @@ { "include": "#strings" }, + { + "match": "(? { assert.ok(!scopesAt('X - 1', '-').includes('keyword.operator.assignment.cpp')); }); +test('exception keywords reuse C++ scopes and ignore non-keyword occurrences', () => { + for (const [word, scope] of [ + ['TRY', 'keyword.control.try.cpp'], + ['CATCH', 'keyword.control.catch.cpp'], + ['THROW', 'keyword.control.throw.cpp'], + ['ENDTRY', 'keyword.control.try.cpp'] + ]) { + assert.ok(scopesAt(word, word).includes(scope)); + assert.ok(scopesAt(`// ${word}`, word).some(s => s.startsWith('comment.'))); + assert.ok(scopesAt(`OUTPUT "${word}"`, word).some(s => s.startsWith('string.'))); + for (const text of [word.toLowerCase(), `${word}Value`, `My${word}`, `${word}_1`]) { + assert.ok(!scopesAt(text, text).some(s => s.startsWith('keyword.')), text); + } + } +}); + test('comments, strings, lowercase and keyword prefixes cannot become keywords', () => { assert.ok(scopesAt('// IF [(', 'IF').some(s => s.startsWith('comment.'))); assert.ok(scopesAt('OUTPUT "IF // ["', 'IF').some(s => s.startsWith('string.'))); -- cgit v1.3.1-4-g156e