vscode-textmate
VSCode TextMate grammar helpers
Last updated 8 years ago by aeschli .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install vscode-textmate 
SYNC missed versions from official npm registry.

VSCode TextMate Build Status Coverage Status

An interpreter for grammar files as defined by TextMate. Supports loading grammar files from JSON or PLIST format. Cross - grammar injections are currently not supported.

Installing

npm install vscode-textmate

Using

var vsctm = require('vscode-textmate');
var grammarPaths = {
	'source.js': './javascript.tmbundle/Syntaxes/JavaScript.plist'
};

var registry = new vsctm.Registry({
	loadGrammar: function (scopeName) {
		var path = grammarPaths[scopeName];
		if (path) {
			return new Promise((c,e) => {
				fs.readFile(path, (error, content) => {
					if (error) {
						e(error);
					} else {
						var rawGrammar = vsctm.parseRawGrammar(content.toString(), path);
						c(rawGrammar);
					}
				});
			});
		}
		return null;
	}
});

// Load the JavaScript grammar and any other grammars included by it async.
registry.loadGrammar('source.js').then(grammar => {
	// at this point `grammar` is available...
	var lineTokens = grammar.tokenizeLine('function add(a,b) { return a+b; }');
	for (var i = 0; i < lineTokens.tokens.length; i++) {
		var token = lineTokens.tokens[i];
		console.log('Token from ' + token.startIndex + ' to ' + token.endIndex + ' with scopes ' + token.scopes);
	}
});

Tokenizing multiple lines

To tokenize multiple lines, you must pass in the previous returned ruleStack.

var ruleStack = null;
for (var i = 0; i < lines.length; i++) {
	var r = grammar.tokenizeLine(lines[i], ruleStack);
	console.log('Line: #' + i + ', tokens: ' + r.tokens);
	ruleStack = r.ruleStack;
}

API doc

See the main.ts file

Developing

  • Clone the repository
  • Run npm install
  • Compile in the background with npm run watch
  • Run tests with npm test
  • Run benchmark with npm run benchmark
  • Troubleshoot a grammar with npm run inspect -- PATH_TO_GRAMMAR PATH_TO_FILE

Code of Conduct

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.

License

MIT

Current Tags

  • 9.3.2                                ...           latest (10 months ago)
  • 4.0.0-next.3                                ...           next (8 years ago)

77 Versions

  • 9.3.2                                ...           10 months ago
  • 9.3.1                                ...           a year ago
  • 9.3.0                                ...           a year ago
  • 9.2.1                                ...           a year ago
  • 9.2.0                                ...           2 years ago
  • 9.1.0                                ...           2 years ago
  • 9.0.0                                ...           4 years ago
  • 8.0.0                                ...           4 years ago
  • 7.0.4                                ...           4 years ago
  • 7.0.3                                ...           4 years ago
  • 7.0.2                                ...           4 years ago
  • 7.0.1                                ...           5 years ago
  • 7.0.0                                ...           5 years ago
  • 6.0.0                                ...           5 years ago
  • 5.5.0                                ...           5 years ago
  • 5.4.1                                ...           5 years ago
  • 5.4.0                                ...           6 years ago
  • 5.3.1                                ...           6 years ago
  • 5.3.0                                ...           6 years ago
  • 5.2.0                                ...           6 years ago
  • 5.1.2                                ...           6 years ago
  • 5.1.1                                ...           7 years ago
  • 5.1.0                                ...           7 years ago
  • 5.0.2                                ...           7 years ago
  • 5.0.1                                ...           7 years ago
  • 5.0.0                                ...           7 years ago
  • 4.4.0                                ...           7 years ago
  • 4.3.0                                ...           7 years ago
  • 4.2.2                                ...           7 years ago
  • 4.2.1                                ...           7 years ago
  • 4.2.0                                ...           7 years ago
  • 4.1.1                                ...           8 years ago
  • 4.1.0                                ...           8 years ago
  • 4.0.1                                ...           8 years ago
  • 4.0.0                                ...           8 years ago
  • 4.0.0-next.3                                ...           8 years ago
  • 4.0.0-next.2                                ...           8 years ago
  • 4.0.0-next.1                                ...           8 years ago
  • 3.3.3                                ...           9 years ago
  • 3.3.2                                ...           9 years ago
  • 3.3.1                                ...           9 years ago
  • 3.3.0                                ...           9 years ago
  • 3.2.0                                ...           9 years ago
  • 3.1.5                                ...           10 years ago
  • 3.1.4                                ...           10 years ago
  • 3.1.3                                ...           10 years ago
  • 3.1.2                                ...           10 years ago
  • 3.1.1                                ...           10 years ago
  • 3.1.0                                ...           10 years ago
  • 3.0.1                                ...           10 years ago
  • 3.0.0                                ...           10 years ago
  • 2.3.2                                ...           10 years ago
  • 2.3.1                                ...           10 years ago
  • 2.3.0                                ...           10 years ago
  • 2.2.0                                ...           10 years ago
  • 2.1.1                                ...           10 years ago
  • 2.1.0                                ...           10 years ago
  • 2.0.1                                ...           10 years ago
  • 2.0.0                                ...           10 years ago
  • 1.2.0                                ...           10 years ago
  • 1.1.0                                ...           11 years ago
  • 1.0.11                                ...           11 years ago
  • 1.0.10                                ...           11 years ago
  • 1.0.9                                ...           11 years ago
  • 1.0.8                                ...           11 years ago
  • 1.0.7                                ...           11 years ago
  • 1.0.6                                ...           11 years ago
  • 1.0.5                                ...           11 years ago
  • 1.0.4                                ...           11 years ago
  • 1.0.3                                ...           11 years ago
  • 1.0.2                                ...           11 years ago
  • 1.0.1                                ...           11 years ago
  • 1.0.0                                ...           11 years ago
  • 0.0.4                                ...           11 years ago
  • 0.0.3                                ...           11 years ago
  • 0.0.2                                ...           11 years ago
  • 0.0.1                                ...           11 years ago
Downloads
Total 313
Today 0
This Week 11
This Month 150
Last Day 2
Last Week 21
Last Month 114
Dependencies (2)
Dev Dependencies (11)

© 2010 - cnpmjs.org x YWFE | Home | YWFE