Skip to content

Commit 9ac4db3

Browse files
committed
Merge branch 'main' into ignore-category-production-inside-category-production
2 parents 2298d07 + 09aab8c commit 9ac4db3

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

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

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,24 @@ TmGrammar toTmGrammar(RscGrammar rsc, str name, NameGeneration nameGeneration =
5656
}
5757

5858
RscGrammar preprocess(RscGrammar rsc) {
59-
// Replace occurrences of singleton ranges with just the corresponding
60-
// literal. This makes it easier to identify delimiters.
61-
rsc = visit (rsc) {
59+
rsc = replaceSingletonRanges(rsc);
60+
rsc = replaceCurrentSemanticTokenTypes(rsc);
61+
rsc = replaceLegacySemanticTokenTypes(rsc);
62+
return rsc;
63+
}
64+
65+
// Replace occurrences of singleton ranges with just the corresponding literal.
66+
// This makes it easier to identify delimiters.
67+
private RscGrammar replaceSingletonRanges(RscGrammar rsc)
68+
= visit (rsc) {
6269
case \char-class([range(char, char)]) => d
6370
when d := \lit("<stringChar(char)>"), isDelimiter(d)
64-
}
71+
};
6572

66-
// Replace current semantic token types with TextMate scopes based on:
67-
// - https://github.com/microsoft/vscode/blob/9f3a7b5bc8a2758584b33d0385b227f25ae8d3fb/src/vs/platform/theme/common/tokenClassificationRegistry.ts#L543-L571
68-
rsc = visit (rsc) {
73+
// Replace current semantic token types with TextMate scopes based on:
74+
// - https://github.com/microsoft/vscode/blob/9f3a7b5bc8a2758584b33d0385b227f25ae8d3fb/src/vs/platform/theme/common/tokenClassificationRegistry.ts#L543-L571
75+
private RscGrammar replaceCurrentSemanticTokenTypes(RscGrammar rsc)
76+
= visit (rsc) {
6977
case \tag("category"("comment")) => \tag("category"("comment"))
7078
case \tag("category"("string")) => \tag("category"("string"))
7179
case \tag("category"("keyword")) => \tag("category"("keyword.control"))
@@ -90,15 +98,16 @@ RscGrammar preprocess(RscGrammar rsc) {
9098
case \tag("category"("decorator")) => \tag("category"("entity.name.decorator")) // Alternative: entity.name.function
9199
// Note: Categories types `member` and `label` are deprecated/undefined
92100
// and therefore excluded from this mapping
93-
}
94-
95-
// Replace legacy semantic token types with TextMate scopes based on:
96-
// - https://github.com/usethesource/rascal/blob/83023f60a6eb9df7a19ccc7a4194b513ac7b7157/src/org/rascalmpl/values/parsetrees/TreeAdapter.java#L44-L59
97-
// - https://github.com/usethesource/rascal-language-servers/blob/752fea3ea09101e5b22ee426b11c5e36db880225/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/SemanticTokenizer.java#L121-L142
98-
// With updates based on:
99-
// - https://github.com/eclipse-lsp4j/lsp4j/blob/f235e91fbe2e45f62e185bbb9f6d21bed48eb2b9/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend#L5639-L5695
100-
// - https://github.com/usethesource/rascal-language-servers/blob/88be4a326128da8c81d581c2b918b4927f2185be/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/SemanticTokenizer.java#L134-L152
101-
rsc = visit (rsc) {
101+
};
102+
103+
// Replace legacy semantic token types with TextMate scopes based on:
104+
// - https://github.com/usethesource/rascal/blob/83023f60a6eb9df7a19ccc7a4194b513ac7b7157/src/org/rascalmpl/values/parsetrees/TreeAdapter.java#L44-L59
105+
// - https://github.com/usethesource/rascal-language-servers/blob/752fea3ea09101e5b22ee426b11c5e36db880225/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/SemanticTokenizer.java#L121-L142
106+
// With updates based on:
107+
// - https://github.com/eclipse-lsp4j/lsp4j/blob/f235e91fbe2e45f62e185bbb9f6d21bed48eb2b9/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend#L5639-L5695
108+
// - https://github.com/usethesource/rascal-language-servers/blob/88be4a326128da8c81d581c2b918b4927f2185be/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/SemanticTokenizer.java#L134-L152
109+
private RscGrammar replaceLegacySemanticTokenTypes(RscGrammar rsc)
110+
= visit (rsc) {
102111
case \tag("category"("Normal")) => \tag("category"("source"))
103112
case \tag("category"("Type")) => \tag("category"("type")) // Updated (before: storage.type)
104113
case \tag("category"("Identifier")) => \tag("category"("variable"))
@@ -115,10 +124,7 @@ RscGrammar preprocess(RscGrammar rsc) {
115124
case \tag("category"("Result")) => \tag("category"("string")) // Updated (before: text)
116125
case \tag("category"("StdOut")) => \tag("category"("string")) // Updated (before: text)
117126
case \tag("category"("StdErr")) => \tag("category"("string")) // Updated (before: text)
118-
}
119-
120-
return rsc;
121-
}
127+
};
122128

123129
@synoposis{
124130
Analyzes Rascal grammar `rsc`. Returns a list of productions, in the form of

0 commit comments

Comments
 (0)