1
1
@synopsis {
2
- Main function to generate a new TextMate grammar for use in the special VS
3
- Code extension
2
+ Main function to generate new TextMate grammars for Rascal and Pico, to be
3
+ used in the special VS Code extension
4
4
}
5
5
6
6
module VSCode
7
7
8
- import Grammar ;
9
- import lang ::rascal ::\syntax ::Rascal ;
10
- import lang ::textmate ::Conversion ;
11
- import lang ::textmate ::Grammar ;
12
- import lang ::textmate ::NameGeneration ;
8
+ import VSCodePico ;
9
+ import VSCodeRascal ;
13
10
14
11
int main () {
15
- str scopeName = "source.rascalmpl.injection" ;
16
- RscGrammar rsc = getRscGrammar ();
17
- TmGrammar tm = toTmGrammar (rsc , scopeName , nameGeneration = short ())[injectionSelector = "R:source.rascalmpl" ];
18
- toJSON (tm , indent = 2 , l = |project://vscode-extension/syntaxes/rascal.tmLanguage.json| );
12
+ VSCodePico ::main ();
13
+ VSCodeRascal ::main ();
19
14
return 0 ;
20
- }
21
-
22
- RscGrammar getRscGrammar () {
23
- Production setCategory (p : prod (_, _, attributes ), str category )
24
- = {\tag ("category" (_)), *rest } := attributes
25
- ? p [attributes = rest + \tag ("category" (category ))]
26
- : p [attributes = attributes + \tag ("category" (category ))];
27
-
28
- return visit (Grammar ::grammar (#Module )) {
29
-
30
- // The following mapping is based on:
31
- // - https://github.com/usethesource/rascal/blob/83023f60a6eb9df7a19ccc7a4194b513ac7b7157/src/org/rascalmpl/values/parsetrees/TreeAdapter.java#L44-L59
32
- // - https://github.com/usethesource/rascal-language-servers/blob/752fea3ea09101e5b22ee426b11c5e36db880225/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/SemanticTokenizer.java#L121-L142
33
- // With updates based on:
34
- // - https://github.com/eclipse-lsp4j/lsp4j/blob/f235e91fbe2e45f62e185bbb9f6d21bed48eb2b9/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend#L5639-L5695
35
- // - https://github.com/usethesource/rascal-language-servers/blob/88be4a326128da8c81d581c2b918b4927f2185be/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/SemanticTokenizer.java#L134-L152
36
- case \tag ("category" ("Normal" )) => \tag ("category" ("source" ))
37
- case \tag ("category" ("Type" )) => \tag ("category" ("type" )) // Updated (before: storage.type)
38
- case \tag ("category" ("Identifier" )) => \tag ("category" ("variable" ))
39
- case \tag ("category" ("Variable" )) => \tag ("category" ("variable" ))
40
- case \tag ("category" ("Constant" )) => \tag ("category" ("string" )) // Updated (before: constant)
41
- case \tag ("category" ("Comment" )) => \tag ("category" ("comment" ))
42
- case \tag ("category" ("Todo" )) => \tag ("category" ("comment" ))
43
- case \tag ("category" ("Quote" )) => \tag ("category" ("string" )) // Updated (before: meta.string)
44
- case \tag ("category" ("MetaAmbiguity" )) => \tag ("category" ("invalid" ))
45
- case \tag ("category" ("MetaVariable" )) => \tag ("category" ("variable" ))
46
- case \tag ("category" ("MetaKeyword" )) => \tag ("category" ("keyword" )) // Updated (before: keyword.other)
47
- case \tag ("category" ("MetaSkipped" )) => \tag ("category" ("string" ))
48
- case \tag ("category" ("NonterminalLabel" )) => \tag ("category" ("variable" )) // Updated (before: variable.parameter)
49
- case \tag ("category" ("Result" )) => \tag ("category" ("string" )) // Updated (before: text)
50
- case \tag ("category" ("StdOut" )) => \tag ("category" ("string" )) // Updated (before: text)
51
- case \tag ("category" ("StdErr" )) => \tag ("category" ("string" )) // Updated (before: text)
52
-
53
- // With additional hot-patching as discussed:
54
- // - https://github.com/SWAT-engineering/rascal-textmate/pull/6
55
- case p : prod (label ("integer" , sort ("Literal" )), _, _) => setCategory (p , "constant.numeric" )
56
- case p : prod (label ("real" , sort ("Literal" )), _, _) => setCategory (p , "constant.numeric" )
57
- case p : prod (label ("rational" , sort ("Literal" )), _, _) => setCategory (p , "constant.numeric" )
58
- case p : prod (label ("location" , sort ("Literal" )), _, _) => setCategory (p , "markup.underline.link" )
59
- case p : prod (label ("regExp" , sort ("Literal" )), _, _) => setCategory (p , "constant.regexp" )
60
- case p : prod (lex ("StringConstant" ), _, _) => setCategory (p , "string.quoted.double" )
61
- case p : prod (lex ("CaseInsensitiveStringConstant" ), _, _) => setCategory (p , "string.quoted.single" )
62
- case p : prod (lex ("PreStringChars" ), _, _) => setCategory (p , "string.quoted.double" )
63
- case p : prod (lex ("MidStringChars" ), _, _) => setCategory (p , "string.quoted.double" )
64
- case p : prod (lex ("PostStringChars" ), _, _) => setCategory (p , "string.quoted.double" )
65
- };
66
15
}
0 commit comments