The aim of this project is to design and implement a scalable converter from Rascal grammars to TextMate grammars. TextMate grammars generated in this way are intended to be included in VS Code extensions to provide syntax highlighting (complementary to Rascal's existing support for semantic highlighting).
In general, there are two possible approaches:
- total conversion: produce equivalent TextMate rules for all Rascal non-terminals;
- partial conversion: produce equivalent TextMate rules for some Rascal
non-terminals "of interest" (e.g., those with a
@category
tag).
Due to the significant differences in expressiveness of Rascal grammars and TextMate grammars, this project applies partial conversion. Alternatively, a previous project by @TarVK applies total conversion.
Enter the following commands in a terminal:
git clone https://github.com/SWAT-engineering/rascal-textmate.git
cd rascal-textmate/rascal-textmate-core
mvn install -Drascal.compile.skip -Drascal.tutor.skip -DskipTests
cd ../..
rm -rf rascal-textmate
-
Add the following dependency in
pom.xml
of the project:<dependency> <groupId>org.rascalmpl</groupId> <artifactId>rascal-textmate-core</artifactId> <version>0.1.0-SNAPSHOT</version> </dependency>
-
Add
|lib://rascal-textmate-core|
toRequire-Libraries
inMETA-INF/RASCAL.MF
of the project. -
Open a REPL in a grammar module of the project, import module
lang::textmate::main::Main
in the REPL, and run functionmain
on thestart
symbol of the grammar. For instance:main(#Foo, "source.foo", |home:///Desktop/foo.json|)
The generated TextMate grammar (as a JSON file) can now be integrated in a VS Code extension as explained here.
The walkthrough explains the main ideas behind the conversion algorithm.
To test tokenization (as part of the conversion
tests),
the vscode-tmgrammar-test
tool is used. Install it locally in directory rascal-textmate-core
as follows:
npm install vscode-tmgrammar-test