Gathering detailed insights and metrics for vscode-textmate
Gathering detailed insights and metrics for vscode-textmate
Gathering detailed insights and metrics for vscode-textmate
Gathering detailed insights and metrics for vscode-textmate
A library that helps tokenize text using Text Mate grammars.
npm install vscode-textmate
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
585 Stars
468 Commits
116 Forks
55 Watching
4 Branches
67 Contributors
Updated on 25 Nov 2024
Minified
Minified + Gzipped
TypeScript (83.52%)
JavaScript (2.33%)
SCSS (2.25%)
Groovy (1.47%)
CSS (1.22%)
HTML (0.94%)
Python (0.79%)
Perl (0.72%)
Ruby (0.64%)
PowerShell (0.53%)
Objective-C (0.52%)
Go (0.46%)
Clojure (0.45%)
Handlebars (0.4%)
Less (0.38%)
C++ (0.37%)
Visual Basic .NET (0.33%)
C (0.31%)
PHP (0.3%)
F# (0.24%)
Shell (0.24%)
CoffeeScript (0.22%)
Java (0.21%)
Makefile (0.21%)
Rust (0.2%)
Batchfile (0.18%)
Dockerfile (0.16%)
R (0.14%)
ShaderLab (0.12%)
Lua (0.09%)
Swift (0.08%)
Pug (0.01%)
Cumulative downloads
Total Downloads
Last day
10.1%
275,788
Compared to previous day
Last week
6.3%
1,571,857
Compared to previous week
Last month
36.2%
5,786,834
Compared to previous month
Last year
20.5%
59,322,489
Compared to previous year
An interpreter for grammar files as defined by TextMate. TextMate grammars use the oniguruma dialect (https://github.com/kkos/oniguruma). Supports loading grammar files from JSON or PLIST format. This library is used in VS Code. Cross - grammar injections are currently not supported.
1npm install vscode-textmate
1const fs = require('fs'); 2const path = require('path'); 3const vsctm = require('vscode-textmate'); 4const oniguruma = require('vscode-oniguruma'); 5 6/** 7 * Utility to read a file as a promise 8 */ 9function readFile(path) { 10 return new Promise((resolve, reject) => { 11 fs.readFile(path, (error, data) => error ? reject(error) : resolve(data)); 12 }) 13} 14 15const wasmBin = fs.readFileSync(path.join(__dirname, './node_modules/vscode-oniguruma/release/onig.wasm')).buffer; 16const vscodeOnigurumaLib = oniguruma.loadWASM(wasmBin).then(() => { 17 return { 18 createOnigScanner(patterns) { return new oniguruma.OnigScanner(patterns); }, 19 createOnigString(s) { return new oniguruma.OnigString(s); } 20 }; 21}); 22 23// Create a registry that can create a grammar from a scope name. 24const registry = new vsctm.Registry({ 25 onigLib: vscodeOnigurumaLib, 26 loadGrammar: (scopeName) => { 27 if (scopeName === 'source.js') { 28 // https://github.com/textmate/javascript.tmbundle/blob/master/Syntaxes/JavaScript.plist 29 return readFile('./JavaScript.plist').then(data => vsctm.parseRawGrammar(data.toString())) 30 } 31 console.log(`Unknown scope name: ${scopeName}`); 32 return null; 33 } 34}); 35 36// Load the JavaScript grammar and any other grammars included by it async. 37registry.loadGrammar('source.js').then(grammar => { 38 const text = [ 39 `function sayHello(name) {`, 40 `\treturn "Hello, " + name;`, 41 `}` 42 ]; 43 let ruleStack = vsctm.INITIAL; 44 for (let i = 0; i < text.length; i++) { 45 const line = text[i]; 46 const lineTokens = grammar.tokenizeLine(line, ruleStack); 47 console.log(`\nTokenizing line: ${line}`); 48 for (let j = 0; j < lineTokens.tokens.length; j++) { 49 const token = lineTokens.tokens[j]; 50 console.log(` - token from ${token.startIndex} to ${token.endIndex} ` + 51 `(${line.substring(token.startIndex, token.endIndex)}) ` + 52 `with scopes ${token.scopes.join(', ')}` 53 ); 54 } 55 ruleStack = lineTokens.ruleStack; 56 } 57}); 58 59/* OUTPUT: 60 61Unknown scope name: source.js.regexp 62 63Tokenizing line: function sayHello(name) { 64 - token from 0 to 8 (function) with scopes source.js, meta.function.js, storage.type.function.js 65 - token from 8 to 9 ( ) with scopes source.js, meta.function.js 66 - token from 9 to 17 (sayHello) with scopes source.js, meta.function.js, entity.name.function.js 67 - token from 17 to 18 (() with scopes source.js, meta.function.js, punctuation.definition.parameters.begin.js 68 - token from 18 to 22 (name) with scopes source.js, meta.function.js, variable.parameter.function.js 69 - token from 22 to 23 ()) with scopes source.js, meta.function.js, punctuation.definition.parameters.end.js 70 - token from 23 to 24 ( ) with scopes source.js 71 - token from 24 to 25 ({) with scopes source.js, punctuation.section.scope.begin.js 72 73Tokenizing line: return "Hello, " + name; 74 - token from 0 to 1 ( ) with scopes source.js 75 - token from 1 to 7 (return) with scopes source.js, keyword.control.js 76 - token from 7 to 8 ( ) with scopes source.js 77 - token from 8 to 9 (") with scopes source.js, string.quoted.double.js, punctuation.definition.string.begin.js 78 - token from 9 to 16 (Hello, ) with scopes source.js, string.quoted.double.js 79 - token from 16 to 17 (") with scopes source.js, string.quoted.double.js, punctuation.definition.string.end.js 80 - token from 17 to 18 ( ) with scopes source.js 81 - token from 18 to 19 (+) with scopes source.js, keyword.operator.arithmetic.js 82 - token from 19 to 20 ( ) with scopes source.js 83 - token from 20 to 24 (name) with scopes source.js, support.constant.dom.js 84 - token from 24 to 25 (;) with scopes source.js, punctuation.terminator.statement.js 85 86Tokenizing line: } 87 - token from 0 to 1 (}) with scopes source.js, punctuation.section.scope.end.js 88 89*/ 90
See vscode-tmgrammar-test that can help you write unit tests against your grammar.
See the main.ts file
npm install
npm run watch
npm test
npm run benchmark
npm run inspect -- PATH_TO_GRAMMAR PATH_TO_FILE
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
No vulnerabilities found.
Reason
all last 30 commits are reviewed through GitHub
Reason
no vulnerabilities detected
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
no binaries found in the repo
Reason
update tool detected
Details
Reason
branch protection is not maximal on development and all release branches
Details
Reason
dependency not pinned by hash detected -- score normalized to 5
Details
Reason
4 commit(s) out of 30 and 0 issue activity out of 30 found in the last 90 days -- score normalized to 3
Reason
no badge detected
Reason
non read-only tokens detected in GitHub workflows
Details
Reason
project is not fuzzed
Score
Last Scanned on 2022-08-15
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More