diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-14 02:52:07 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-14 02:52:07 +0000 |
| commit | d5851e995363e6f637a5f35cafe3ddaf8934705a (patch) | |
| tree | d3d2b1b5474ca3c33e3025420152f7384572e977 /plugin | |
| parent | 0e83581ed907aee1f6e59524c7d28b6f9c016f8e (diff) | |
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 <noreply@anthropic.com>
Diffstat (limited to 'plugin')
| -rw-r--r-- | plugin/ThirdPartyNotices.md | 5 | ||||
| -rw-r--r-- | plugin/examples/highlighting.cps | 6 | ||||
| -rw-r--r-- | plugin/syntaxes/cie-pseudocode.tmLanguage.json | 12 | ||||
| -rw-r--r-- | plugin/test/highlighting.test.js | 16 |
4 files changed, 38 insertions, 1 deletions
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 @@ -9,6 +9,18 @@ "include": "#strings" }, { + "match": "(?<!\\w)(?:TRY|ENDTRY)(?!\\w)", + "name": "keyword.control.try.cpp" + }, + { + "match": "(?<!\\w)CATCH(?!\\w)", + "name": "keyword.control.catch.cpp" + }, + { + "match": "(?<!\\w)THROW(?!\\w)", + "name": "keyword.control.throw.cpp" + }, + { "match": "(?<!\\w)(?:IF|THEN|ELSE|ENDIF|WHILE|DO|ENDWHILE|REPEAT|UNTIL|FOR|TO|STEP|NEXT|RETURN|CALL)(?!\\w)", "name": "keyword.control.cie-pseudocode" }, diff --git a/plugin/test/highlighting.test.js b/plugin/test/highlighting.test.js index 24751bf..0f677a3 100644 --- a/plugin/test/highlighting.test.js +++ b/plugin/test/highlighting.test.js @@ -53,6 +53,22 @@ test('both assignment characters share the C++ assignment scope', () => { 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.'))); |
