Skip to content

Commit 3d0c94c

Browse files
authored
Merge pull request #24 from SWAT-engineering/update-readme
Update README
2 parents 69bd92c + 7aaa581 commit 3d0c94c

File tree

7 files changed

+87
-25
lines changed

7 files changed

+87
-25
lines changed

README.md

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# rascal-textmate
22

3+
## Background
4+
35
The aim of this project is to design and implement a scalable converter from
46
Rascal grammars to TextMate grammars. TextMate grammars generated in this way
57
are intended to be included in VS Code extensions to provide syntax highlighting
@@ -16,12 +18,56 @@ TextMate grammars, this project applies partial conversion. Alternatively, a
1618
previous [project](https://github.com/TarVK/syntax-highlighter) by
1719
[@TarVK](https://github.com/TarVK) applies total conversion.
1820

19-
## Documentation
21+
## Usage
22+
23+
### Installing `rascal-textmate`
24+
25+
Enter the following commands in a terminal:
26+
27+
```shell
28+
git clone https://github.com/SWAT-engineering/rascal-textmate.git
29+
cd rascal-textmate/rascal-textmate-core
30+
mvn install -Drascal.compile.skip -Drascal.tutor.skip -DskipTests
31+
cd ../..
32+
rm -rf rascal-textmate
33+
```
34+
35+
### Running `rascal-textmate` in an existing Rascal project
36+
37+
1. Add the following dependency in `pom.xml` of the project:
38+
39+
```xml
40+
<dependency>
41+
<groupId>org.rascalmpl</groupId>
42+
<artifactId>rascal-textmate-core</artifactId>
43+
<version>0.1.0-SNAPSHOT</version>
44+
</dependency>
45+
```
46+
47+
2. Add `|lib://rascal-textmate-core|` to `Require-Libraries` in
48+
`META-INF/RASCAL.MF` of the project.
49+
50+
3. Open a REPL in a grammar module of the project, import module
51+
`lang::textmate::main::Main` in the REPL, and run function
52+
[`main`](https://github.com/SWAT-engineering/rascal-textmate/blob/69bd92c1e39b51c78ad6d49e680bba212a8df2a7/rascal-textmate-core/src/main/rascal/Main.rsc#L38-L47)
53+
on the `start` symbol of the grammar. For instance:
54+
55+
```rascal
56+
main(#Foo, "source.foo", |home:///Desktop/foo.json|)
57+
```
58+
59+
The generated TextMate grammar (as a JSON file) can now be integrated in a
60+
VS Code extension as explained
61+
[here](https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide#contributing-a-basic-grammar).
62+
63+
## Contributing
64+
65+
### Documentation
2066

2167
The [walkthrough](rascal-textmate-core/src/main/rascal/lang/textmate/conversiontests/Walkthrough.rsc)
22-
explains the main ideas behind the conversion algorithm in this project.
68+
explains the main ideas behind the conversion algorithm.
2369

24-
## Tests
70+
### Tests
2571

2672
To test tokenization (as part of the conversion
2773
[tests](rascal-textmate-core/src/main/rascal/lang/textmate/conversiontests)),

rascal-textmate-core/pom.xml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<dependency>
6565
<groupId>org.rascalmpl</groupId>
6666
<artifactId>rascal</artifactId>
67-
<version>0.40.4</version>
67+
<version>0.40.17</version>
6868
</dependency>
6969

7070
<!-- Rascal tests require JUnit 4 -->
@@ -77,6 +77,19 @@
7777
</dependencies>
7878

7979
<build>
80+
<resources>
81+
<resource>
82+
<directory>.</directory>
83+
<filtering>false</filtering>
84+
<includes>
85+
<include>META-INF/RASCAL.MF</include>
86+
</includes>
87+
</resource>
88+
<resource>
89+
<directory>src/main/rascal</directory>
90+
<filtering>false</filtering>
91+
</resource>
92+
</resources>
8093
<plugins>
8194
<plugin>
8295
<groupId>org.apache.maven.plugins</groupId>

rascal-textmate-core/src/main/rascal/lang/textmate/Conversion.rsc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,10 @@ list[ConversionUnit] analyze(RscGrammar rsc, str name) {
227227
228228
// Analyze delimiters
229229
jobStep(jobLabel, "Analyzing delimiters");
230-
set[Symbol] delimiters
231-
= removeStrictPrefixes({s | /Symbol s := rsc, isDelimiter(delabel(s))})
232-
- {s | p <- prods, /just(s) := getOuterDelimiterPair(rsc, p)}
233-
- {s | p <- prods, /just(s) := getInnerDelimiterPair(rsc, p, getOnlyFirst = true)};
230+
set[Symbol] delimiters = {s | /Symbol s := rsc, isDelimiter(delabel(s))};
231+
delimiters &= removeStrictPrefixes(delimiters);
232+
delimiters -= {s | p <- prods, /just(s) := getOuterDelimiterPair(rsc, p)};
233+
delimiters -= {s | p <- prods, /just(s) := getInnerDelimiterPair(rsc, p, getOnlyFirst = true)};
234234
list[Production] prodsDelimiters = [prod(lex(DELIMITERS_PRODUCTION_NAME), [\alt(delimiters)], {})];
235235
236236
// Analyze keywords
@@ -552,4 +552,4 @@ private TmRule toTmRule(RegExp begin, RegExp end, list[TmRule] patterns)
552552
end.string,
553553
beginCaptures = toCaptures(begin.categories),
554554
endCaptures = toCaptures(end.categories),
555-
patterns = patterns);
555+
patterns = patterns);

rascal-textmate-core/src/main/rascal/Main.rsc renamed to rascal-textmate-core/src/main/rascal/lang/textmate/main/Main.rsc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
Main functions to generate TextMate grammars for Rascal grammars
2929
}
3030

31-
module Main
31+
module lang::textmate::main::Main
3232

3333
import Grammar;
3434
import lang::textmate::Conversion;
@@ -44,4 +44,4 @@ int main(RscGrammar rsc, str scopeName, loc l) {
4444
TmGrammar tm = toTmGrammar(rsc, scopeName, nameGeneration = short());
4545
toJSON(tm, indent = 2, l = l);
4646
return 0;
47-
}
47+
}

rascal-textmate-core/src/main/rascal/VSCode.rsc renamed to rascal-textmate-core/src/main/rascal/lang/textmate/main/VSCode.rsc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929
used in the special VS Code extension
3030
}
3131

