├── .gitignore ├── TODO.md ├── images ├── demo.gif └── syntax.png ├── tslint.json ├── .vscodeignore ├── tsconfig.json ├── .vscode ├── tasks.json └── launch.json ├── BUILD.md ├── LICENSE.txt ├── scripts └── build.js ├── grammars ├── shellscript.json ├── lua.json ├── go.json ├── d.json ├── ruby.json ├── python.json ├── c.json ├── ocaml.json ├── javascript.json ├── typescript.json ├── cpp.json ├── typescriptreact.json ├── php.json └── rust.json ├── CHANGELOG.md ├── README.md ├── package.json └── src └── extension.ts /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | parsers 3 | out 4 | -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | # ToDo 2 | * Instructions on how to add a new language 3 | * More languages 4 | -------------------------------------------------------------------------------- /images/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EvgeniyPeshkov/syntax-highlighter/HEAD/images/demo.gif -------------------------------------------------------------------------------- /images/syntax.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EvgeniyPeshkov/syntax-highlighter/HEAD/images/syntax.png -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "indent": [true, "tabs"], 4 | "semicolon": [true, "always"] 5 | } 6 | } -------------------------------------------------------------------------------- /.vscodeignore: -------------------------------------------------------------------------------- 1 | **/*.ts 2 | **/*.map 3 | .vscode/** 4 | .gitignore 5 | tslint.json 6 | tsconfig.json 7 | scripts/** 8 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": ".", 4 | "paths": { "*": ["types/*"] }, 5 | "module": "commonjs", 6 | "target": "es6", 7 | "outDir": "out", 8 | "lib": ["es6"], 9 | "sourceMap": true, 10 | "rootDir": "src" 11 | }, 12 | "exclude": ["node_modules", ".vscode-test"] 13 | } 14 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "type": "npm", 6 | "script": "watch", 7 | "problemMatcher": "$tsc-watch", 8 | "isBackground": true, 9 | "presentation": { 10 | "reveal": "never" 11 | }, 12 | "group": { 13 | "kind": "build", 14 | "isDefault": true 15 | } 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "Extension", 6 | "type": "extensionHost", 7 | "request": "launch", 8 | "runtimeExecutable": "${execPath}", 9 | "args": ["--extensionDevelopmentPath=${workspaceFolder}" ], 10 | "stopOnEntry": false, 11 | "sourceMaps": true, 12 | "outFiles": [ "${workspaceRoot}/out/**/*.js" ], 13 | "preLaunchTask": "npm: watch" 14 | }, 15 | { 16 | "name": "Build", 17 | "type": "node", 18 | "request": "launch", 19 | "program": "${workspaceFolder}/scripts/build.js" 20 | } 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /BUILD.md: -------------------------------------------------------------------------------- 1 | # Build instructions 2 | 3 | In general, {Syntax Highlighter} extension is built the same way as 4 | [any other VSCode extension](https://code.visualstudio.com/api/extension-guides/overview). 5 | {Syntax Highlighter} utilizes [WebAssembly bindings to the Tree-sitter parsing library]( 6 | https://github.com/tree-sitter/tree-sitter/tree/master/lib/binding_web). 7 | All language parsers are therefore [compiled to binary .wasm modules]( 8 | https://github.com/tree-sitter/tree-sitter/tree/master/lib/binding_web#generate-wasm-language-files). 9 | This is done by postinstall hook when you call `npm install` as usual. 10 | See [build.js](scripts/build.js) script for details. 11 | 12 | To build .wasm you'll need Emscripten SDK. Installation instructions can be found [here]( 13 | https://emscripten.org/docs/getting_started/downloads.html) or [here]( 14 | https://webassembly.org/getting-started/developers-guide/). 15 | Or you can use docker. *tree-sitter-cli* will try to deploy [trzeci/emscripten-slim]( 16 | https://hub.docker.com/r/trzeci/emscripten-slim/) image as fallback when `emcc` isn't found. 17 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Evgeniy Peshkov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /scripts/build.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const { exec } = require('child_process'); 4 | const fs = require('fs'); 5 | const path = require('path'); 6 | 7 | // Languages 8 | let langs = []; 9 | fs.readdirSync(__dirname + "/../grammars/").forEach(name => { 10 | langs.push(path.basename(name, ".json")); 11 | }); 12 | 13 | // Language-package map 14 | const langMap = { 15 | typescript: ["typescript", "typescript"], 16 | typescriptreact: ["typescript", "tsx"], 17 | ocaml: ["ocaml", "ocaml"], 18 | shellscript: ["bash"] 19 | } 20 | 21 | // Build wasm parsers for supported languages 22 | const parsersDir = __dirname + "/../parsers"; 23 | if (!fs.existsSync(parsersDir)) { 24 | fs.mkdirSync(parsersDir); 25 | } 26 | for (li of langs) { 27 | const lang = li; 28 | let module = "node_modules/tree-sitter-" + lang; 29 | let output = "tree-sitter-" + lang + ".wasm"; 30 | if (langMap[lang]) { 31 | module = path.join("node_modules/tree-sitter-" + 32 | langMap[lang][0], ...langMap[lang].slice(1)) 33 | output = "tree-sitter-" + langMap[lang][langMap[lang].length - 1] + ".wasm"; 34 | } 35 | 36 | console.log("Compiling " + lang + " parser"); 37 | exec("node_modules/.bin/tree-sitter build-wasm " + module, 38 | (err) => { 39 | if (err) 40 | console.log("Failed to build wasm for " + lang + ": " + err.message); 41 | else 42 | fs.rename(output, "parsers/" + lang + ".wasm", 43 | (err) => { 44 | if (err) 45 | console.log("Failed to copy built parser: " + err.message); 46 | else 47 | console.log("Successfully compiled " + lang + " parser"); 48 | }); 49 | }); 50 | } 51 | -------------------------------------------------------------------------------- /grammars/shellscript.json: -------------------------------------------------------------------------------- 1 | { 2 | "simpleTerms": { 3 | 4 | "special_variable_name": "variable", 5 | "variable_name": "variable", 6 | 7 | "file_descriptor": "number", 8 | "ansii_c_string": "string", 9 | "heredoc_body": "string", 10 | "heredoc_start": "string", 11 | "regex": "string", 12 | "comment": "comment", 13 | 14 | "\"if\"": "control", 15 | "\"fi\"": "control", 16 | "\"then\"": "control", 17 | "\"else\"": "control", 18 | "\"elif\"": "control", 19 | "\"for\"": "control", 20 | "\"do\"": "control", 21 | "\"done\"": "control", 22 | "\"case\"": "control", 23 | "\"esac\"": "control", 24 | "\"in\"": "control", 25 | "\"while\"": "control", 26 | "\"until\"": "control", 27 | "\"function\"": "control", 28 | "\"local\"": "control", 29 | "\"declare\"": "control", 30 | "\"export\"": "control", 31 | "\"readonly\"": "control", 32 | "\"typeset\"": "control", 33 | "\"unset\"": "control", 34 | "\"unsetenv\"": "control", 35 | 36 | "\"=\"": "operator", 37 | "\"&\"": "operator", 38 | "\"&&\"": "operator", 39 | "\"|\"": "operator", 40 | "\"||\"": "operator", 41 | "\"<\"": "operator", 42 | "\">\"": "operator", 43 | "\">>\"": "operator", 44 | "\"&>\"": "operator", 45 | "\"&>>\"": "operator", 46 | "\"<&\"": "operator", 47 | "\">&\"": "operator", 48 | "\"<<-\"": "operator", 49 | "\"<<<\"": "operator", 50 | "test_operator": "operator", 51 | 52 | "\"$\"": "punctuation", 53 | "\"${\"": "punctuation", 54 | "\"}\"": "punctuation", 55 | "\"$(\"": "punctuation", 56 | "\"(\"": "punctuation", 57 | "\")\"": "punctuation", 58 | "\"[\"": "punctuation", 59 | "\"]\"": "punctuation", 60 | "\"\"\"": "punctuation" 61 | }, 62 | 63 | "complexTerms": ["word", "raw_string", "string"], 64 | 65 | "complexScopes": { 66 | "word": "variable", 67 | 68 | "function_definition > word": "function", 69 | "command_name > word": "function", 70 | "command_name > string": "function", 71 | "command_name > raw_string": "function", 72 | 73 | "variable_assignment > word": "number" 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /grammars/lua.json: -------------------------------------------------------------------------------- 1 | { 2 | "simpleTerms": { 3 | 4 | "method": "function", 5 | 6 | "\"local\"": "modifier", 7 | "\"function\"": "modifier", 8 | 9 | "number": "number", 10 | "string": "string", 11 | "comment": "comment", 12 | 13 | "true": "constant", 14 | "false": "constant", 15 | "nil": "constant", 16 | "global_variable": "constant", 17 | 18 | "\"while\"": "control", 19 | "\"do\"": "control", 20 | "\"until\"": "control", 21 | "\"break\"": "control", 22 | "\"for\"": "control", 23 | "\"if\"": "control", 24 | "\"else\"": "control", 25 | "\"elseif\"": "control", 26 | "\"then\"": "control", 27 | "\"end\"": "control", 28 | "\"goto\"": "control", 29 | "\"repeat\"": "control", 30 | "\"return\"": "control", 31 | 32 | "self": "operator", 33 | "\"and\"": "operator", 34 | "\"or\"": "operator", 35 | "\"not\"": "operator", 36 | "\"in\"": "operator", 37 | "\"next\"": "operator", 38 | "\"spread\"": "operator", 39 | 40 | "\"+\"": "operator", 41 | "\"-\"": "operator", 42 | "\"*\"": "operator", 43 | "\"/\"": "operator", 44 | "\"%\"": "operator", 45 | "\"^\"": "operator", 46 | "\"#\"": "operator", 47 | "\"&\"": "operator", 48 | "\"~\"": "operator", 49 | "\"|\"": "operator", 50 | "\"//\"": "operator", 51 | "\"<<\"": "operator", 52 | "\">>\"": "operator", 53 | "\"==\"": "operator", 54 | "\"~=\"": "operator", 55 | "\"<=\"": "operator", 56 | "\">=\"": "operator", 57 | "\"<\"": "operator", 58 | "\">\"": "operator", 59 | "\"=\"": "operator", 60 | "\"::\"": "operator", 61 | "\":\"": "operator", 62 | "\".\"": "operator", 63 | "\"..\"": "operator", 64 | 65 | "\"{\"": "punctuation", 66 | "\"}\"": "punctuation", 67 | "\"[\"": "punctuation", 68 | "\"]\"": "punctuation", 69 | "\"(\"": "punctuation", 70 | "\")\"": "punctuation", 71 | "\";\"": "punctuation", 72 | "\",\"": "punctuation" 73 | }, 74 | 75 | "complexTerms": ["identifier", "property_identifier"], 76 | 77 | "complexScopes": { 78 | "identifier": "variable", 79 | "property_identifier": "variable", 80 | 81 | "function_call > identifier": "function", 82 | "function_call > property_identifier": "function", 83 | "function_name > identifier": "function", 84 | "function_name > property_identifier": "function", 85 | "local_function > identifier": "function" 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /grammars/go.json: -------------------------------------------------------------------------------- 1 | { 2 | "simpleTerms": { 3 | "type_identifier": "type", 4 | "package_identifier": "scope", 5 | 6 | "\"var\"": "modifier", 7 | "\"const\"": "modifier", 8 | 9 | "interpreted_string_literal": "string", 10 | "raw_string_literal": "string", 11 | "escape_sequence": "string", 12 | "rune_literal": "number", 13 | "int_literal": "number", 14 | "float_literal": "number", 15 | "imaginary_literal": "number", 16 | "comment": "comment", 17 | 18 | "nil": "constant", 19 | "false": "constant", 20 | "true": "constant", 21 | 22 | "\"if\"": "control", 23 | "\"for\"": "control", 24 | "\"else\"": "control", 25 | "\"case\"": "control", 26 | "\"break\"": "control", 27 | "\"switch\"": "control", 28 | "\"select\"": "control", 29 | "\"return\"": "control", 30 | "\"default\"": "control", 31 | "\"continue\"": "control", 32 | "\"goto\"": "control", 33 | "\"fallthrough\"": "control", 34 | "\"defer\"": "control", 35 | "\"range\"": "control", 36 | "\"go\"": "control", 37 | 38 | "\"type\"": "operator", 39 | "\"struct\"": "operator", 40 | "\"import\"": "operator", 41 | "\"package\"": "operator", 42 | "\"func\"": "operator", 43 | "\"interface\"": "operator", 44 | "\"map\"": "operator", 45 | "\"chan\"": "operator", 46 | 47 | "\"+\"": "operator", 48 | "\"-\"": "operator", 49 | "\"*\"": "operator", 50 | "\"/\"": "operator", 51 | "\"%\"": "operator", 52 | "\"++\"": "operator", 53 | "\"--\"": "operator", 54 | "\"==\"": "operator", 55 | "\"!=\"": "operator", 56 | "\">\"": "operator", 57 | "\"<\"": "operator", 58 | "\">=\"": "operator", 59 | "\"<=\"": "operator", 60 | "\"!\"": "operator", 61 | "\"|\"": "operator", 62 | "\"^\"": "operator", 63 | "\"<<\"": "operator", 64 | "\">>\"": "operator", 65 | "\"=\"": "operator", 66 | "\"+=\"": "operator", 67 | "\"-=\"": "operator", 68 | "\"*=\"": "operator", 69 | "\"/=\"": "operator", 70 | "\"%=\"": "operator", 71 | "\"<<=\"": "operator", 72 | "\">>=\"": "operator", 73 | "\"&=\"": "operator", 74 | "\"^=\"": "operator", 75 | "\"|=\"": "operator", 76 | "\":=\"": "operator", 77 | "\"&\"": "operator", 78 | "\"&&\"": "operator", 79 | "\"&^\"": "operator", 80 | "\"&^=\"": "operator", 81 | "\"||\"": "operator", 82 | "\"...\"": "operator", 83 | "\"<-\"": "operator", 84 | "\"[\"": "operator", 85 | "\"]\"": "operator", 86 | 87 | "\"(\"": "punctuation", 88 | "\")\"": "punctuation", 89 | "\"{\"": "punctuation", 90 | "\"}\"": "punctuation", 91 | "\",\"": "punctuation", 92 | "\";\"": "punctuation", 93 | "\".\"": "punctuation", 94 | "\":\"": "punctuation" 95 | }, 96 | 97 | "complexTerms": ["identifier", "field_identifier"], 98 | 99 | "complexScopes": { 100 | "identifier": "variable", 101 | "field_identifier": "variable", 102 | 103 | "call_expression > identifier": "function", 104 | "function_declaration > identifier": "function", 105 | "method_declaration > field_identifier": "function", 106 | "call_expression > selector_expression > field_identifier": "function", 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /grammars/d.json: -------------------------------------------------------------------------------- 1 | { 2 | "simpleTerms": { 3 | "type_identifier": "type", 4 | "primitive_type": "type", 5 | 6 | "statement_identifier": "variable", 7 | 8 | "\"const\"": "modifier", 9 | "\"static\"": "modifier", 10 | "\"auto\"": "modifier", 11 | "\"extern\"": "modifier", 12 | "\"shared\"": "modifier", 13 | "\"__gshared\"": "modifier", 14 | "function_specifier": "modifier", 15 | 16 | "number_literal": "number", 17 | "char_literal": "string", 18 | "string_literal": "string", 19 | "system_lib_string": "string", 20 | "escape_sequence": "string", 21 | "comment": "comment", 22 | 23 | "null": "constant", 24 | "true": "constant", 25 | "false": "constant", 26 | 27 | "\"if\"": "control", 28 | "\"else\"": "control", 29 | "\"do\"": "control", 30 | "\"for\"": "control", 31 | "\"while\"": "control", 32 | "\"break\"": "control", 33 | "\"continue\"": "control", 34 | "\"return\"": "control", 35 | "\"switch\"": "control", 36 | "\"case\"": "control", 37 | "\"default\"": "control", 38 | "\"goto\"": "control", 39 | "\"struct\"": "control", 40 | "\"class\"": "control", 41 | "\"interface\"": "control", 42 | "\"abstract\"": "control", 43 | "\"enum\"": "control", 44 | "\"union\"": "control", 45 | "\"cast\"": "control", 46 | "\"ref\"": "control", 47 | 48 | "\"sizeof\"": "operator", 49 | "\".\"": "operator", 50 | "\"*\"": "operator", 51 | "\"-\"": "operator", 52 | "\"+\"": "operator", 53 | "\"/\"": "operator", 54 | "\"%\"": "operator", 55 | "\"++\"": "operator", 56 | "\"--\"": "operator", 57 | "\"==\"": "operator", 58 | "\"!\"": "operator", 59 | "\"!=\"": "operator", 60 | "\"<\"": "operator", 61 | "\">\"": "operator", 62 | "\">=\"": "operator", 63 | "\"<=\"": "operator", 64 | "\"&&\"": "operator", 65 | "\"||\"": "operator", 66 | "\"&\"": "operator", 67 | "\"|\"": "operator", 68 | "\"^\"": "operator", 69 | "\"~\"": "operator", 70 | "\"<<\"": "operator", 71 | "\">>\"": "operator", 72 | "\"=\"": "operator", 73 | "\"+=\"": "operator", 74 | "\"-=\"": "operator", 75 | "\"*=\"": "operator", 76 | "\"/=\"": "operator", 77 | "\"%=\"": "operator", 78 | "\"<<=\"": "operator", 79 | "\">>=\"": "operator", 80 | "\"&=\"": "operator", 81 | "\"^=\"": "operator", 82 | "\"|=\"": "operator", 83 | "\"?\"": "operator", 84 | "\":\"": "operator", 85 | 86 | "\"version\"": "directive", 87 | "\"import\"": "directive", 88 | "\"package\"": "directive", 89 | "\"debug\"": "directive", 90 | "\"unittest\"": "directive", 91 | "preproc_directive": "directive", 92 | "preproc_arg": "directive", 93 | 94 | "\";\"": "punctuation", 95 | "\"[\"": "punctuation", 96 | "\"]\"": "punctuation", 97 | "\",\"": "punctuation", 98 | "\"{\"": "punctuation", 99 | "\"}\"": "punctuation", 100 | "\"(\"": "punctuation", 101 | "\")\"": "punctuation" 102 | }, 103 | 104 | "complexTerms": ["identifier", "field_identifier"], 105 | 106 | "complexScopes": { 107 | "identifier": "variable", 108 | "field_identifier": "variable", 109 | 110 | "call_expression > identifier" : "function", 111 | "call_expression > field_expression > field_identifier" : "function", 112 | "function_declarator > identifier" : "function" 113 | } 114 | 115 | } 116 | -------------------------------------------------------------------------------- /grammars/ruby.json: -------------------------------------------------------------------------------- 1 | { 2 | "simpleTerms": { 3 | "constant": "type", 4 | 5 | "class_variable": "variable", 6 | "instance_variable": "variable", 7 | 8 | "string": "string", 9 | "bare_string": "string", 10 | "subshell": "string", 11 | "heredoc_beginning": "string", 12 | "heredoc_body": "string", 13 | "regex": "string", 14 | "escape_sequence": "string", 15 | "symbol": "string", 16 | "bare_symbol": "string", 17 | "interpolation": "string", 18 | "float": "number", 19 | "integer": "number", 20 | "complex": "number", 21 | "rational": "number", 22 | "comment": "comment", 23 | 24 | "nil": "constant", 25 | "true": "constant", 26 | "false": "constant", 27 | 28 | "\"if\"": "control", 29 | "\"unless\"": "control", 30 | "\"def\"": "control", 31 | "\"do\"": "control", 32 | "\"end\"": "control", 33 | "\"else\"": "control", 34 | "\"elsif\"": "control", 35 | "\"class\"": "control", 36 | "\"module\"": "control", 37 | "\"alias\"": "control", 38 | "\"begin\"": "control", 39 | "\"rescue\"": "control", 40 | "\"ensure\"": "control", 41 | "\"return\"": "control", 42 | "\"yield\"": "control", 43 | "\"case\"": "control", 44 | "\"when\"": "control", 45 | "\"then\"": "control", 46 | "\"for\"": "control", 47 | "\"break\"": "control", 48 | "\"next\"": "control", 49 | "\"retry\"": "control", 50 | "\"while\"": "control", 51 | "\"in\"": "control", 52 | "\"until\"": "control", 53 | 54 | "self": "control", 55 | "super": "control", 56 | 57 | "\"and\"": "operator", 58 | "\"or\"": "operator", 59 | "\"not\"": "operator", 60 | "\"||\"": "operator", 61 | "\"&&\"": "operator", 62 | "\"!\"": "operator", 63 | "\"~\"": "operator", 64 | "\"<<\"": "operator", 65 | "\">>\"": "operator", 66 | "\"=\"": "operator", 67 | "\"==\"": "operator", 68 | "\"!=\"": "operator", 69 | "\"===\"": "operator", 70 | "\"<=>\"": "operator", 71 | "\"=~\"": "operator", 72 | "\"!~\"": "operator", 73 | "\"<\"": "operator", 74 | "\"<=\"": "operator", 75 | "\">\"": "operator", 76 | "\">=\"": "operator", 77 | "\"&\"": "operator", 78 | "\"|\"": "operator", 79 | "\"^\"": "operator", 80 | "\"+\"": "operator", 81 | "\"-\"": "operator", 82 | "\"/\"": "operator", 83 | "\"%\"": "operator", 84 | "\"*\"": "operator", 85 | "\"**\"": "operator", 86 | "\"+@\"": "operator", 87 | "\"-@\"": "operator", 88 | "\"..\"": "operator", 89 | "\"[]\"": "operator", 90 | "\"[]=\"": "operator", 91 | "\"defined?\"": "operator", 92 | 93 | "\",\"": "punctuation", 94 | "\"%w(\"": "punctuation", 95 | "\"%i(\"": "punctuation", 96 | "\"(\"": "punctuation", 97 | "\")\"": "punctuation", 98 | "\"{\"": "punctuation", 99 | "\"}\"": "punctuation", 100 | "\"#{\"": "punctuation" 101 | }, 102 | 103 | "complexTerms": ["identifier"], 104 | 105 | "complexScopes": { 106 | "identifier": "variable", 107 | "block_parameters > identifier": "variable", 108 | "keyword_parameter > identifier": "constant", 109 | 110 | "method > identifier": "function", 111 | "setter > identifier": "function", 112 | "call > identifier": "function", 113 | "method_call > identifier": "function", 114 | "singleton_method > identifier": "function", 115 | "method_parameters > identifier": "function" 116 | }, 117 | } 118 | -------------------------------------------------------------------------------- /grammars/python.json: -------------------------------------------------------------------------------- 1 | { 2 | "simpleTerms": { 3 | "module": "scope", 4 | 5 | "\"global\"": "modifier", 6 | "\"nonlocal\"": "modifier", 7 | 8 | "decorator": "function", 9 | "\"print\"": "function", 10 | "\"assert\"": "function", 11 | "\"exec\"": "function", 12 | "\"del\"": "function", 13 | 14 | "integer" : "number", 15 | "float" : "number", 16 | "string": "string", 17 | "escape_sequence": "string", 18 | "interpolation": "string", 19 | "comment": "comment", 20 | 21 | "none": "constant", 22 | "true": "constant", 23 | "false": "constant", 24 | 25 | "\"if\"": "control", 26 | "\"else\"": "control", 27 | "\"elif\"": "control", 28 | "\"while\"": "control", 29 | "\"for\"": "control", 30 | "\"return\"": "control", 31 | "\"break\"": "control", 32 | "\"continue\"": "control", 33 | "\"pass\"": "control", 34 | "\"raise\"": "control", 35 | "\"yield\"": "control", 36 | "\"await\"": "control", 37 | "\"async\"": "control", 38 | "\"try\"": "control", 39 | "\"except\"": "control", 40 | "\"with\"": "control", 41 | "\"as\"": "control", 42 | "\"finally\"": "control", 43 | 44 | "\"+\"": "operator", 45 | "\"-\"": "operator", 46 | "\"*\"": "operator", 47 | "\"/\"": "operator", 48 | "\"%\"": "operator", 49 | "\"@\"": "operator", 50 | "\"**\"": "operator", 51 | "\"//\"": "operator", 52 | "\"==\"": "operator", 53 | "\"!=\"": "operator", 54 | "\"<>\"": "operator", 55 | "\">\"": "operator", 56 | "\"<\"": "operator", 57 | "\">=\"": "operator", 58 | "\"<=\"": "operator", 59 | "\"=\"": "operator", 60 | "\"+=\"": "operator", 61 | "\"-=\"": "operator", 62 | "\"*=\"": "operator", 63 | "\"/=\"": "operator", 64 | "\"%=\"": "operator", 65 | "\"@=\"": "operator", 66 | "\"**=\"": "operator", 67 | "\"//=\"": "operator", 68 | "\"&\"": "operator", 69 | "\"|\"": "operator", 70 | "\"^\"": "operator", 71 | "\"~\"": "operator", 72 | "\"<<\"": "operator", 73 | "\">>\"": "operator", 74 | 75 | "\"in\"": "operator", 76 | "\"and\"": "operator", 77 | "\"or\"": "operator", 78 | "\"not\"": "operator", 79 | "\"is\"": "operator", 80 | 81 | "\"import\"": "directive", 82 | "\"from\"": "directive", 83 | "\"class\"": "directive", 84 | "\"def\"": "directive", 85 | "\"lambda\"": "directive", 86 | 87 | "\"[\"": "punctuation", 88 | "\"]\"": "punctuation", 89 | "\"{\"": "punctuation", 90 | "\"}\"": "punctuation", 91 | "\"(\"": "punctuation", 92 | "\")\"": "punctuation" 93 | }, 94 | 95 | "complexTerms": ["identifier", "attribute"], 96 | 97 | "complexScopes": { 98 | "type > identifier": "type", 99 | "class_definition > identifier": "type", 100 | "class_definition > argument_list > attribute": "type", 101 | "class_definition > argument_list > identifier": "type", 102 | "class_definition > argument_list > keyword_argument > attribute": "type", 103 | "class_definition > argument_list > keyword_argument > identifier": "type", 104 | 105 | "identifier": "variable", 106 | "attribute > identifier": "variable", 107 | "keyword_argument > identifier": "variable", 108 | "default_parameter > identifier": "variable", 109 | "parameters > identifier": "variable", 110 | "parameters > list_splat > identifier": "variable", 111 | "parameters > dictionary_splat > identifier": "variable", 112 | 113 | "call > identifier": "function", 114 | "call > attribute > identifier[-1]": "function", 115 | "function_definition > identifier": "function" 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /grammars/c.json: -------------------------------------------------------------------------------- 1 | { 2 | "simpleTerms": { 3 | "type_identifier": "type", 4 | "primitive_type": "type", 5 | "\"signed\"": "type", 6 | "\"unsigned\"": "type", 7 | "\"short\"": "type", 8 | "\"long\"": "type", 9 | 10 | "statement_identifier": "variable", 11 | 12 | "\"const\"": "modifier", 13 | "\"static\"": "modifier", 14 | "\"auto\"": "modifier", 15 | "\"extern\"": "modifier", 16 | "\"inline\"": "modifier", 17 | "\"register\"": "modifier", 18 | "\"volatile\"": "modifier", 19 | "\"restrict\"": "modifier", 20 | "\"_Atomic\"": "modifier", 21 | "\"__attribute__\"": "modifier", 22 | "function_specifier": "modifier", 23 | 24 | "number_literal": "number", 25 | "char_literal": "string", 26 | "string_literal": "string", 27 | "system_lib_string": "string", 28 | "escape_sequence": "string", 29 | "comment": "comment", 30 | 31 | "null": "constant", 32 | "true": "constant", 33 | "false": "constant", 34 | 35 | "\"if\"": "control", 36 | "\"else\"": "control", 37 | "\"do\"": "control", 38 | "\"for\"": "control", 39 | "\"while\"": "control", 40 | "\"break\"": "control", 41 | "\"continue\"": "control", 42 | "\"return\"": "control", 43 | "\"switch\"": "control", 44 | "\"case\"": "control", 45 | "\"default\"": "control", 46 | "\"goto\"": "control", 47 | "\"struct\"": "control", 48 | "\"enum\"": "control", 49 | "\"union\"": "control", 50 | "\"typedef\"": "control", 51 | 52 | "\"sizeof\"": "operator", 53 | "\".\"": "operator", 54 | "\"->\"": "operator", 55 | "\"*\"": "operator", 56 | "\"-\"": "operator", 57 | "\"+\"": "operator", 58 | "\"/\"": "operator", 59 | "\"%\"": "operator", 60 | "\"++\"": "operator", 61 | "\"--\"": "operator", 62 | "\"==\"": "operator", 63 | "\"!\"": "operator", 64 | "\"!=\"": "operator", 65 | "\"<\"": "operator", 66 | "\">\"": "operator", 67 | "\">=\"": "operator", 68 | "\"<=\"": "operator", 69 | "\"&&\"": "operator", 70 | "\"||\"": "operator", 71 | "\"&\"": "operator", 72 | "\"|\"": "operator", 73 | "\"^\"": "operator", 74 | "\"~\"": "operator", 75 | "\"<<\"": "operator", 76 | "\">>\"": "operator", 77 | "\"=\"": "operator", 78 | "\"+=\"": "operator", 79 | "\"-=\"": "operator", 80 | "\"*=\"": "operator", 81 | "\"/=\"": "operator", 82 | "\"%=\"": "operator", 83 | "\"<<=\"": "operator", 84 | "\">>=\"": "operator", 85 | "\"&=\"": "operator", 86 | "\"^=\"": "operator", 87 | "\"|=\"": "operator", 88 | "\"?\"": "operator", 89 | "\":\"": "operator", 90 | 91 | "\"#if\"": "directive", 92 | "\"#ifdef\"": "directive", 93 | "\"#ifndef\"": "directive", 94 | "\"#elif\"": "directive", 95 | "\"#else\"": "directive", 96 | "\"#endif\"": "directive", 97 | "\"#define\"": "directive", 98 | "\"#include\"": "directive", 99 | "preproc_directive": "directive", 100 | "preproc_arg": "directive", 101 | 102 | "\";\"": "punctuation", 103 | "\"[\"": "punctuation", 104 | "\"]\"": "punctuation", 105 | "\",\"": "punctuation", 106 | "\"{\"": "punctuation", 107 | "\"}\"": "punctuation", 108 | "\"(\"": "punctuation", 109 | "\")\"": "punctuation" 110 | }, 111 | 112 | "complexTerms": ["identifier", "field_identifier"], 113 | 114 | "complexScopes": { 115 | "identifier": "variable", 116 | "field_identifier": "variable", 117 | 118 | "call_expression > identifier" : "function", 119 | "call_expression > field_expression > field_identifier" : "function", 120 | "function_declarator > identifier" : "function" 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /grammars/ocaml.json: -------------------------------------------------------------------------------- 1 | { 2 | "simpleTerms": { 3 | "class_name": "type", 4 | "module_type_name": "type", 5 | "constructor_name": "type", 6 | 7 | "label": "variable", 8 | "field_name": "variable", 9 | "instance_variable_name": "variable", 10 | "attribute_id": "variable", 11 | "type_variable": "variable", 12 | "conversion_specification": "variable", 13 | "tag": "variable", 14 | 15 | "method_name": "function", 16 | "directive": "function", 17 | "\"open\"": "function", 18 | "\"include\"": "function", 19 | "\"inherit\"": "function", 20 | 21 | "\"private\"": "modifier", 22 | "\"rec\"": "modifier", 23 | "\"nonrec\"": "modifier", 24 | "\"mutable\"": "modifier", 25 | "\"constraint\"": "modifier", 26 | "\"virtual\"": "modifier", 27 | 28 | "\"if\"": "control", 29 | "\"then\"": "control", 30 | "\"else\"": "control", 31 | "\"while\"": "control", 32 | "\"do\"": "control", 33 | "\"done\"": "control", 34 | "\"for\"": "control", 35 | "\"to\"": "control", 36 | "\"downto\"": "control", 37 | "\"match\"": "control", 38 | "\"with\"": "control", 39 | "\"when\"": "control", 40 | "\"function\"": "control", 41 | "\"fun\"": "control", 42 | "\"try\"": "control", 43 | "\"|\"": "control", 44 | "\"->\"": "control", 45 | "\"sig\"": "control", 46 | "\"struct\"": "control", 47 | "\"object\"": "control", 48 | "\"begin\"": "control", 49 | "\"end\"": "control", 50 | "match_operator": "control", 51 | 52 | "\"in\"": "operator", 53 | "\"module\"": "operator", 54 | "\"functor\"": "operator", 55 | "\"class\"": "operator", 56 | "\"let\"": "operator", 57 | "\"and\"": "operator", 58 | "\"external\"": "operator", 59 | "\"method\"": "operator", 60 | "\"initializer\"": "operator", 61 | "\"type\"": "operator", 62 | "\"exception\"": "operator", 63 | "\"val\"": "operator", 64 | 65 | "prefix_operator": "operator", 66 | "infix_operator": "operator", 67 | "indexing_operator": "operator", 68 | "let_operator": "operator", 69 | "and_operator": "operator", 70 | "\"*\"": "operator", 71 | "\"&\"": "operator", 72 | "\"#\"": "operator", 73 | "\"::\"": "operator", 74 | "\"assert\"": "operator", 75 | "\"lazy\"": "operator", 76 | "\"of\"": "operator", 77 | "\"as\"": "operator", 78 | "\"<-\"": "operator", 79 | "\"new\"": "operator", 80 | 81 | "comment": "comment", 82 | "line_number_directive": "comment", 83 | "shebang": "comment", 84 | "number": "number", 85 | "string": "string", 86 | "quoted_string": "string", 87 | "character": "string", 88 | "escape_sequence": "string", 89 | "pretty_printing_indication": "string", 90 | "boolean": "constant", 91 | "unit": "constant", 92 | 93 | "\"[@\"": "punctuation", 94 | "\"[@@\"": "punctuation", 95 | "\"[@@@\"": "punctuation", 96 | "\"[%\"": "punctuation", 97 | "\"[%%\"": "punctuation", 98 | "\"%\"": "punctuation", 99 | "\";\"": "punctuation", 100 | "\";;\"": "punctuation", 101 | "\",\"": "punctuation", 102 | "\"[\"": "punctuation", 103 | "\"]\"": "punctuation", 104 | "\"[|\"": "punctuation", 105 | "\"|]\"": "punctuation", 106 | "\"{\"": "punctuation", 107 | "\"}\"": "punctuation", 108 | "\"(\"": "punctuation", 109 | "\")\"": "punctuation", 110 | "\"=\"": "punctuation", 111 | "\":\"": "punctuation", 112 | "\":>\"": "punctuation", 113 | "\"+=\"": "punctuation", 114 | "\":=\"": "punctuation" 115 | }, 116 | 117 | "complexTerms": ["value_name", "module_name"], 118 | 119 | "complexScopes": { 120 | "module_name": "type", 121 | "value_name": "variable", 122 | 123 | "value_specification > value_name": "function", 124 | "let_binding > value_name": "function", 125 | "external > value_name": "function", 126 | 127 | "parameter > value_name": "variable", 128 | "alias_pattern > value_name": "variable", 129 | "module_parameter > module_name": "variable", 130 | "inheritance_definition > value_name": "variable" 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /grammars/javascript.json: -------------------------------------------------------------------------------- 1 | { 2 | "simpleTerms": { 3 | "shorthand_property_identifier": "variable", 4 | 5 | "\"var\"": "modifier", 6 | "\"let\"": "modifier", 7 | "\"extends\"": "modifier", 8 | "\"const\"": "modifier", 9 | "\"static\"": "modifier", 10 | 11 | "number": "number", 12 | "string": "string", 13 | "escape_sequence": "string", 14 | "template_string": "string", 15 | "regex": "string", 16 | "comment": "comment", 17 | "hash_bang_line": "comment", 18 | 19 | "true": "constant", 20 | "false": "constant", 21 | "null": "constant", 22 | "undefined": "constant", 23 | 24 | "\"as\"": "control", 25 | "\"if\"": "control", 26 | "\"do\"": "control", 27 | "\"else\"": "control", 28 | "\"while\"": "control", 29 | "\"for\"": "control", 30 | "\"return\"": "control", 31 | "\"break\"": "control", 32 | "\"continue\"": "control", 33 | "\"throw\"": "control", 34 | "\"try\"": "control", 35 | "\"catch\"": "control", 36 | "\"finally\"": "control", 37 | "\"switch\"": "control", 38 | "\"case\"": "control", 39 | "\"default\"": "control", 40 | "\"export\"": "control", 41 | "\"import\"": "control", 42 | "\"from\"": "control", 43 | "\"yield\"": "control", 44 | "\"async\"": "control", 45 | "\"await\"": "control", 46 | "\"debugger\"": "control", 47 | "\"delete\"": "control", 48 | 49 | "this": "operator", 50 | "\"class\"": "operator", 51 | "\"function\"": "operator", 52 | 53 | "\"in\"": "operator", 54 | "\"instanceof\"": "operator", 55 | "\"of\"": "operator", 56 | "\"new\"": "operator", 57 | "\"typeof\"": "operator", 58 | "\"get\"": "operator", 59 | "\"set\"": "operator", 60 | 61 | "\"=\"": "operator", 62 | "\"+=\"": "operator", 63 | "\"-=\"": "operator", 64 | "\"*=\"": "operator", 65 | "\"/=\"": "operator", 66 | "\"%=\"": "operator", 67 | "\"<<=\"": "operator", 68 | "\">>=\"": "operator", 69 | "\">>>=\"": "operator", 70 | "\"&=\"": "operator", 71 | "\"^=\"": "operator", 72 | "\"|=\"": "operator", 73 | "\"!\"": "operator", 74 | "\"+\"": "operator", 75 | "\"-\"": "operator", 76 | "\"*\"": "operator", 77 | "\"/\"": "operator", 78 | "\"%\"": "operator", 79 | "\"==\"": "operator", 80 | "\"===\"": "operator", 81 | "\"!=\"": "operator", 82 | "\"!==\"": "operator", 83 | "\">=\"": "operator", 84 | "\"<=\"": "operator", 85 | "\"=>\"": "operator", 86 | "\">\"": "operator", 87 | "\"<\"": "operator", 88 | "\":\"": "operator", 89 | "\"?\"": "operator", 90 | "\"&&\"": "operator", 91 | "\"||\"": "operator", 92 | "\"&\"": "operator", 93 | "\"~\"": "operator", 94 | "\"^\"": "operator", 95 | "\">>\"": "operator", 96 | "\">>>\"": "operator", 97 | "\"<<\"": "operator", 98 | "\"|\"": "operator", 99 | "\"++\"": "operator", 100 | "\"--\"": "operator", 101 | "\"...\"": "operator", 102 | 103 | "\"(\"": "punctuation", 104 | "\")\"": "punctuation", 105 | "\"{\"": "punctuation", 106 | "\"}\"": "punctuation", 107 | "\";\"": "punctuation", 108 | "\"[\"": "punctuation", 109 | "\"]\"": "punctuation", 110 | "\".\"": "punctuation", 111 | "\",\"": "punctuation", 112 | "\"${\"": "punctuation" 113 | }, 114 | 115 | "complexTerms": ["identifier", "field_identifier", "property_identifier", "super"], 116 | 117 | "complexScopes": { 118 | "identifier": "variable", 119 | "property_identifier": "variable", 120 | "formal_parameters > identifier": "variable", 121 | "jsx_attribute > property_identifier": "variable", 122 | 123 | "class > identifier": "type", 124 | "new_expression > identifier": "type", 125 | "jsx_opening_element > identifier": "type", 126 | "jsx_closing_element > identifier": "type", 127 | "jsx_self_closing_element > identifier": "type", 128 | 129 | "call_expression > identifier": "function", 130 | "call_expression > super": "function", 131 | "function > identifier": "function", 132 | "generator_function > identifier": "function", 133 | "method_definition > property_identifier": "function", 134 | "call_expression > member_expression > property_identifier": "function" 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /grammars/typescript.json: -------------------------------------------------------------------------------- 1 | { 2 | "simpleTerms": { 3 | "type_identifier": "type", 4 | "predefined_type": "type", 5 | 6 | "namespace": "scope", 7 | "\"module\"": "scope", 8 | 9 | "shorthand_property_identifier": "variable", 10 | 11 | "\"var\"": "modifier", 12 | "\"let\"": "modifier", 13 | "\"extends\"": "modifier", 14 | "\"const\"": "modifier", 15 | "\"static\"": "modifier", 16 | "\"public\"": "modifier", 17 | "\"private\"": "modifier", 18 | "\"protected\"": "modifier", 19 | "\"readonly\"": "modifier", 20 | 21 | "number": "number", 22 | "string": "string", 23 | "escape_sequence": "string", 24 | "template_string": "string", 25 | "template_substitution": "string", 26 | "regex": "string", 27 | "comment": "comment", 28 | "hash_bang_line": "comment", 29 | 30 | "true": "constant", 31 | "false": "constant", 32 | "null": "constant", 33 | "undefined": "constant", 34 | 35 | "\"as\"": "control", 36 | "\"if\"": "control", 37 | "\"do\"": "control", 38 | "\"else\"": "control", 39 | "\"while\"": "control", 40 | "\"for\"": "control", 41 | "\"return\"": "control", 42 | "\"break\"": "control", 43 | "\"continue\"": "control", 44 | "\"throw\"": "control", 45 | "\"try\"": "control", 46 | "\"catch\"": "control", 47 | "\"finally\"": "control", 48 | "\"switch\"": "control", 49 | "\"case\"": "control", 50 | "\"default\"": "control", 51 | "\"export\"": "control", 52 | "\"import\"": "control", 53 | "\"from\"": "control", 54 | "\"yield\"": "control", 55 | "\"async\"": "control", 56 | "\"await\"": "control", 57 | "\"debugger\"": "control", 58 | 59 | "this": "operator", 60 | "\"class\"": "operator", 61 | "\"type\"": "operator", 62 | "\"enum\"": "operator", 63 | "\"function\"": "operator", 64 | "\"interface\"": "operator", 65 | "\"implements\"": "operator", 66 | "\"declare\"": "operator", 67 | 68 | "\"in\"": "operator", 69 | "\"instanceof\"": "operator", 70 | "\"of\"": "operator", 71 | "\"new\"": "operator", 72 | "\"delete\"": "operator", 73 | "\"typeof\"": "operator", 74 | "\"get\"": "operator", 75 | "\"set\"": "operator", 76 | 77 | "\"=\"": "operator", 78 | "\"+=\"": "operator", 79 | "\"-=\"": "operator", 80 | "\"*=\"": "operator", 81 | "\"/=\"": "operator", 82 | "\"%=\"": "operator", 83 | "\"<<=\"": "operator", 84 | "\">>=\"": "operator", 85 | "\">>>=\"": "operator", 86 | "\"&=\"": "operator", 87 | "\"^=\"": "operator", 88 | "\"|=\"": "operator", 89 | "\"!\"": "operator", 90 | "\"+\"": "operator", 91 | "\"-\"": "operator", 92 | "\"*\"": "operator", 93 | "\"/\"": "operator", 94 | "\"%\"": "operator", 95 | "\"==\"": "operator", 96 | "\"===\"": "operator", 97 | "\"!=\"": "operator", 98 | "\"!==\"": "operator", 99 | "\">=\"": "operator", 100 | "\"<=\"": "operator", 101 | "\"=>\"": "operator", 102 | "\">\"": "operator", 103 | "\"<\"": "operator", 104 | "\":\"": "operator", 105 | "\"?\"": "operator", 106 | "\"&&\"": "operator", 107 | "\"||\"": "operator", 108 | "\"&\"": "operator", 109 | "\"~\"": "operator", 110 | "\"^\"": "operator", 111 | "\">>\"": "operator", 112 | "\">>>\"": "operator", 113 | "\"<<\"": "operator", 114 | "\"|\"": "operator", 115 | "\"++\"": "operator", 116 | "\"--\"": "operator", 117 | "\"...\"": "operator", 118 | 119 | "\"(\"": "punctuation", 120 | "\")\"": "punctuation", 121 | "\"{\"": "punctuation", 122 | "\"}\"": "punctuation", 123 | "\";\"": "punctuation", 124 | "\"[\"": "punctuation", 125 | "\"]\"": "punctuation", 126 | "\".\"": "punctuation", 127 | "\",\"": "punctuation", 128 | "\"${\"": "punctuation" 129 | }, 130 | 131 | "complexTerms": ["identifier", "property_identifier", "super"], 132 | 133 | "complexScopes": { 134 | "class > identifier": "type", 135 | "new_expression > call_expression > identifier": "type", 136 | "jsx_opening_element > identifier": "type", 137 | "jsx_closing_element > identifier": "type", 138 | "jsx_self_closing_element > identifier": "type", 139 | 140 | "nested_type_identifier > identifier": "scope", 141 | 142 | "identifier": "variable", 143 | "property_identifier": "variable", 144 | "member_expression > property_identifier": "variable", 145 | "jsx_attribute > property_identifier": "variable", 146 | 147 | "call_expression > identifier": "function", 148 | "call_expression > super": "function", 149 | "function > identifier": "function", 150 | "generator_function > identifier": "function", 151 | "method_definition > property_identifier": "function", 152 | "call_expression > member_expression > property_identifier": "function", 153 | "method_signature > property_identifier": "function", 154 | "function_signature > identifier": "function" 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /grammars/cpp.json: -------------------------------------------------------------------------------- 1 | { 2 | "simpleTerms": { 3 | "type_identifier": "type", 4 | "primitive_type": "type", 5 | "\"unsigned\"": "type", 6 | "\"signed\"": "type", 7 | "\"short\"": "type", 8 | "\"long\"": "type", 9 | "\"auto\"": "type", 10 | 11 | "namespace_identifier": "scope", 12 | 13 | "operator_name": "function", 14 | 15 | "\"public\"": "modifier", 16 | "\"protected\"": "modifier", 17 | "\"private\"": "modifier", 18 | "\"virtual\"": "modifier", 19 | "\"override\"": "modifier", 20 | "\"default\"": "modifier", 21 | "\"final\"": "modifier", 22 | "\"const\"": "modifier", 23 | "\"constexpr\"": "modifier", 24 | "\"static\"": "modifier", 25 | "\"extern\"": "modifier", 26 | "\"inline\"": "modifier", 27 | "\"noexcept\"": "modifier", 28 | "\"explicit\"": "modifier", 29 | "\"friend\"": "modifier", 30 | "\"register\"": "modifier", 31 | "\"volatile\"": "modifier", 32 | "\"restrict\"": "modifier", 33 | "\"_Atomic\"": "modifier", 34 | "\"__attribute__\"": "modifier", 35 | "function_specifier": "modifier", 36 | 37 | "number_literal": "number", 38 | "char_literal": "string", 39 | "string_literal": "string", 40 | "system_lib_string": "string", 41 | "raw_string_literal": "string", 42 | "escape_sequence": "string", 43 | "comment": "comment", 44 | 45 | "null": "constant", 46 | "nullptr": "constant", 47 | "true": "constant", 48 | "false": "constant", 49 | 50 | "\"if\"": "control", 51 | "\"else\"": "control", 52 | "\"do\"": "control", 53 | "\"for\"": "control", 54 | "\"while\"": "control", 55 | "\"break\"": "control", 56 | "\"continue\"": "control", 57 | "\"return\"": "control", 58 | "\"switch\"": "control", 59 | "\"case\"": "control", 60 | "\"goto\"": "control", 61 | 62 | "\"struct\"": "control", 63 | "\"enum\"": "control", 64 | "\"union\"": "control", 65 | "\"typedef\"": "control", 66 | "\"class\"": "control", 67 | "\"using\"": "control", 68 | "\"namespace\"": "control", 69 | "\"template\"": "control", 70 | "\"typename\"": "control", 71 | "\"try\"": "control", 72 | "\"catch\"": "control", 73 | "\"throw\"": "control", 74 | 75 | "\"sizeof\"": "operator", 76 | "\"new\"": "operator", 77 | "\".\"": "operator", 78 | "\"->\"": "operator", 79 | "\"*\"": "operator", 80 | "\"-\"": "operator", 81 | "\"+\"": "operator", 82 | "\"/\"": "operator", 83 | "\"%\"": "operator", 84 | "\"++\"": "operator", 85 | "\"--\"": "operator", 86 | "\"==\"": "operator", 87 | "\"!\"": "operator", 88 | "\"!=\"": "operator", 89 | "\"<\"": "operator", 90 | "\">\"": "operator", 91 | "\">=\"": "operator", 92 | "\"<=\"": "operator", 93 | "\"&&\"": "operator", 94 | "\"||\"": "operator", 95 | "\"&\"": "operator", 96 | "\"|\"": "operator", 97 | "\"^\"": "operator", 98 | "\"~\"": "operator", 99 | "\"<<\"": "operator", 100 | "\">>\"": "operator", 101 | "\"=\"": "operator", 102 | "\"+=\"": "operator", 103 | "\"-=\"": "operator", 104 | "\"*=\"": "operator", 105 | "\"/=\"": "operator", 106 | "\"%=\"": "operator", 107 | "\"<<=\"": "operator", 108 | "\">>=\"": "operator", 109 | "\"&=\"": "operator", 110 | "\"^=\"": "operator", 111 | "\"|=\"": "operator", 112 | "\"?\"": "operator", 113 | "\"::\"": "operator", 114 | 115 | "\"#if\"": "directive", 116 | "\"#ifdef\"": "directive", 117 | "\"#ifndef\"": "directive", 118 | "\"#elif\"": "directive", 119 | "\"#else\"": "directive", 120 | "\"#endif\"": "directive", 121 | "\"#define\"": "directive", 122 | "\"#include\"": "directive", 123 | "preproc_directive": "directive", 124 | 125 | "\";\"": "punctuation", 126 | "\":\"": "punctuation", 127 | "\",\"": "punctuation", 128 | "\"[\"": "punctuation", 129 | "\"]\"": "punctuation", 130 | "\"{\"": "punctuation", 131 | "\"}\"": "punctuation", 132 | "\"(\"": "punctuation", 133 | "\")\"": "punctuation" 134 | }, 135 | 136 | "complexTerms": ["identifier", "field_identifier", "\"delete\""], 137 | 138 | "complexScopes": { 139 | "identifier": "variable", 140 | "field_identifier": "variable", 141 | 142 | "call_expression > identifier": "function", 143 | "call_expression > field_expression > field_identifier": "function", 144 | "call_expression > scoped_identifier > identifier": "function", 145 | "template_function > identifier": "function", 146 | "template_function > scoped_identifier > identifier": "function", 147 | "template_method > field_identifier": "function", 148 | "function_declarator > identifier": "function", 149 | "function_declarator > field_identifier": "function", 150 | "function_declarator > scoped_identifier > identifier": "function", 151 | "destructor_name > identifier": "function", 152 | 153 | "\"delete\"": "operator", 154 | "delete_method_clause > \"delete\"": "modifier" 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /grammars/typescriptreact.json: -------------------------------------------------------------------------------- 1 | { 2 | "simpleTerms": { 3 | "type_identifier": "type", 4 | "predefined_type": "type", 5 | 6 | "namespace": "scope", 7 | "\"module\"": "scope", 8 | 9 | "shorthand_property_identifier": "variable", 10 | 11 | "\"var\"": "modifier", 12 | "\"let\"": "modifier", 13 | "\"extends\"": "modifier", 14 | "\"const\"": "modifier", 15 | "\"static\"": "modifier", 16 | "\"public\"": "modifier", 17 | "\"private\"": "modifier", 18 | "\"protected\"": "modifier", 19 | "\"readonly\"": "modifier", 20 | "\"namespace\"": "modifier", 21 | "\"module\"": "modifier", 22 | 23 | "number": "number", 24 | "string": "string", 25 | "escape_sequence": "string", 26 | "template_string": "string", 27 | "template_substitution": "string", 28 | "regex": "string", 29 | "comment": "comment", 30 | "hash_bang_line": "comment", 31 | 32 | "true": "constant", 33 | "false": "constant", 34 | "null": "constant", 35 | "undefined": "constant", 36 | 37 | "\"as\"": "control", 38 | "\"if\"": "control", 39 | "\"do\"": "control", 40 | "\"else\"": "control", 41 | "\"while\"": "control", 42 | "\"for\"": "control", 43 | "\"return\"": "control", 44 | "\"break\"": "control", 45 | "\"continue\"": "control", 46 | "\"throw\"": "control", 47 | "\"try\"": "control", 48 | "\"catch\"": "control", 49 | "\"finally\"": "control", 50 | "\"switch\"": "control", 51 | "\"case\"": "control", 52 | "\"default\"": "control", 53 | "\"export\"": "control", 54 | "\"import\"": "control", 55 | "\"from\"": "control", 56 | "\"yield\"": "control", 57 | "\"async\"": "control", 58 | "\"await\"": "control", 59 | "\"debugger\"": "control", 60 | 61 | "this": "operator", 62 | "\"class\"": "operator", 63 | "\"type\"": "operator", 64 | "\"enum\"": "operator", 65 | "\"function\"": "operator", 66 | "\"interface\"": "operator", 67 | "\"implements\"": "operator", 68 | "\"declare\"": "operator", 69 | 70 | "\"in\"": "operator", 71 | "\"instanceof\"": "operator", 72 | "\"of\"": "operator", 73 | "\"new\"": "operator", 74 | "\"delete\"": "operator", 75 | "\"typeof\"": "operator", 76 | "\"get\"": "operator", 77 | "\"set\"": "operator", 78 | 79 | "\"=\"": "operator", 80 | "\"+=\"": "operator", 81 | "\"-=\"": "operator", 82 | "\"*=\"": "operator", 83 | "\"/=\"": "operator", 84 | "\"%=\"": "operator", 85 | "\"<<=\"": "operator", 86 | "\">>=\"": "operator", 87 | "\">>>=\"": "operator", 88 | "\"&=\"": "operator", 89 | "\"^=\"": "operator", 90 | "\"|=\"": "operator", 91 | "\"!\"": "operator", 92 | "\"+\"": "operator", 93 | "\"-\"": "operator", 94 | "\"*\"": "operator", 95 | "\"/\"": "operator", 96 | "\"%\"": "operator", 97 | "\"==\"": "operator", 98 | "\"===\"": "operator", 99 | "\"!=\"": "operator", 100 | "\"!==\"": "operator", 101 | "\">=\"": "operator", 102 | "\"<=\"": "operator", 103 | "\"=>\"": "operator", 104 | "\">\"": "operator", 105 | "\"<\"": "operator", 106 | "\":\"": "operator", 107 | "\"?\"": "operator", 108 | "\"&&\"": "operator", 109 | "\"||\"": "operator", 110 | "\"&\"": "operator", 111 | "\"~\"": "operator", 112 | "\"^\"": "operator", 113 | "\">>\"": "operator", 114 | "\">>>\"": "operator", 115 | "\"<<\"": "operator", 116 | "\"|\"": "operator", 117 | "\"++\"": "operator", 118 | "\"--\"": "operator", 119 | "\"...\"": "operator", 120 | 121 | "\"(\"": "punctuation", 122 | "\")\"": "punctuation", 123 | "\"{\"": "punctuation", 124 | "\"}\"": "punctuation", 125 | "\";\"": "punctuation", 126 | "\"[\"": "punctuation", 127 | "\"]\"": "punctuation", 128 | "\".\"": "punctuation", 129 | "\",\"": "punctuation", 130 | "\"${\"": "punctuation" 131 | }, 132 | 133 | "complexTerms": ["identifier", "property_identifier", "super"], 134 | 135 | "complexScopes": { 136 | "class > identifier": "type", 137 | "new_expression > call_expression > identifier": "type", 138 | "jsx_opening_element > identifier": "type", 139 | "jsx_closing_element > identifier": "type", 140 | "jsx_opening_element > nested_identifier > identifier": "type", 141 | "jsx_closing_element > nested_identifier > identifier": "type", 142 | "jsx_self_closing_element > identifier": "type", 143 | 144 | "nested_type_identifier > identifier": "scope", 145 | 146 | "identifier": "variable", 147 | "property_identifier": "variable", 148 | "member_expression > property_identifier": "variable", 149 | "jsx_attribute > property_identifier": "variable", 150 | 151 | "call_expression > identifier": "function", 152 | "call_expression > super": "function", 153 | "function > identifier": "function", 154 | "generator_function > identifier": "function", 155 | "method_definition > property_identifier": "function", 156 | "call_expression > member_expression > property_identifier": "function", 157 | "method_signature > property_identifier": "function", 158 | "function_signature > identifier": "function" 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /grammars/php.json: -------------------------------------------------------------------------------- 1 | { 2 | "simpleTerms": { 3 | 4 | "variable_name": "variable", 5 | 6 | "__construct": "function", 7 | "\"echo\"": "function", 8 | "\"print\"": "function", 9 | "\"unset\"": "function", 10 | "\"isset\"": "function", 11 | "\"eval\"": "function", 12 | "\"array\"": "function", 13 | "\"list\"": "function", 14 | "\"empty\"": "function", 15 | 16 | "require_once": "function", 17 | "require": "function", 18 | "include_once": "function", 19 | "include": "function", 20 | 21 | "\"callable\"": "modifier", 22 | "\"var\"": "modifier", 23 | "\"trait\"": "modifier", 24 | "\"class\"": "modifier", 25 | "\"interface\"": "modifier", 26 | "\"function\"": "modifier", 27 | "\"type\"": "modifier", 28 | 29 | "\"static\"": "modifier", 30 | "\"public\"": "modifier", 31 | "\"private\"": "modifier", 32 | "\"protected\"": "modifier", 33 | "\"global\"": "modifier", 34 | "\"const\"": "modifier", 35 | "\"abstract\"": "modifier", 36 | "\"extends\"": "modifier", 37 | "\"implements\"": "modifier", 38 | "\"final\"": "modifier", 39 | 40 | "integer": "number", 41 | "float": "number", 42 | "string": "string", 43 | "regex": "string", 44 | 45 | "true": "constant", 46 | "false": "constant", 47 | 48 | "comment": "comment", 49 | 50 | "\"if\"": "control", 51 | "\"do\"": "control", 52 | "\"else\"": "control", 53 | "\"elseif\"": "control", 54 | "\"endif\"": "control", 55 | "\"while\"": "control", 56 | "\"endwhile\"": "control", 57 | "\"for\"": "control", 58 | "\"endfor\"": "control", 59 | "\"foreach\"": "control", 60 | "\"endforeach\"": "control", 61 | "\"declare\"": "control", 62 | "\"enddeclare\"": "control", 63 | "\"return\"": "control", 64 | "\"break\"": "control", 65 | "\"continue\"": "control", 66 | "\"throw\"": "control", 67 | "\"try\"": "control", 68 | "\"catch\"": "control", 69 | "\"finally\"": "control", 70 | "\"switch\"": "control", 71 | "\"endswitch\"": "control", 72 | "\"case\"": "control", 73 | "\"default\"": "control", 74 | "\"yield\"": "control", 75 | "\"goto\"": "control", 76 | "\"exit\"": "control", 77 | "\"die\"": "control", 78 | 79 | "\"new\"": "operator", 80 | "\"clone\"": "operator", 81 | "\"insteadof\"": "operator", 82 | "\"instanceof\"": "operator", 83 | 84 | "\"+\"": "operator", 85 | "\"-\"": "operator", 86 | "\"*\"": "operator", 87 | "\"/\"": "operator", 88 | "\"%\"": "operator", 89 | "\"**\"": "operator", 90 | "\"=\"": "operator", 91 | "\"==\"": "operator", 92 | "\"===\"": "operator", 93 | "\"!=\"": "operator", 94 | "\"!==\"": "operator", 95 | "\"<\"": "operator", 96 | "\">\"": "operator", 97 | "\"<>\"": "operator", 98 | "\"<=\"": "operator", 99 | "\"=>\"": "operator", 100 | "\">=\"": "operator", 101 | "\"<=>\"": "operator", 102 | "\"&\"": "operator", 103 | "\"$\"": "operator", 104 | "\"|\"": "operator", 105 | "\"^\"": "operator", 106 | "\"~\"": "operator", 107 | "\"<<\"": "operator", 108 | "\">>\"": "operator", 109 | "\"++\"": "operator", 110 | "\"--\"": "operator", 111 | "\"and\"": "operator", 112 | "\"or\"": "operator", 113 | "\"xor\"": "operator", 114 | "\"!\"": "operator", 115 | "\"&&\"": "operator", 116 | "\"||\"": "operator", 117 | "\".\"": "operator", 118 | "\"?\"": "operator", 119 | "\":\"": "operator", 120 | "\"??\"": "operator", 121 | "\"->\"": "operator", 122 | "\"as\"": "operator", 123 | 124 | "\"use\"": "directive", 125 | "\"namespace\"": "directive", 126 | 127 | "\"(\"": "punctuation", 128 | "\")\"": "punctuation", 129 | "\"{\"": "punctuation", 130 | "\"}\"": "punctuation", 131 | "\"[\"": "punctuation", 132 | "\"]\"": "punctuation", 133 | "\";\"": "punctuation", 134 | "\",\"": "punctuation" 135 | }, 136 | 137 | "complexTerms": ["name", "simple_variable"], 138 | 139 | "complexScopes": { 140 | "class_declaration > name": "type", 141 | "catch_clause > qualified_name > name": "type", 142 | "class_base_clause > qualified_name > name": "type", 143 | "interface_declaration > name": "type", 144 | "class_interface_clause > qualified_name > name": "type", 145 | "object_creation_expression > qualified_name > name": "type", 146 | "cast_expression > cast_type": "type", 147 | "object_creation_expression > new_variable > simple_variable": "type", 148 | 149 | "name": "variable", 150 | "member_access_expression > name": "variable", 151 | 152 | "function_definition > name": "function", 153 | "function_call_expression > name": "function", 154 | "function_call_expression > qualified_name": "function", 155 | "method_declaration > name": "function", 156 | "method_declaration > function_definition > name": "function", 157 | "scoped_call_expression > name": "function", 158 | "member_call_expression > name": "function", 159 | 160 | "const_element > name": "constant", 161 | "class_constant_access_expression > name": "constant", 162 | "qualified_name > name": "constant" 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Syntax Highlighter Change Log 2 | 3 | ## **Version 0.5.1** 4 | #### Changes: 5 | * Update *tree-sitter* core and parsers. 6 | * Publishing to Open-VSX registry. 7 | #### Fixes: 8 | * C++: structures with attributes. 9 | * Python: f-strings interpolation. 10 | * JavaScript: editor freezes. 11 | 12 | 13 | ## **Version 0.5.0** 14 | #### Semantic Token Provider 15 | * Utilizes new Semantic Token API. 16 | * Standard semantic token types. 17 | * Follows color theme out-of-the box. 18 | * No need to manually define colors in *settings.json*. 19 | * Much faster implementation. 20 | * Doesn't use slow Decoration API. 21 | 22 | 23 | ## **Version 0.4.5** 24 | #### Critical fixes: 25 | * Fix frequent crashes. 26 | 27 | 28 | ## **Version 0.4.4** 29 | #### New programming languages: 30 | * OCaml 31 | 32 | 33 | ## **Version 0.4.3** 34 | #### Changes: 35 | * Fix highlighting og modules in TypeScript 36 | * Update PHP and TypeScript *tree-sitter* parsers 37 | * Update version of VSCode engine 38 | 39 | 40 | ## **Version 0.4.2** 41 | #### Changes: 42 | * [Setting to enable/disable terms](README.md#syntaxhighlightterms) 43 | * Update *tree-sitter* core and parsers 44 | 45 | 46 | ## **Version 0.4.1** 47 | #### New programming languages: 48 | * ShellScript/Bash 49 | 50 | 51 | ## **Version 0.4.0** 52 | #### New programming languages: 53 | * TypeScript React (TSX) 54 | 55 | 56 | ## **Version 0.3.8** 57 | #### Changes: 58 | * Update core *vscode* and *typescript* packages 59 | * Update core *tree-sitter* packages 60 | * Update *typescript*, *go*, *ruby* and *lua* parsers 61 | 62 | 63 | ## **Version 0.3.7** 64 | #### Changes: 65 | * Update *tree-sitter-python* parser 66 | * Update *vsce* module 67 | * Fix: doesn't work when VSCode is installed on D:\ (#30) 68 | 69 | 70 | ## **Version 0.3.6** 71 | #### Changes: 72 | * Update core *tree-sitter* modules 73 | * Rust: fix use declarations (#29) 74 | * Rust: update *tree-sitter-rust* 75 | * Debug: tool-tip with syntax scope on hover 76 | 77 | 78 | ## **Version 0.3.5** 79 | #### Changes: 80 | * [Setting to enable/disable languages](README.md#syntaxhighlightlanguages) 81 | 82 | 83 | ## **Version 0.3.4** 84 | #### Changes: 85 | * Rust: fix highlighting of module consts (#17) 86 | * Rust: highlighting of `=>` operator 87 | * TS/JS: highlighting of `this` keyword 88 | 89 | 90 | ## **Version 0.3.3** 91 | #### Changes: 92 | * The latest versions of *tree-sitter-cpp/c* 93 | * C++: fix highlighting of `virtual` method definitions 94 | * C++: fix highlighting of `delete` in method definitions 95 | * C++: fix highlighting of `throw` expressions 96 | * C++/C: highlighting of `__attribute__` as *modifier* 97 | 98 | 99 | ## **Version 0.3.2** 100 | #### Changes: 101 | * Go: highlighting of punctuation 102 | * Go: highlighting of `[` and `]` 103 | * Go: highlighting of `&^` and `&^=` operators 104 | * Demo for Go in README.md 105 | 106 | 107 | ## **Version 0.3.1** 108 | #### Changes: 109 | * Demo of {Syntax Highlighter} in README.md 110 | * C++: highlighting of `noexcept` keyword 111 | * C++: highlighting of operator definitions (e.g. `operator!()`) 112 | * C++: highlighting `default` as *modifier* instead of *control* 113 | 114 | 115 | ## **Version 0.3.0** 116 | #### New programming languages: 117 | * Ruby 118 | 119 | 120 | ## **Version 0.2.9** 121 | #### Changes: 122 | * Fix corruption of highlighting on multi-line edits (including formatting and renaming) 123 | * `syntax.highlightComment` setting to optionally disable highlighting of comments 124 | * Update dependency packages 125 | 126 | 127 | ## **Version 0.2.8** 128 | #### New programming languages: 129 | * Lua 130 | 131 | 132 | ## **Version 0.2.7** 133 | #### New programming languages: 134 | * PHP 135 | 136 | #### Fixes: 137 | * TypeScript and Javascript highlighting has been fixed 138 | * In Rust "_" is highlighted as variable 139 | * Internal improvements 140 | 141 | 142 | ## **Version 0.2.6** 143 | #### Changes: 144 | * More consistent names of syntax terms 145 | * Internal improvements 146 | 147 | #### !!!Attention!!! 148 | This release changes names of some syntax terms. 149 | I apologize to all current users, who has already tuned colors, for this inconvenience. 150 | 151 | Please rename {Syntax Highlighter} colors in `settings.json` the following way: 152 | * `"syntax.namespace" -> "syntax.scope"` 153 | * `"syntax.keyword_constant" -> "syntax.constant"` 154 | * `"syntax.keyword_directive" -> "syntax.directive"` 155 | * `"syntax.keyword_control" -> "syntax.control"` 156 | * `"syntax.keyword_operator" -> "syntax.operator"` 157 | * `"syntax.storage_modifier" -> "syntax.modifier"` 158 | 159 | 160 | ## **Version 0.2.5** 161 | #### Fixed bugs: 162 | * Terms like directives and operators stopped to be colored by {Syntax Highlighter} 163 | * Highlighting is not updated in editors, opened on startup, until switch tab 164 | 165 | 166 | ## **Version 0.2.4** 167 | #### Even better Rust 168 | Thanks to [@Geobert](https://github.com/Geobert) ones again. 169 | 170 | 171 | ## **Version 0.2.3** 172 | #### Much better Rust 173 | Huge thanks to [@Geobert](https://github.com/Geobert) for contribution. 174 | 175 | 176 | ## **Version 0.2.2** 177 | #### New programming languages: 178 | * Rust 179 | 180 | 181 | ## **Version 0.2.1** 182 | #### New programming languages: 183 | * Python 184 | 185 | 186 | ## **Version 0.2.0** 187 | ### **Cross-platform support.** 188 | **Huge thanks to [@jeff-hykin](https://github.com/jeff-hykin) for providing the right solution.** 189 | 190 | There is no need to download .vsxi package for your OS from 191 | [Github page](https://github.com/EvgeniyPeshkov/syntax-highlighter/releases) anymore. 192 | Cross-platform version in Marketplace fits any OS and architecture. 193 | 194 | 195 | ## **Version 0.1.1** 196 | #### New programming languages: 197 | * Go 198 | * TypeScript 199 | * JavaScript 200 | 201 | 202 | ## **Version 0.1.0** 203 | ### Initial version 204 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Syntax Highlighter for VSCode 2 | 3 | #### Syntax highlighter based on [Tree-Sitter](https://tree-sitter.github.io/tree-sitter/). 4 | #### Languages: 5 | #### C++, C, Python, TypeScript, TypeScriptReact, JavaScript, 6 | #### Go, Rust, Php, Ruby, ShellScript, Bash, OCaml, Lua 7 | 8 | ![demo](images/demo.gif) 9 | 10 | #### Languages: 11 | * C++ 12 | * C 13 | * Python 14 | * TypeScript 15 | * TypeScriptReact 16 | * JavaScript 17 | * Go 18 | * Rust 19 | * Php 20 | * Ruby 21 | * ShellScript 22 | * Bash 23 | * OCaml 24 | * Lua 25 | * More to come... 26 | 27 | ## Description 28 | 29 | Provides universal syntax coloring engine for almost any programming language. 30 | See [list of currently supported languages](#languages) above. Under the hood the 31 | extension utilizes VSCode Semantic Token API to override syntax coloring provided 32 | by standard TextMate regex matching. Constructing entire syntax tree, Tree-sitter 33 | efficiently overcomes all limitations of built-in TextMate grammars. Being 34 | context-aware, it's able to parse complex language structures providing complete 35 | coverage of source code. Incremental parsing system ensures high performance. 36 | All these advantages enable accurate and consistent syntax highlighting. 37 | 38 | ## Customization 39 | 40 | {Syntax Highlighter} is a 41 | [semantic token provider](https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide). 42 | It follows the current color theme out-of-the-box, as soon as the theme 43 | enables semantic colorization through its `semanticHighlighting` setting. 44 | You can forcefully enable semantic highlighting in `settings.json`: 45 | 46 | ```json 47 | "editor.semanticTokenColorCustomizations": { 48 | "enabled": true, // enable for all themes 49 | "[Default Dark+]": { 50 | "enabled": true // enable for a particular theme 51 | } 52 | } 53 | ``` 54 | 55 | To customize token colors follow 56 | [this guide](https://code.visualstudio.com/docs/getstarted/themes#_editor-semantic-highlighting). 57 | For example: 58 | 59 | ```json 60 | "editor.semanticTokenColorCustomizations": { 61 | "[Default Dark+]": { 62 | "enabled": true, 63 | "rules": { 64 | "type": "#26A69A", 65 | "namespace": "#00897B", 66 | "function": "#00BCD4", 67 | "variable": "#42A5F5", 68 | "number": "#90A4AE", 69 | "string": { 70 | "foreground": "#90A4AE", 71 | "italic": true 72 | }, 73 | "comment": { 74 | "foreground": "#546E7A", 75 | "fontStyle": "italic" 76 | }, 77 | "variable.readonly.defaultLibrary": "#A89F9B", 78 | "macro": "#7E57C2", 79 | "keyword": "#7986CB", 80 | "operator": "#9575CD", 81 | "type.modification": "#00897B", 82 | "punctuation": "#A1887F" 83 | } 84 | } 85 | } 86 | ``` 87 | 88 | If no color is assigned to a semantic token by a theme, the VSCode uses the 89 | [Semantic Token Scope Map](https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide#semantic-token-scope-map). 90 | 91 | {Syntax Highlighter} provides the next tokens: 92 | * **type** - types (class, struct, enum) 93 | * **namespace** - scopes (namespace, module, outer class) 94 | * **function** - functions (function, method, interface) 95 | * **variable** - variables (variable, property, member) 96 | * **number** - number literals (10, 10.0f, 0x10) 97 | * **string** - string literals (string, regex, char) 98 | * **comment** - comments 99 | * **variable.readonly.defaultLibrary** - language constants (true, nullptr, nil) 100 | * **macro** - directives (#include, import, use) 101 | * **keyword** - control keywords (if, continue, return) 102 | * **operator** - operators (&&, +=, ->) 103 | * **type.modification** - modifiers (const, public, override) 104 | * **punctuation** - punctuation symbols (., :, {) 105 | 106 | **punctuation** is a custom (non-standard) token introduced by {Syntax Highlighter}. 107 | Its fallback TextMate scope is *"punctuation"*. The default fallback for 108 | **type.modification** is *"storage.modifier"*. Note that if you override **type** 109 | color you should also override **type.modification**. Otherwise, **type.modification** 110 | color will first fallback to a more general **type** instead of mapped TextMate scope. 111 | The same goes for **variable** and **variable.readonly.defaultLibrary**. 112 | 113 | ## Settings 114 | #### `syntax.highlightComment` 115 | Enable/disable highlighting of comments. 116 | 117 | This setting is useful, when you have other extensions, providing colorization within 118 | comments. For example, highlighting of ToDo-like tags or documentation syntax, like 119 | Doxygen or Sphinx. To not overwrite their colorization you can disable highlighting of 120 | comments, putting `"syntax.highlightComment": false,` in your `settings.json`. 121 | 122 | #### `syntax.highlightTerms` 123 | List of enabled terms. 124 | 125 | If you want to disable {Syntax Highlighter} for certain terms and use standard 126 | coloring instead, just remove them from `syntax.highlightTerms` list in your 127 | `settings.json`. By default all [supported terms]((#customization)) are enabled. 128 | 129 | #### `syntax.highlightLanguages` 130 | List of enabled languages. 131 | 132 | If you want to disable {Syntax Highlighter} for certain languages and use standard 133 | coloring instead, just remove them from `syntax.highlightLanguages` list in your 134 | `settings.json`. By default all [supported languages]((#languages)) are enabled. 135 | 136 | ## [Build](BUILD.md) 137 | 138 | {Syntax Highlighter} utilizes 139 | [WebAssembly bindings to the Tree-sitter parsing library](https://github.com/tree-sitter/tree-sitter/tree/master/lib/binding_web). 140 | All language parsers are 141 | [compiled to binary .wasm modules](https://github.com/tree-sitter/tree-sitter/tree/master/lib/binding_web#generate-wasm-language-files). 142 | To build .wasm you'll need Emscripten SDK. Refer to [BUILD.md](BUILD.md) for instructions. 143 | 144 | ## [Contribute](CONTRIBUTING.md) 145 | 146 | The best way to contribute is to implement support of new languages. Extension 147 | improvements are also welcome. Refer to [CONTRIBUTE.md](CONTRIBUTE.md) for details. 148 | 149 | ## [ToDo](TODO.md) 150 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "syntax-highlighter", 3 | "displayName": "Syntax Highlighter", 4 | "description": "Syntax highlighting based on Tree-sitter", 5 | "homepage": "https://github.com/EvgeniyPeshkov/syntax-highlighter", 6 | "version": "0.5.1", 7 | "publisher": "evgeniypeshkov", 8 | "license": "MIT", 9 | "icon": "images/syntax.png", 10 | "galleryBanner": { 11 | "color": "#263238", 12 | "theme": "dark" 13 | }, 14 | "repository": { 15 | "url": "https://github.com/EvgeniyPeshkov/syntax-highlighter" 16 | }, 17 | "author": { 18 | "name": "Evgeniy Peshkov", 19 | "email": "peshkov.e@outlook.com" 20 | }, 21 | "categories": [ 22 | "Programming Languages", 23 | "Themes", 24 | "Other" 25 | ], 26 | "keywords": [ 27 | "Syntax", 28 | "Highlighter", 29 | "Highlight", 30 | "Highlighting", 31 | "Coloring", 32 | "Tree-Sitter", 33 | "Parser", 34 | "C", 35 | "C++", 36 | "CPP", 37 | "Python", 38 | "TypeScript", 39 | "TS", 40 | "TypeScriptReact", 41 | "TSX", 42 | "JavaScript", 43 | "JS", 44 | "Go", 45 | "Rust", 46 | "Php", 47 | "Ruby", 48 | "ShellScript", 49 | "Bash", 50 | "OCaml", 51 | "Lua", 52 | "D", 53 | ], 54 | "activationEvents": [ 55 | "onLanguage:c", 56 | "onLanguage:cpp", 57 | "onLanguage:python", 58 | "onLanguage:typescript", 59 | "onLanguage:typescriptreact", 60 | "onLanguage:javascript", 61 | "onLanguage:go", 62 | "onLanguage:rust", 63 | "onLanguage:php", 64 | "onLanguage:ruby", 65 | "onLanguage:shellscript", 66 | "onLanguage:ocaml", 67 | "onLanguage:lua", 68 | "onLanguage:d" 69 | ], 70 | "main": "./out/extension.js", 71 | "scripts": { 72 | "vscode:prepublish": "npm run compile", 73 | "vscode:package": "node ./node_modules/.bin/vsce package", 74 | "compile": "tsc -p ./", 75 | "watch": "tsc -watch -p ./", 76 | "postinstall": "node ./scripts/build.js" 77 | }, 78 | "engines": { 79 | "vscode": "^1.46.0" 80 | }, 81 | "dependencies": { 82 | "jsonc-parser": "^2.2.1", 83 | "web-tree-sitter": "^0.19.1" 84 | }, 85 | "devDependencies": { 86 | "@types/node": "^13.7.2", 87 | "@types/vscode": "^1.46.0", 88 | "ovsx": "0.1.0-next.a9154dc", 89 | "tree-sitter": "^0.19.0", 90 | "tree-sitter-bash": "^0.19.0", 91 | "tree-sitter-c": "^0.19.0", 92 | "tree-sitter-cli": "^0.19.4", 93 | "tree-sitter-cpp": "^0.19.0", 94 | "tree-sitter-d": "github:cybershadow/tree-sitter-d", 95 | "tree-sitter-go": "^0.19.1", 96 | "tree-sitter-javascript": "^0.19.0", 97 | "tree-sitter-lua": "^1.6.2", 98 | "tree-sitter-ocaml": "^0.19.0", 99 | "tree-sitter-php": "^0.19.0", 100 | "tree-sitter-python": "^0.19.0", 101 | "tree-sitter-ruby": "github:tree-sitter/tree-sitter-ruby#v0.19.0", 102 | "tree-sitter-rust": "^0.19.1", 103 | "tree-sitter-typescript": "^0.19.0", 104 | "tslint": "^6.1.2", 105 | "typescript": "^3.9.3", 106 | "vsce": "^1.87.0" 107 | }, 108 | "contributes": { 109 | "semanticTokenTypes": [ 110 | { 111 | "id": "punctuation", 112 | "description": "Punctuation symbols" 113 | } 114 | ], 115 | "semanticTokenScopes": [ 116 | { 117 | "scopes": { 118 | "punctuation": [ 119 | "punctuation" 120 | ], 121 | "type.modification": [ 122 | "storage.modifier" 123 | ] 124 | } 125 | } 126 | ], 127 | "configuration": { 128 | "title": "{Syntax Highlighter} configuration", 129 | "properties": { 130 | "syntax.highlightComment": { 131 | "description": "Enable highlighting of comments", 132 | "type": "boolean", 133 | "default": true 134 | }, 135 | "syntax.highlightLanguages": { 136 | "description": "Enabled languages", 137 | "type": "array", 138 | "default": [ 139 | "c", 140 | "cpp", 141 | "python", 142 | "typescript", 143 | "typescriptreact", 144 | "javascript", 145 | "go", 146 | "rust", 147 | "php", 148 | "ruby", 149 | "shellscript", 150 | "ocaml", 151 | "lua", 152 | "d" 153 | ] 154 | }, 155 | "syntax.highlightTerms": { 156 | "description": "Enabled terms", 157 | "type": "array", 158 | "default": [ 159 | "type", 160 | "scope", 161 | "function", 162 | "variable", 163 | "number", 164 | "string", 165 | "comment", 166 | "constant", 167 | "directive", 168 | "control", 169 | "operator", 170 | "modifier", 171 | "punctuation" 172 | ] 173 | }, 174 | "syntax.debugHover": { 175 | "description": "Show tool-tip with syntax scope on hover", 176 | "type": "boolean", 177 | "default": false 178 | }, 179 | "syntax.debugDepth": { 180 | "description": "Depth of syntax scope in debug tools", 181 | "type": "integer", 182 | "default": -1 183 | } 184 | } 185 | } 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /grammars/rust.json: -------------------------------------------------------------------------------- 1 | { 2 | "simpleTerms": { 3 | 4 | "primitive_type": "type", 5 | 6 | "inner_attribute_item": "variable", 7 | "shorthand_field_identifier": "variable", 8 | "\"_\"": "variable", 9 | 10 | "boolean_literal": "number", 11 | "integer_literal": "number", 12 | "float_literal": "number", 13 | "char_literal": "string", 14 | "string_literal": "string", 15 | "raw_string_literal": "string", 16 | "escape_sequence": "string", 17 | "line_comment": "comment", 18 | "block_comment": "comment", 19 | 20 | "\"let\"": "modifier", 21 | "\"const\"": "modifier", 22 | "\"static\"": "modifier", 23 | "\"extern\"": "modifier", 24 | "\"dyn\"": "modifier", 25 | "\"trait\"": "modifier", 26 | "\"mod\"": "modifier", 27 | "\"pub\"": "modifier", 28 | "\"default\"": "modifier", 29 | "\"ref\"": "modifier", 30 | "mutable_specifier": "modifier", 31 | 32 | "\"fn\"": "control", 33 | "\"type\"": "control", 34 | "\"struct\"": "control", 35 | "\"enum\"": "control", 36 | "\"union\"": "control", 37 | "\"impl\"": "control", 38 | 39 | "\"unsafe\"": "control", 40 | "\"match\"": "control", 41 | "\"if\"": "control", 42 | "\"in\"": "control", 43 | "\"else\"": "control", 44 | "\"move\"": "control", 45 | "\"while\"": "control", 46 | "\"loop\"": "control", 47 | "\"for\"": "control", 48 | "\"return\"": "control", 49 | "\"continue\"": "control", 50 | "\"break\"": "control", 51 | "\"where\"": "control", 52 | "\"macro_rules!\"": "control", 53 | 54 | "self": "control", 55 | "super": "control", 56 | "crate": "control", 57 | 58 | "\".\"": "operator", 59 | "\"->\"": "operator", 60 | "\"=>\"": "operator", 61 | "\"-\"": "operator", 62 | "\"+\"": "operator", 63 | "\"/\"": "operator", 64 | "\"%\"": "operator", 65 | "\"++\"": "operator", 66 | "\"--\"": "operator", 67 | "\"==\"": "operator", 68 | "\"!\"": "operator", 69 | "\"!=\"": "operator", 70 | "\"<\"": "operator", 71 | "\">\"": "operator", 72 | "\">=\"": "operator", 73 | "\"<=\"": "operator", 74 | "\"&&\"": "operator", 75 | "\"||\"": "operator", 76 | "\"&\"": "operator", 77 | "\"|\"": "operator", 78 | "\"^\"": "operator", 79 | "\"~\"": "operator", 80 | "\"<<\"": "operator", 81 | "\">>\"": "operator", 82 | "\"=\"": "operator", 83 | "\"+=\"": "operator", 84 | "\"-=\"": "operator", 85 | "\"*=\"": "operator", 86 | "\"/=\"": "operator", 87 | "\"%=\"": "operator", 88 | "\"<<=\"": "operator", 89 | "\">>=\"": "operator", 90 | "\"&=\"": "operator", 91 | "\"^=\"": "operator", 92 | "\"|=\"": "operator", 93 | "\"?\"": "operator", 94 | "\"::\"": "operator", 95 | "\"..\"": "operator", 96 | "\"as\"": "operator", 97 | 98 | "\"use\"": "directive", 99 | "\"#\"": "directive", 100 | 101 | "\";\"": "punctuation", 102 | "\":\"": "punctuation", 103 | "\",\"": "punctuation", 104 | "\"{\"": "punctuation", 105 | "\"}\"": "punctuation" 106 | }, 107 | 108 | "complexTerms": [ 109 | "identifier", "field_identifier", "type_identifier", 110 | "\"(\"", "\")\"", "\"[\"", "\"]\"", "\"*\""], 111 | 112 | "complexScopes": { 113 | "type_identifier": "type", 114 | "scoped_type_identifier > type_identifier": "type", 115 | "use_declaration > identifier": "type", 116 | "use_declaration > scoped_identifier > identifier[-1]": "type", 117 | "use_list > identifier": "type", 118 | "use_list > scoped_identifier > identifier": "type", 119 | "use_wildcard > \"*\"": "type", 120 | "use_as_clause > identifier": "type", 121 | "tuple_struct_pattern > identifier": "type", 122 | "tuple_struct_pattern > scoped_identifier > identifier[-1]": "type", 123 | "enum_variant > identifier": "type", 124 | "match_pattern > scoped_identifier > identifier[-1]": "type", 125 | "unit_type > \"(\"": "type", 126 | "unit_type > \")\"": "type", 127 | 128 | "scoped_identifier > identifier": "scope", 129 | "scoped_type_identifier > identifier": "scope", 130 | "scoped_type_identifier > scoped_identifier > identifier": "scope", 131 | "scoped_identifier > scoped_identifier > identifier": "scope", 132 | "scoped_use_list > scoped_identifier > identifier": "scope", 133 | "scoped_use_list > identifier": "scope", 134 | "use_wildcard > scoped_identifier > identifier": "scope", 135 | "use_wildcard > identifier": "scope", 136 | "struct_pattern > scoped_type_identifier > identifier": "scope", 137 | "struct_expression > scoped_type_identifier > identifier": "scope", 138 | 139 | "identifier": "variable", 140 | "field_identifier": "variable", 141 | "scoped_identifier > identifier[-1]": "variable", 142 | 143 | "call_expression > identifier": "function", 144 | "call_expression > field_expression > field_identifier[-1]": "function", 145 | "call_expression > scoped_identifier > identifier[-1]": "function", 146 | "macro_invocation > identifier": "function", 147 | "macro_definition > identifier": "function", 148 | "generic_function > identifier": "function", 149 | "generic_function > field_expression > field_identifier": "function", 150 | "generic_function > scoped_identifier > identifier": "function", 151 | "function_item > identifier": "function", 152 | "function_signature_item > identifier": "function", 153 | 154 | "lifetime > identifier": "modifier", 155 | 156 | "meta_item > identifier": "directive", 157 | 158 | "\"*\"": "operator", 159 | "\"(\"": "punctuation", 160 | "\")\"": "punctuation", 161 | "\"[\"": "punctuation", 162 | "\"]\"": "punctuation", 163 | "unit_expression > \"(\"": "constant", 164 | "unit_expression > \")\"": "constant", 165 | "attribute_item > \"[\"": "directive", 166 | "attribute_item > \"]\"": "directive" 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /src/extension.ts: -------------------------------------------------------------------------------- 1 | import * as vscode from 'vscode'; 2 | import * as parser from 'web-tree-sitter'; 3 | import * as jsonc from 'jsonc-parser'; 4 | import * as fs from 'fs'; 5 | import * as path from 'path'; 6 | 7 | // Grammar class 8 | const parserPromise = parser.init(); 9 | class Grammar { 10 | // Parser 11 | readonly lang: string; 12 | parser: parser; 13 | // Grammar 14 | readonly simpleTerms: { [sym: string]: string } = {}; 15 | readonly complexTerms: string[] = []; 16 | readonly complexScopes: { [sym: string]: string } = {}; 17 | readonly complexDepth: number = 0; 18 | readonly complexOrder: boolean = false; 19 | 20 | // Constructor 21 | constructor(lang: string) { 22 | // Parse grammar file 23 | this.lang = lang; 24 | const grammarFile = __dirname + "/../grammars/" + lang + ".json"; 25 | const grammarJson = jsonc.parse(fs.readFileSync(grammarFile).toString()); 26 | for (const t in grammarJson.simpleTerms) 27 | this.simpleTerms[t] = grammarJson.simpleTerms[t]; 28 | for (const t in grammarJson.complexTerms) 29 | this.complexTerms[t] = grammarJson.complexTerms[t]; 30 | for (const t in grammarJson.complexScopes) 31 | this.complexScopes[t] = grammarJson.complexScopes[t]; 32 | for (const s in this.complexScopes) { 33 | const depth = s.split(">").length; 34 | if (depth > this.complexDepth) 35 | this.complexDepth = depth; 36 | if (s.indexOf("[") >= 0) 37 | this.complexOrder = true; 38 | } 39 | this.complexDepth--; 40 | } 41 | 42 | // Parser initialization 43 | async init() { 44 | // Load wasm parser 45 | await parserPromise; 46 | this.parser = new parser(); 47 | let langFile = path.join(__dirname, "../parsers", this.lang + ".wasm"); 48 | const langObj = await parser.Language.load(langFile); 49 | this.parser.setLanguage(langObj); 50 | } 51 | 52 | // Build syntax tree 53 | tree(doc: string) { 54 | return this.parser.parse(doc); 55 | } 56 | 57 | // Parse syntax tree 58 | parse(tree: parser.Tree) { 59 | // Travel tree and peek terms 60 | let terms: { term: string; range: vscode.Range }[] = []; 61 | let stack: parser.SyntaxNode[] = []; 62 | let node = tree.rootNode.firstChild; 63 | while (stack.length > 0 || node) { 64 | // Go deeper 65 | if (node) { 66 | stack.push(node); 67 | node = node.firstChild; 68 | } 69 | // Go back 70 | else { 71 | node = stack.pop(); 72 | let type = node.type; 73 | if (!node.isNamed()) 74 | type = '"' + type + '"'; 75 | 76 | // Simple one-level terms 77 | let term: string | undefined = undefined; 78 | if (!this.complexTerms.includes(type)) { 79 | term = this.simpleTerms[type]; 80 | } 81 | // Complex terms require multi-level analyzes 82 | else { 83 | // Build complex scopes 84 | let desc = type; 85 | let scopes = [desc]; 86 | let parent = node.parent; 87 | for (let i = 0; i < this.complexDepth && parent; i++) { 88 | let parentType = parent.type; 89 | if (!parent.isNamed()) 90 | parentType = '"' + parentType + '"'; 91 | desc = parentType + " > " + desc; 92 | scopes.push(desc); 93 | parent = parent.parent; 94 | } 95 | // If there is also order complexity 96 | if (this.complexOrder) 97 | { 98 | let index = 0; 99 | let sibling = node.previousSibling; 100 | while (sibling) { 101 | if (sibling.type === node.type) 102 | index++; 103 | sibling = sibling.previousSibling; 104 | } 105 | 106 | let rindex = -1; 107 | sibling = node.nextSibling; 108 | while (sibling) { 109 | if (sibling.type === node.type) 110 | rindex--; 111 | sibling = sibling.nextSibling; 112 | } 113 | 114 | let orderScopes: string[] = []; 115 | for (let i = 0; i < scopes.length; i++) 116 | orderScopes.push(scopes[i], scopes[i] + "[" + index + "]", 117 | scopes[i] + "[" + rindex + "]"); 118 | scopes = orderScopes; 119 | } 120 | // Use most complex scope 121 | for (const d of scopes) 122 | if (d in this.complexScopes) 123 | term = this.complexScopes[d]; 124 | } 125 | 126 | // If term is found add it 127 | if (term) { 128 | terms.push({ 129 | term: term, 130 | range: new vscode.Range( 131 | new vscode.Position( 132 | node.startPosition.row, 133 | node.startPosition.column), 134 | new vscode.Position( 135 | node.endPosition.row, 136 | node.endPosition.column)) 137 | }); 138 | } 139 | // Go right 140 | node = node.nextSibling 141 | } 142 | } 143 | return terms; 144 | } 145 | } 146 | 147 | // Semantic token legend 148 | const termMap = new Map(); 149 | function buildLegend() { 150 | // Terms vocabulary 151 | termMap.set("type", { type: "type" }); 152 | termMap.set("scope", { type: "namespace" }); 153 | termMap.set("function", { type: "function" }); 154 | termMap.set("variable", { type: "variable" }); 155 | termMap.set("number", { type: "number" }); 156 | termMap.set("string", { type: "string" }); 157 | termMap.set("comment", { type: "comment" }); 158 | termMap.set("constant", { type: "variable", modifiers: ["readonly", "defaultLibrary"] }); 159 | termMap.set("directive", { type: "macro" }); 160 | termMap.set("control", { type: "keyword" }); 161 | termMap.set("operator", { type: "operator" }); 162 | termMap.set("modifier", { type: "type", modifiers: ["modification"] }); 163 | termMap.set("punctuation", { type: "punctuation" }); 164 | // Tokens and modifiers in use 165 | let tokens: string[] = []; 166 | let modifiers: string[] = []; 167 | termMap.forEach(t => { 168 | if (!tokens.includes(t.type)) 169 | tokens.push(t.type); 170 | t.modifiers?.forEach(m => { 171 | if (!modifiers.includes(m)) 172 | modifiers.push(m); 173 | }); 174 | }); 175 | // Construct semantic token legend 176 | return new vscode.SemanticTokensLegend(tokens, modifiers); 177 | } 178 | const legend = buildLegend(); 179 | 180 | // Semantic token provider 181 | class TokensProvider implements vscode.DocumentSemanticTokensProvider, vscode.HoverProvider { 182 | readonly grammars: { [lang: string]: Grammar } = {}; 183 | readonly trees: { [doc: string]: parser.Tree } = {}; 184 | readonly supportedTerms: string[] = []; 185 | readonly debugDepth: number; 186 | 187 | constructor() { 188 | // Terms 189 | const availableTerms: string[] = [ 190 | "type", "scope", "function", "variable", "number", "string", "comment", 191 | "constant", "directive", "control", "operator", "modifier", "punctuation", 192 | ]; 193 | const enabledTerms: string[] = vscode.workspace. 194 | getConfiguration("syntax").get("highlightTerms"); 195 | availableTerms.forEach(term => { 196 | if (enabledTerms.includes(term)) 197 | this.supportedTerms.push(term); 198 | }); 199 | if (!vscode.workspace.getConfiguration("syntax").get("highlightComment")) 200 | if (this.supportedTerms.includes("comment")) 201 | this.supportedTerms.splice(this.supportedTerms.indexOf("comment"), 1); 202 | this.debugDepth = vscode.workspace.getConfiguration("syntax").get("debugDepth"); 203 | } 204 | 205 | // Provide document tokens 206 | async provideDocumentSemanticTokens( 207 | doc: vscode.TextDocument, 208 | token: vscode.CancellationToken): Promise 209 | { 210 | // Grammar 211 | const lang = doc.languageId; 212 | if (!(lang in this.grammars)) { 213 | this.grammars[lang] = new Grammar(lang); 214 | await this.grammars[lang].init(); 215 | } 216 | // Parse document 217 | const grammar = this.grammars[lang]; 218 | const tree = grammar.tree(doc.getText()); 219 | const terms = grammar.parse(tree); 220 | this.trees[doc.uri.toString()] = tree; 221 | // Build tokens 222 | const builder = new vscode.SemanticTokensBuilder(legend); 223 | terms.forEach((t) => { 224 | if (!this.supportedTerms.includes(t.term)) 225 | return; 226 | const type = termMap.get(t.term).type; 227 | const modifiers = termMap.get(t.term).modifiers; 228 | if (t.range.start.line === t.range.end.line) 229 | return builder.push(t.range, type, modifiers); 230 | let line = t.range.start.line; 231 | builder.push(new vscode.Range(t.range.start, 232 | doc.lineAt(line).range.end), type, modifiers); 233 | for (line = line + 1; line < t.range.end.line; line++) 234 | builder.push(doc.lineAt(line).range, type, modifiers); 235 | builder.push(new vscode.Range(doc.lineAt(line).range.start, 236 | t.range.end), type, modifiers); 237 | }); 238 | return builder.build(); 239 | } 240 | 241 | // Provide hover tooltips 242 | async provideHover( 243 | doc: vscode.TextDocument, 244 | pos: vscode.Position, 245 | token: vscode.CancellationToken): Promise 246 | { 247 | const uri = doc.uri.toString(); 248 | if (!(uri in this.trees)) 249 | return null; 250 | const grammar = this.grammars[doc.languageId]; 251 | const tree = this.trees[uri]; 252 | 253 | const xy: parser.Point = { row: pos.line, column: pos.character }; 254 | let node = tree.rootNode.descendantForPosition(xy); 255 | if (!node) 256 | return null; 257 | 258 | let type = node.type; 259 | if (!node.isNamed()) 260 | type = '"' + type + '"'; 261 | let parent = node.parent; 262 | 263 | const depth = Math.max(grammar.complexDepth, this.debugDepth); 264 | for (let i = 0; i < depth && parent; i++) { 265 | let parentType = parent.type; 266 | if (!parent.isNamed()) 267 | parentType = '"' + parentType + '"'; 268 | type = parentType + " > " + type; 269 | parent = parent.parent; 270 | } 271 | 272 | // If there is also order complexity 273 | if (grammar.complexOrder) 274 | { 275 | let index = 0; 276 | let sibling = node.previousSibling; 277 | while (sibling) { 278 | if (sibling.type === node.type) 279 | index++; 280 | sibling = sibling.previousSibling; 281 | } 282 | 283 | let rindex = -1; 284 | sibling = node.nextSibling; 285 | while (sibling) { 286 | if (sibling.type === node.type) 287 | rindex--; 288 | sibling = sibling.nextSibling; 289 | } 290 | 291 | type = type + "[" + index + "]" + "[" + rindex + "]"; 292 | } 293 | 294 | return { 295 | contents: [type], 296 | range: new vscode.Range( 297 | node.startPosition.row, node.startPosition.column, 298 | node.endPosition.row, node.endPosition.column) 299 | }; 300 | } 301 | } 302 | 303 | // Extension activation 304 | export async function activate(context: vscode.ExtensionContext) { 305 | 306 | // Languages 307 | let availableGrammars: string[] = []; 308 | fs.readdirSync(__dirname + "/../grammars/").forEach(name => { 309 | availableGrammars.push(path.basename(name, ".json")); 310 | }); 311 | 312 | let availableParsers: string[] = []; 313 | fs.readdirSync(__dirname + "/../parsers/").forEach(name => { 314 | availableParsers.push(path.basename(name, ".wasm")); 315 | }); 316 | 317 | const enabledLangs: string[] = 318 | vscode.workspace.getConfiguration("syntax").get("highlightLanguages"); 319 | let supportedLangs: { language: string }[] = []; 320 | availableGrammars.forEach(lang => { 321 | if (availableParsers.includes(lang) && enabledLangs.includes(lang)) 322 | supportedLangs.push({language: lang}); 323 | }); 324 | 325 | const engine = new TokensProvider(); 326 | context.subscriptions.push( 327 | vscode.languages.registerDocumentSemanticTokensProvider( 328 | supportedLangs, engine, legend)); 329 | 330 | // Register debug hover providers 331 | // Very useful tool for implementation and fixing of grammars 332 | if (vscode.workspace.getConfiguration("syntax").get("debugHover")) 333 | for (const lang of supportedLangs) 334 | vscode.languages.registerHoverProvider(lang, engine); 335 | } 336 | --------------------------------------------------------------------------------