Skip to content

Commit

Permalink
Merge pull request #6 from SWAT-engineering/restore-updated-categories
Browse files Browse the repository at this point in the history
Restore updated categories (specifically for Rascal syntax highlighting)
  • Loading branch information
sungshik authored Jul 16, 2024
2 parents 6842b97 + 0546433 commit 23cca94
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 15 deletions.
45 changes: 34 additions & 11 deletions rascal-textmate-core/src/main/rascal/VSCode.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,48 @@ int main() {
return 0;
}

RscGrammar getRscGrammar() =
visit (Grammar::grammar(#Module)) {
RscGrammar getRscGrammar() {
Production setCategory(p: prod(_, _, attributes), str category)
= {\tag("category"(_)), *rest} := attributes
? p[attributes = rest + \tag("category"(category))]
: p[attributes = attributes + \tag("category"(category))];

return visit (Grammar::grammar(#Module)) {

// The following mapping is based on:
// - https://github.com/usethesource/rascal/blob/83023f60a6eb9df7a19ccc7a4194b513ac7b7157/src/org/rascalmpl/values/parsetrees/TreeAdapter.java#L44-L59
// - https://github.com/usethesource/rascal-language-servers/blob/752fea3ea09101e5b22ee426b11c5e36db880225/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/SemanticTokenizer.java#L121-L142
// With updates based on:
// - https://github.com/eclipse-lsp4j/lsp4j/blob/f235e91fbe2e45f62e185bbb9f6d21bed48eb2b9/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend#L5639-L5695
// - https://github.com/usethesource/rascal-language-servers/blob/88be4a326128da8c81d581c2b918b4927f2185be/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/SemanticTokenizer.java#L134-L152
case \tag("category"("Normal")) => \tag("category"("source"))
case \tag("category"("Type")) => \tag("category"("storage.type"))
case \tag("category"("Type")) => \tag("category"("type")) // Updated (before: storage.type)
case \tag("category"("Identifier")) => \tag("category"("variable"))
case \tag("category"("Variable")) => \tag("category"("variable"))
case \tag("category"("Constant")) => \tag("category"("constant"))
case \tag("category"("Constant")) => \tag("category"("string")) // Updated (before: constant)
case \tag("category"("Comment")) => \tag("category"("comment"))
case \tag("category"("Todo")) => \tag("category"("comment"))
case \tag("category"("Quote")) => \tag("category"("meta.string"))
case \tag("category"("Quote")) => \tag("category"("string")) // Updated (before: meta.string)
case \tag("category"("MetaAmbiguity")) => \tag("category"("invalid"))
case \tag("category"("MetaVariable")) => \tag("category"("variable"))
case \tag("category"("MetaKeyword")) => \tag("category"("keyword.other"))
case \tag("category"("MetaKeyword")) => \tag("category"("keyword")) // Updated (before: keyword.other)
case \tag("category"("MetaSkipped")) => \tag("category"("string"))
case \tag("category"("NonterminalLabel")) => \tag("category"("variable.parameter"))
case \tag("category"("Result")) => \tag("category"("text"))
case \tag("category"("StdOut")) => \tag("category"("text"))
case \tag("category"("StdErr")) => \tag("category"("text"))
};
case \tag("category"("NonterminalLabel")) => \tag("category"("variable")) // Updated (before: variable.parameter)
case \tag("category"("Result")) => \tag("category"("string")) // Updated (before: text)
case \tag("category"("StdOut")) => \tag("category"("string")) // Updated (before: text)
case \tag("category"("StdErr")) => \tag("category"("string")) // Updated (before: text)

// With additional hot-patching as discussed:
// - https://github.com/SWAT-engineering/rascal-textmate/pull/6
case p: prod(label("integer", sort("Literal")), _, _) => setCategory(p, "constant.numeric")
case p: prod(label("real", sort("Literal")), _, _) => setCategory(p, "constant.numeric")
case p: prod(label("rational", sort("Literal")), _, _) => setCategory(p, "constant.numeric")
case p: prod(label("location", sort("Literal")), _, _) => setCategory(p, "markup.underline.link")
case p: prod(label("regExp", sort("Literal")), _, _) => setCategory(p, "string.regexp")
case p: prod(lex("StringConstant"), _, _) => setCategory(p, "string.quoted.double")
case p: prod(lex("CaseInsensitiveStringConstant"), _, _) => setCategory(p, "string.quoted.single")
case p: prod(lex("PreStringChars"), _, _) => setCategory(p, "string.interpolated")
case p: prod(lex("MidStringChars"), _, _) => setCategory(p, "string.interpolated")
case p: prod(lex("PostStringChars"), _, _) => setCategory(p, "string.interpolated")
};
}
44 changes: 40 additions & 4 deletions vscode-extension/syntaxes/rascal.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@
}
}
},
"prod(label(\"rational\",sort(\"Literal\")),[label(\"rationalLiteral\",lex(\"RationalLiteral\"))],{tag(\"category\"(\"constant.numeric\"))})": {
"match": "((?:[1-9][0-9]*?r[0-9](?:[0-9]*?(?!(?:[0-9]|[A-Z]|\\_|[a-z]))))|(?:[0-9][0-9]*?r))",
"name": "prod(label(\"rational\",sort(\"Literal\")),[label(\"rationalLiteral\",lex(\"RationalLiteral\"))],{tag(\"category\"(\"constant.numeric\"))})",
"captures": {
"1": {
"name": "constant.numeric"
}
}
},
"prod(label(\"integer\",sort(\"Literal\")),[label(\"integerLiteral\",sort(\"IntegerLiteral\"))],{tag(\"category\"(\"constant.numeric\"))})": {
"match": "((?:0(?:[0-7]+?(?!(?:[0-9]|[A-Z]|\\_|[a-z]))))|(?:(?:[1-9](?:[0-9]*?(?!(?:[0-9]|[A-Z]|\\_|[a-z]))))|(?:(?:\\b0\\b)(?!(?:[0-9]|[A-Z]|\\_|[a-z]))))|(?:0(?:X|x)(?:(?:[0-9]|[A-F]|[a-f])+?(?!(?:[0-9]|[A-Z]|\\_|[a-z])))))",
"name": "prod(label(\"integer\",sort(\"Literal\")),[label(\"integerLiteral\",sort(\"IntegerLiteral\"))],{tag(\"category\"(\"constant.numeric\"))})",
"captures": {
"1": {
"name": "constant.numeric"
}
}
},
"prod(lex(\"keywords\"),[alt({lit(\"lexical\"),lit(\"loc\"),lit(\"if\"),lit(\"assoc\"),lit(\"test\"),lit(\"lrel\"),lit(\"throws\"),lit(\"clear\"),lit(\"module\"),lit(\"any\"),lit(\"int\"),lit(\"quit\"),lit(\"o\"),lit(\"anno\"),lit(\"true\"),lit(\"public\"),lit(\"keyword\"),lit(\"for\"),lit(\"tuple\"),lit(\"bracket\"),lit(\"bag\"),lit(\"it\"),lit(\"visit\"),lit(\"do\"),lit(\"data\"),lit(\"layout\"),lit(\"bool\"),lit(\"edit\"),lit(\"join\"),lit(\"is\"),lit(\"import\"),lit(\"view\"),lit(\"in\"),lit(\"rat\"),lit(\"modules\"),lit(\"continue\"),lit(\"left\"),lit(\"num\"),lit(\"assert\"),lit(\"throw\"),lit(\"one\"),lit(\"help\"),lit(\"default\"),lit(\"all\"),lit(\"global\"),lit(\"syntax\"),lit(\"false\"),lit(\"finally\"),lit(\"private\"),lit(\"mod\"),lit(\"java\"),lit(\"node\"),lit(\"start\"),lit(\"set\"),lit(\"right\"),lit(\"variable\"),lit(\"map\"),lit(\"10\"),lit(\"on\"),lit(\"break\"),lit(\"dynamic\"),lit(\"solve\"),lit(\"fail\"),lit(\"unimport\"),lit(\"outermost\"),lit(\"real\"),lit(\"list\"),lit(\"insert\"),lit(\"innermost\"),lit(\"declarations\"),lit(\"else\"),lit(\"rel\"),lit(\"function\"),lit(\"notin\"),lit(\"filter\"),lit(\"datetime\"),lit(\"catch\"),lit(\"try\"),lit(\"renaming\"),lit(\"tag\"),lit(\"has\"),lit(\"Z\"),lit(\"when\"),lit(\"type\"),lit(\"append\"),lit(\"extend\"),lit(\"switch\"),lit(\"void\"),lit(\"history\"),lit(\"T\"),lit(\"while\"),lit(\"str\"),lit(\"value\"),lit(\"undeclare\"),lit(\"case\"),lit(\"alias\"),lit(\"return\"),lit(\"0\")})],{tag(\"category\"(\"keyword.control\"))})": {
"match": "((?:\\blexical\\b)|(?:\\bloc\\b)|(?:\\bif\\b)|(?:\\bassoc\\b)|(?:\\btest\\b)|(?:\\blrel\\b)|(?:\\bthrows\\b)|(?:\\bclear\\b)|(?:\\bmodule\\b)|(?:\\bany\\b)|(?:\\bint\\b)|(?:\\bquit\\b)|(?:\\bo\\b)|(?:\\banno\\b)|(?:\\btrue\\b)|(?:\\bpublic\\b)|(?:\\bkeyword\\b)|(?:\\bfor\\b)|(?:\\btuple\\b)|(?:\\bbracket\\b)|(?:\\bbag\\b)|(?:\\bit\\b)|(?:\\bvisit\\b)|(?:\\bdo\\b)|(?:\\bdata\\b)|(?:\\blayout\\b)|(?:\\bbool\\b)|(?:\\bedit\\b)|(?:\\bjoin\\b)|(?:\\bis\\b)|(?:\\bimport\\b)|(?:\\bview\\b)|(?:\\bin\\b)|(?:\\brat\\b)|(?:\\bmodules\\b)|(?:\\bcontinue\\b)|(?:\\bleft\\b)|(?:\\bnum\\b)|(?:\\bassert\\b)|(?:\\bthrow\\b)|(?:\\bone\\b)|(?:\\bhelp\\b)|(?:\\bdefault\\b)|(?:\\ball\\b)|(?:\\bglobal\\b)|(?:\\bsyntax\\b)|(?:\\bfalse\\b)|(?:\\bfinally\\b)|(?:\\bprivate\\b)|(?:\\bmod\\b)|(?:\\bjava\\b)|(?:\\bnode\\b)|(?:\\bstart\\b)|(?:\\bset\\b)|(?:\\bright\\b)|(?:\\bvariable\\b)|(?:\\bmap\\b)|(?:\\b10\\b)|(?:\\bon\\b)|(?:\\bbreak\\b)|(?:\\bdynamic\\b)|(?:\\bsolve\\b)|(?:\\bfail\\b)|(?:\\bunimport\\b)|(?:\\boutermost\\b)|(?:\\breal\\b)|(?:\\blist\\b)|(?:\\binsert\\b)|(?:\\binnermost\\b)|(?:\\bdeclarations\\b)|(?:\\belse\\b)|(?:\\brel\\b)|(?:\\bfunction\\b)|(?:\\bnotin\\b)|(?:\\bfilter\\b)|(?:\\bdatetime\\b)|(?:\\bcatch\\b)|(?:\\btry\\b)|(?:\\brenaming\\b)|(?:\\btag\\b)|(?:\\bhas\\b)|(?:\\bZ\\b)|(?:\\bwhen\\b)|(?:\\btype\\b)|(?:\\bappend\\b)|(?:\\bextend\\b)|(?:\\bswitch\\b)|(?:\\bvoid\\b)|(?:\\bhistory\\b)|(?:\\bT\\b)|(?:\\bwhile\\b)|(?:\\bstr\\b)|(?:\\bvalue\\b)|(?:\\bundeclare\\b)|(?:\\bcase\\b)|(?:\\balias\\b)|(?:\\breturn\\b)|(?:\\b0\\b))",
"name": "prod(lex(\"keywords\"),[alt({lit(\"lexical\"),lit(\"loc\"),lit(\"if\"),lit(\"assoc\"),lit(\"test\"),lit(\"lrel\"),lit(\"throws\"),lit(\"clear\"),lit(\"module\"),lit(\"any\"),lit(\"int\"),lit(\"quit\"),lit(\"o\"),lit(\"anno\"),lit(\"true\"),lit(\"public\"),lit(\"keyword\"),lit(\"for\"),lit(\"tuple\"),lit(\"bracket\"),lit(\"bag\"),lit(\"it\"),lit(\"visit\"),lit(\"do\"),lit(\"data\"),lit(\"layout\"),lit(\"bool\"),lit(\"edit\"),lit(\"join\"),lit(\"is\"),lit(\"import\"),lit(\"view\"),lit(\"in\"),lit(\"rat\"),lit(\"modules\"),lit(\"continue\"),lit(\"left\"),lit(\"num\"),lit(\"assert\"),lit(\"throw\"),lit(\"one\"),lit(\"help\"),lit(\"default\"),lit(\"all\"),lit(\"global\"),lit(\"syntax\"),lit(\"false\"),lit(\"finally\"),lit(\"private\"),lit(\"mod\"),lit(\"java\"),lit(\"node\"),lit(\"start\"),lit(\"set\"),lit(\"right\"),lit(\"variable\"),lit(\"map\"),lit(\"10\"),lit(\"on\"),lit(\"break\"),lit(\"dynamic\"),lit(\"solve\"),lit(\"fail\"),lit(\"unimport\"),lit(\"outermost\"),lit(\"real\"),lit(\"list\"),lit(\"insert\"),lit(\"innermost\"),lit(\"declarations\"),lit(\"else\"),lit(\"rel\"),lit(\"function\"),lit(\"notin\"),lit(\"filter\"),lit(\"datetime\"),lit(\"catch\"),lit(\"try\"),lit(\"renaming\"),lit(\"tag\"),lit(\"has\"),lit(\"Z\"),lit(\"when\"),lit(\"type\"),lit(\"append\"),lit(\"extend\"),lit(\"switch\"),lit(\"void\"),lit(\"history\"),lit(\"T\"),lit(\"while\"),lit(\"str\"),lit(\"value\"),lit(\"undeclare\"),lit(\"case\"),lit(\"alias\"),lit(\"return\"),lit(\"0\")})],{tag(\"category\"(\"keyword.control\"))})",
Expand All @@ -18,6 +36,15 @@
}
}
},
"prod(label(\"real\",sort(\"Literal\")),[label(\"realLiteral\",lex(\"RealLiteral\"))],{tag(\"category\"(\"constant.numeric\"))})": {
"match": "((?:(?:(?<!\\.)(?:\\.))[0-9]+?(?:E|e)(?:\\+|\\-)??[0-9]+?(?:D|F|d|f)??)|(?:[0-9]+?(?:(?:\\.)(?!(?:\\.)))[0-9]*?(?:D|F|d|f)??)|(?:(?:(?<!\\.)(?:\\.))[0-9]+?(?:D|F|d|f)??)|(?:[0-9]+?(?:E|e)(?:\\+|\\-)??[0-9]+?(?:D|F|d|f)??)|(?:[0-9]+?(?:D|F|d|f))|(?:[0-9]+?(?:\\.)[0-9]*?(?:E|e)(?:\\+|\\-)??[0-9]+?(?:D|F|d|f)??))",
"name": "prod(label(\"real\",sort(\"Literal\")),[label(\"realLiteral\",lex(\"RealLiteral\"))],{tag(\"category\"(\"constant.numeric\"))})",
"captures": {
"1": {
"name": "constant.numeric"
}
}
},
"prod(lex(\"delimiters\"),[alt({lit(\"bottom-up-break\"),lit(\")\"),lit(\"\"),lit(\"\\n\"),lit(\"!:=\"),lit(\"\\'\"),lit(\"!=\"),lit(\"\\>=\"),lit(\"://\"),lit(\"non-assoc\"),lit(\"&=\"),lit(\"\\<-\"),lit(\"*=\"),lit(\"+=\"),lit(\"top-down-break\"),lit(\",\"),lit(\"...\"),lit(\"/=\"),lit(\"\"),lit(\"(\"),lit(\"*/\"),lit(\"%\"),lit(\"!\\<\\<\"),lit(\"=\\>\"),lit(\"!\\>\\>\"),lit(\"||\"),lit(\"\\>\\>\"),lit(\"::\"),lit(\"\"),lit(\"&&\"),lit(\"@\"),lit(\":=\"),lit(\"#\"),lit(\"\\<==\\>\"),lit(\"\\\"\"),lit(\"\\<\\<=\"),lit(\"}\"),lit(\"?=\"),lit(\"\\<:\"),lit(\"==\\>\"),lit(\"^\"),lit(\"/*\"),lit(\";\"),lit(\"{\"),lit(\"-=\"),lit(\"$T\")})],{})": {
"match": "(?:(?:bottom\\-up\\-break)|(?:\\))|(?:\\x{226B})|(?:\\n)|(?:\\!\\:\\=)|(?:\\')|(?:\\!\\=)|(?:\\>\\=)|(?:\\:\\/\\/)|(?:non\\-assoc)|(?:\\&\\=)|(?:\\<\\-)|(?:\\*\\=)|(?:\\+\\=)|(?:top\\-down\\-break)|(?:\\,)|(?:\\.\\.\\.)|(?:\\/\\=)|(?:\\x{21E8})|(?:\\()|(?:\\*\\/)|(?:\\%)|(?:\\!\\<\\<)|(?:\\=\\>)|(?:\\!\\>\\>)|(?:\\|\\|)|(?:\\>\\>)|(?:\\:\\:)|(?:\\x{26A0})|(?:\\&\\&)|(?:\\@)|(?:\\:\\=)|(?:\\#)|(?:\\<\\=\\=\\>)|(?:\\\")|(?:\\<\\<\\=)|(?:\\})|(?:\\?\\=)|(?:\\<\\:)|(?:\\=\\=\\>)|(?:\\^)|(?:\\/\\*)|(?:\\;)|(?:\\{)|(?:\\-\\=)|(?:\\$T))",
"name": "prod(lex(\"delimiters\"),[alt({lit(\"bottom-up-break\"),lit(\")\"),lit(\"\"),lit(\"\\n\"),lit(\"!:=\"),lit(\"\\'\"),lit(\"!=\"),lit(\"\\>=\"),lit(\"://\"),lit(\"non-assoc\"),lit(\"&=\"),lit(\"\\<-\"),lit(\"*=\"),lit(\"+=\"),lit(\"top-down-break\"),lit(\",\"),lit(\"...\"),lit(\"/=\"),lit(\"\"),lit(\"(\"),lit(\"*/\"),lit(\"%\"),lit(\"!\\<\\<\"),lit(\"=\\>\"),lit(\"!\\>\\>\"),lit(\"||\"),lit(\"\\>\\>\"),lit(\"::\"),lit(\"\"),lit(\"&&\"),lit(\"@\"),lit(\":=\"),lit(\"#\"),lit(\"\\<==\\>\"),lit(\"\\\"\"),lit(\"\\<\\<=\"),lit(\"}\"),lit(\"?=\"),lit(\"\\<:\"),lit(\"==\\>\"),lit(\"^\"),lit(\"/*\"),lit(\";\"),lit(\"{\"),lit(\"-=\"),lit(\"$T\")})],{})",
Expand Down Expand Up @@ -81,19 +108,19 @@
"patterns": [
{
"match": "((?:\\\\)(?:\\x{20}|\\\"|\\'|\\-|\\<|\\>|[\\[-\\]]|b|f|n|r|t))",
"name": "prod(lex(\"Char\"),[lit(\"\\\\\"),\\char-class([range(32,32),range(34,34),range(39,39),range(45,45),range(60,60),range(62,62),range(91,93),range(98,98),range(102,102),range(110,110),range(114,114),range(116,116)])],{tag(\"category\"(\"constant\"))})",
"name": "prod(lex(\"Char\"),[lit(\"\\\\\"),\\char-class([range(32,32),range(34,34),range(39,39),range(45,45),range(60,60),range(62,62),range(91,93),range(98,98),range(102,102),range(110,110),range(114,114),range(116,116)])],{tag(\"category\"(\"string\"))})",
"captures": {
"1": {
"name": "constant"
"name": "string"
}
}
},
{
"match": "((?:(?:\\\\)U(?:(?:\\b10\\b)|(?:(?:\\b0\\b)(?:[0-9]|[A-F]|[a-f])))(?:[0-9]|[A-F]|[a-f])(?:[0-9]|[A-F]|[a-f])(?:[0-9]|[A-F]|[a-f])(?:[0-9]|[A-F]|[a-f]))|(?:(?:\\\\)u(?:[0-9]|[A-F]|[a-f])(?:[0-9]|[A-F]|[a-f])(?:[0-9]|[A-F]|[a-f])(?:[0-9]|[A-F]|[a-f]))|(?:(?:\\\\)a[0-7](?:[0-9]|[A-F]|[a-f])))",
"name": "prod(lex(\"Char\"),[lex(\"UnicodeEscape\")],{tag(\"category\"(\"constant\"))})",
"name": "prod(lex(\"Char\"),[lex(\"UnicodeEscape\")],{tag(\"category\"(\"string\"))})",
"captures": {
"1": {
"name": "constant"
"name": "string"
}
}
}
Expand All @@ -106,6 +133,15 @@
{
"include": "#prod(lex(\"delimiters\"),[alt({lit(\"bottom-up-break\"),lit(\")\"),lit(\"\"),lit(\"\\n\"),lit(\"!:=\"),lit(\"\\'\"),lit(\"!=\"),lit(\"\\>=\"),lit(\"://\"),lit(\"non-assoc\"),lit(\"&=\"),lit(\"\\<-\"),lit(\"*=\"),lit(\"+=\"),lit(\"top-down-break\"),lit(\",\"),lit(\"...\"),lit(\"/=\"),lit(\"\"),lit(\"(\"),lit(\"*/\"),lit(\"%\"),lit(\"!\\<\\<\"),lit(\"=\\>\"),lit(\"!\\>\\>\"),lit(\"||\"),lit(\"\\>\\>\"),lit(\"::\"),lit(\"\"),lit(\"&&\"),lit(\"@\"),lit(\":=\"),lit(\"#\"),lit(\"\\<==\\>\"),lit(\"\\\"\"),lit(\"\\<\\<=\"),lit(\"}\"),lit(\"?=\"),lit(\"\\<:\"),lit(\"==\\>\"),lit(\"^\"),lit(\"/*\"),lit(\";\"),lit(\"{\"),lit(\"-=\"),lit(\"$T\")})],{})"
},
{
"include": "#prod(label(\"integer\",sort(\"Literal\")),[label(\"integerLiteral\",sort(\"IntegerLiteral\"))],{tag(\"category\"(\"constant.numeric\"))})"
},
{
"include": "#prod(label(\"real\",sort(\"Literal\")),[label(\"realLiteral\",lex(\"RealLiteral\"))],{tag(\"category\"(\"constant.numeric\"))})"
},
{
"include": "#prod(label(\"rational\",sort(\"Literal\")),[label(\"rationalLiteral\",lex(\"RationalLiteral\"))],{tag(\"category\"(\"constant.numeric\"))})"
},
{
"include": "#lit(\"`\"):lit(\"`\")"
},
Expand Down

0 comments on commit 23cca94

Please sign in to comment.