vscode-textmate | A library that helps tokenize text using Text Mate grammars | Code Quality library
kandi X-RAY | vscode-textmate Summary
kandi X-RAY | vscode-textmate Summary
An interpreter for grammar files as defined by TextMate. TextMate grammars use the oniguruma dialect (Supports loading grammar files from JSON or PLIST format. This library is used in VS Code. Cross - grammar injections are currently not supported.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Loads the grammar .
- Tokenizes a file .
- Run test test .
- Tokenize a rule .
vscode-textmate Key Features
vscode-textmate Examples and Code Snippets
Community Discussions
Trending Discussions on vscode-textmate
QUESTION
I'm trying to syntax-highlight code snippets on my library website. I've tried Highlight.js and Prism, but neither of them tokenize the code correctly (it's Ruby), so in the end the code is not syntax-highlighted properly. This is because they both implement their own tokenization regexes, which is an approach that's bound to have flaws.
I've then discovered that GitHub, Atom and VSCode all use TextMate grammars for their tokenization. This to me sounds like the right approach, to have language grammars maintained in a single place, so that other tools can then reuse them instead of each defining their own.
My question is: how to tokenize a code string using a TextMate grammar in Node? My goal is to have something like:
...ANSWER
Answered 2019-Oct-19 at 12:04After posting my comment I gave it another try and was sucessful this time around. The following example shows how to use vscode-textmate
with the official TypeScript.tmLanguage
but the basics should be applicable to other languages.
- First make sure you have Python 2.7 (not 3.X) installed on your machine and on Windows in your PATH variable.
- Install
vscode-textmate
using npm or yarn which will invoke the required Python interpreter during installation. - Grab your XML grammar (usually ending in
.tmLanguage
) and place it in the project root. - Use the
vscode-textmate
plugin as follows:
QUESTION
I'm interested in creating a code editor app for Android in C# (using Xamarin). Obviously, one of the necessities for any great code editor is syntax highlighting for a wide range of popular languages. I don't want to write custom tokenizers for all of these languages myself, so I'm looking for a library that already has grammars for them.
From my time browsing the VSCode editor source code, I know that there are many predefined grammar files for certain languages, in .tmLanguage
(TextMate-style) or .cson
(Atom-style) format. For example, here are a bunch of grammars maintained by Atom, and here is the official C# grammar maintained by the .NET Foundation.
I initially sought a .NET library that would parse these files and allow me to match them against expressions, but AFAICS none exists. Something like vscode-textmate or textpow would be just what I'm looking for, but those are not written in .NET.
Can anyone point me to a library that would help me with this purpose? Also, would it be a good idea to use a .NET JavaScript engine to execute functions from the above libraries if I can't find any? Normally I wouldn't hesitate to use an engine, but I'm afraid delays of a few hundred ms would not be acceptable for syntax highlighting.
...ANSWER
Answered 2017-Jun-10 at 23:31For one of my current projects I did a research of available syntax parsers. One of them was ANTLR, and here is an article on how to use it from C#: https://tomassetti.me/getting-started-with-antlr-in-csharp/
It has a very large (over 100) collection of pre-build grammars for different languages: https://github.com/antlr/grammars-v4
ANTLR is Java based, so I guess it will not be an issue to get it working on Android.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install vscode-textmate
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page