Skip to content

Commit

Permalink
feat: improved TextMate grammar (#623)
Browse files Browse the repository at this point in the history
### Summary of Changes

Various improvements to the auto-generated TextMate grammar:
* Categorization of keywords into correct groups
* Description of number literals
* Treatment of keywords that are enclosed in backticks as names
* Test markers are no longer treated as comments
  • Loading branch information
lars-reimann authored Oct 9, 2023
1 parent 608e470 commit d7ff0e2
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dist/
dist-ssr/
generated/
out/
syntaxes/safe-ds.tmLanguage.json
syntaxes/safe-ds.generated.tmLanguage.json

# Node
.npm/
Expand Down
2 changes: 1 addition & 1 deletion langium-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"grammar": "src/language/grammar/safe-ds.langium",
"fileExtensions": [".sdspipe", ".sdsstub", ".sdstest"],
"textMate": {
"out": "syntaxes/safe-ds.tmLanguage.json"
"out": "syntaxes/safe-ds.generated.tmLanguage.json"
}
}
],
Expand Down
88 changes: 88 additions & 0 deletions syntaxes/safe-ds.tmLanguage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"name": "safe-ds",
"scopeName": "source.safe-ds",
"fileTypes": [
".sdspipe",
".sdsstub",
".sdstest"
],
"patterns": [
{
"include": "#comments"
},
{
"name": "constant.numeric.safe-ds",
"match": "\\b([0-9]+(\\.[0-9]+)?([eE][+-]?[0-9]+)?)\\b"
},
{
"name": "constant.language.safe-ds",
"match": "\\b(false|null|true)\\b"
},
{
"name": "storage.type.safe-ds",
"match": "\\b(annotation|attr|class|enum|fun|package|pipeline|schema|segment|val)\\b"
},
{
"name": "storage.modifier.safe-ds",
"match": "\\b(const|in|internal|out|private|static)\\b"
},
{
"name": "keyword.operator.safe-ds",
"match": "\\b(and|not|or|sub|super)\\b"
},
{
"name": "keyword.other.safe-ds",
"match": "\\b(as|from|import|literal|union|where|yield)\\b"
},
{
"name": "entity.name.safe-ds",
"begin": "\\`",
"end": "\\`"
},
{
"name": "string.quoted.double.safe-ds",
"begin": "\"",
"end": "\"",
"patterns": [
{
"include": "#string-character-escape"
}
]
}
],
"repository": {
"comments": {
"patterns": [
{
"name": "comment.line.double-slash.safe-ds",
"begin": "//",
"beginCaptures": {
"1": {
"name": "punctuation.whitespace.comment.leading.safe-ds"
}
},
"end": "(?=$)"
},
{
"name": "comment.block.safe-ds",
"begin": "/\\*",
"beginCaptures": {
"0": {
"name": "punctuation.definition.comment.safe-ds"
}
},
"end": "\\*/",
"endCaptures": {
"0": {
"name": "punctuation.definition.comment.safe-ds"
}
}
}
]
},
"string-character-escape": {
"name": "constant.character.escape.safe-ds",
"match": "\\\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|u\\{[0-9A-Fa-f]+\\}|[0-2][0-7]{0,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.|$)"
}
}
}

0 comments on commit d7ff0e2

Please sign in to comment.