Skip to content

Commit

Permalink
Add TextMate grammar (used by Visual Studio Code)
Browse files Browse the repository at this point in the history
  • Loading branch information
d-torrance authored and mahrud committed Jul 27, 2024
1 parent a7a2f1f commit 2f774ce
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
9 changes: 9 additions & 0 deletions M2/Macaulay2/editors/make-M2-symbols.m2
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ symbolsForHighlightJS = template -> (
output = replace("@M2CONSTANTS@", hljsformat CONSTANTS, output);
output)

symbolsForTextMate = template -> (
output = replace("@M2KEYWORDS@", demark("|", KEYWORDS), template);
output = replace("@M2DATATYPES@", demark("|", DATATYPES), output);
output = replace("@M2FUNCTIONS@", demark("|", FUNCTIONS), output);
output = replace("@M2CONSTANTS@", demark("|", CONSTANTS), output);
output)

-------------------------------------------------------------------------------
-- Generate syntax files from templates in the same directory

Expand Down Expand Up @@ -178,6 +185,8 @@ generateGrammar("pygments/macaulay2.py", symbolsForPygments)
-- highlight.js: Write macaulay2.js
generateGrammar("highlightjs/macaulay2.js", symbolsForHighlightJS)

generateGrammar("textmate/macaulay2.tmLanguage.json", symbolsForTextMate)

-- Local Variables:
-- compile-command: "make -C $M2BUILDDIR/Macaulay2/emacs M2-symbols "
-- End:
106 changes: 106 additions & 0 deletions M2/Macaulay2/editors/textmate/macaulay2.tmLanguage.json.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"name": "Macaulay2",
"scopeName": "source.macaulay2",
"fileTypes": [
"m2"
],
"patterns": [
{
"include": "#comments"
},
{
"include": "#strings"
},
{
"include": "#keywords"
},
{
"include": "#support"
}
],
"repository": {
"storage": {
"patterns": [
{
"name": "meta.function.macaulay2",
"match": "(\\)"
}
]
},
"keywords": {
"patterns": [
{
"name": "keyword.other.macaulay2",
"match": "(x?)\\b(@M2KEYWORDS@)\\b"
},
{
"name": "keyword.operator.functionArrow.macaulay2",
"match": "->"
},
{
"name": "keyword.operator.optionArrow.macaulay2",
"match": "=>"
},
{
"name": "keyword.operator.arithmetic.macaulay2",
"match": "%|\\*|/|//|-|\\+|\\\\"
}
]
},
"strings": {
"patterns": [
{
"name": "string.quoted.double.macaulay2",
"begin": "\"",
"end": "\"",
"patterns": [
{
"name": "constant.character.escape.macaulay2",
"match": "\\\\."
}
]
},
{
"name": "string.tripleslash.macaulay2",
"begin": "///",
"end": "///"
}
]
},
"comments": {
"patterns": [
{
"name": "comment.line.double-dash.macaulay2",
"begin": "--",
"end": "$"
},
{
"name": "comment.block.macaulay2",
"begin": "-\\*",
"end": "\\*-"
},
{
"name": "comment.block.macaulay2.deprecated",
"begin": "{\\*",
"end": "\\*}"
}
]
},
"support": {
"patterns": [
{
"name": "entity.name.type.macaulay2",
"match": "(x?)\\b(@M2DATATYPES@)\\b"
},
{
"name": "support.function.macaulay2",
"match": "(x?)\\b(@M2FUNCTIONS@)\\b"
},
{
"name": "constant.language.macaulay2",
"match": "(x?)\\b(@M2CONSTANTS@)\\b"
}
]
}
}
}

0 comments on commit 2f774ce

Please sign in to comment.