@@ -54,16 +54,24 @@ TmGrammar toTmGrammar(RscGrammar rsc, str name, NameGeneration nameGeneration =
5454}
5555
5656RscGrammar preprocess (RscGrammar rsc ) {
57- // Replace occurrences of singleton ranges with just the corresponding
58- // literal. This makes it easier to identify delimiters.
59- rsc = visit (rsc ) {
57+ rsc = replaceSingletonRanges (rsc );
58+ rsc = replaceCurrentSemanticTokenTypes (rsc );
59+ rsc = replaceLegacySemanticTokenTypes (rsc );
60+ return rsc ;
61+ }
62+
63+ // Replace occurrences of singleton ranges with just the corresponding literal.
64+ // This makes it easier to identify delimiters.
65+ private RscGrammar replaceSingletonRanges (RscGrammar rsc )
66+ = visit (rsc ) {
6067 case \char -class ([range (char , char )]) => d
6168 when d := \lit ("<stringChar (char )> " ), isDelimiter (d )
62- }
69+ };
6370
64- // Replace current semantic token types with TextMate scopes based on:
65- // - https://github.com/microsoft/vscode/blob/9f3a7b5bc8a2758584b33d0385b227f25ae8d3fb/src/vs/platform/theme/common/tokenClassificationRegistry.ts#L543-L571
66- rsc = visit (rsc ) {
71+ // Replace current semantic token types with TextMate scopes based on:
72+ // - https://github.com/microsoft/vscode/blob/9f3a7b5bc8a2758584b33d0385b227f25ae8d3fb/src/vs/platform/theme/common/tokenClassificationRegistry.ts#L543-L571
73+ private RscGrammar replaceCurrentSemanticTokenTypes (RscGrammar rsc )
74+ = visit (rsc ) {
6775 case \tag ("category" ("comment" )) => \tag ("category" ("comment" ))
6876 case \tag ("category" ("string" )) => \tag ("category" ("string" ))
6977 case \tag ("category" ("keyword" )) => \tag ("category" ("keyword.control" ))
@@ -88,15 +96,16 @@ RscGrammar preprocess(RscGrammar rsc) {
8896 case \tag ("category" ("decorator" )) => \tag ("category" ("entity.name.decorator" )) // Alternative: entity.name.function
8997 // Note: Categories types `member` and `label` are deprecated/undefined
9098 // and therefore excluded from this mapping
91- }
92-
93- // Replace legacy semantic token types with TextMate scopes based on:
94- // - https://github.com/usethesource/rascal/blob/83023f60a6eb9df7a19ccc7a4194b513ac7b7157/src/org/rascalmpl/values/parsetrees/TreeAdapter.java#L44-L59
95- // - https://github.com/usethesource/rascal-language-servers/blob/752fea3ea09101e5b22ee426b11c5e36db880225/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/SemanticTokenizer.java#L121-L142
96- // With updates based on:
97- // - https://github.com/eclipse-lsp4j/lsp4j/blob/f235e91fbe2e45f62e185bbb9f6d21bed48eb2b9/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend#L5639-L5695
98- // - https://github.com/usethesource/rascal-language-servers/blob/88be4a326128da8c81d581c2b918b4927f2185be/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/SemanticTokenizer.java#L134-L152
99- rsc = visit (rsc ) {
99+ };
100+
101+ // Replace legacy semantic token types with TextMate scopes based on:
102+ // - https://github.com/usethesource/rascal/blob/83023f60a6eb9df7a19ccc7a4194b513ac7b7157/src/org/rascalmpl/values/parsetrees/TreeAdapter.java#L44-L59
103+ // - https://github.com/usethesource/rascal-language-servers/blob/752fea3ea09101e5b22ee426b11c5e36db880225/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/SemanticTokenizer.java#L121-L142
104+ // With updates based on:
105+ // - https://github.com/eclipse-lsp4j/lsp4j/blob/f235e91fbe2e45f62e185bbb9f6d21bed48eb2b9/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend#L5639-L5695
106+ // - https://github.com/usethesource/rascal-language-servers/blob/88be4a326128da8c81d581c2b918b4927f2185be/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/SemanticTokenizer.java#L134-L152
107+ private RscGrammar replaceLegacySemanticTokenTypes (RscGrammar rsc )
108+ = visit (rsc ) {
100109 case \tag ("category" ("Normal" )) => \tag ("category" ("source" ))
101110 case \tag ("category" ("Type" )) => \tag ("category" ("type" )) // Updated (before: storage.type)
102111 case \tag ("category" ("Identifier" )) => \tag ("category" ("variable" ))
@@ -113,10 +122,7 @@ RscGrammar preprocess(RscGrammar rsc) {
113122 case \tag ("category" ("Result" )) => \tag ("category" ("string" )) // Updated (before: text)
114123 case \tag ("category" ("StdOut" )) => \tag ("category" ("string" )) // Updated (before: text)
115124 case \tag ("category" ("StdErr" )) => \tag ("category" ("string" )) // Updated (before: text)
116- }
117-
118- return rsc ;
119- }
125+ };
120126
121127@synoposis {
122128 Analyzes Rascal grammar `rsc`. Returns a list of productions, in the form of
0 commit comments