32-
module VSCode
32+
module lang::textmate::main::VSCode
3333

34-
import VSCodePico;
35-
import VSCodeRascal;
34+
import lang::textmate::main::VSCodePico;
35+
import lang::textmate::main::VSCodeRascal;
3636

3737
int main() {
38-
VSCodePico::main();
39-
VSCodeRascal::main();
38+
lang::textmate::main::VSCodePico::main();
39+
lang::textmate::main::VSCodeRascal::main();
4040
return 0;
41-
}
41+
}

rascal-textmate-core/src/main/rascal/VSCodePico.rsc renamed to rascal-textmate-core/src/main/rascal/lang/textmate/main/VSCodePico.rsc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929
special VS Code extension
3030
}
3131

32-
module VSCodePico
32+
module lang::textmate::main::VSCodePico
3333

34-
import Main;
34+
import lang::textmate::main::Main;
3535
extend lang::textmate::conversiontests::PicoWithCategories;
3636

37-
int main() = Main::main(rsc, "source.pico", |project://vscode-extension/syntaxes/pico.tmLanguage.json|);
37+
int main() = lang::textmate::main::Main::main(
38+
rsc, "source.pico", |project://vscode-extension/syntaxes/pico.tmLanguage.json|);

rascal-textmate-core/src/main/rascal/VSCodeRascal.rsc renamed to rascal-textmate-core/src/main/rascal/lang/textmate/main/VSCodeRascal.rsc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929
the special VS Code extension
3030
}
3131

32-
module VSCodeRascal
32+
module lang::textmate::main::VSCodeRascal
3333

3434
import Grammar;
35-
import Main;
35+
import lang::textmate::main::Main;
3636
extend lang::textmate::conversiontests::Rascal;
3737

38-
int main() = Main::main(getRscGrammar(), "source.rascalmpl", |project://vscode-extension/syntaxes/rascal.tmLanguage.json|);
38+
int main() = lang::textmate::main::Main::main(
39+
getRscGrammar(), "source.rascalmpl",
40+
|project://vscode-extension/syntaxes/rascal.tmLanguage.json|);
3941

4042
// Relevant comment regarding grammar precedence in VS Code:
4143
// - https://github.com/microsoft/vscode-docs/issues/2862#issuecomment-599994967
@@ -45,7 +47,7 @@ private Grammar getRscGrammar() {
4547
= {\tag("category"(_)), *rest} := attributes
4648
? p[attributes = rest + \tag("category"(category))]
4749
: p[attributes = attributes + \tag("category"(category))];
48-
50+
4951
return visit (rsc) {
5052
// Temporarily hot-patch Rascal's own grammar as discussed here:
5153
// - https://github.com/SWAT-engineering/rascal-textmate/pull/6
@@ -60,4 +62,4 @@ private Grammar getRscGrammar() {
6062
case p: prod(lex("MidStringChars"), _, _) => setCategory(p, "string.quoted.double")
6163
case p: prod(lex("PostStringChars"), _, _) => setCategory(p, "string.quoted.double")
6264
};
63-
}
65+
}

0 commit comments

Comments
 (0)