From d7ff0e28b40ad2cb1a0821dc18b8862dbc1dbebe Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Mon, 9 Oct 2023 22:06:02 +0200 Subject: [PATCH] feat: improved TextMate grammar (#623) ### 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 --- .gitignore | 2 +- langium-config.json | 2 +- syntaxes/safe-ds.tmLanguage.json | 88 ++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 syntaxes/safe-ds.tmLanguage.json diff --git a/.gitignore b/.gitignore index 6d3d5e96c..f9b0b7ebc 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,7 @@ dist/ dist-ssr/ generated/ out/ -syntaxes/safe-ds.tmLanguage.json +syntaxes/safe-ds.generated.tmLanguage.json # Node .npm/ diff --git a/langium-config.json b/langium-config.json index 804d120ef..3a866c5da 100644 --- a/langium-config.json +++ b/langium-config.json @@ -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" } } ], diff --git a/syntaxes/safe-ds.tmLanguage.json b/syntaxes/safe-ds.tmLanguage.json new file mode 100644 index 000000000..40238aa67 --- /dev/null +++ b/syntaxes/safe-ds.tmLanguage.json @@ -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]?|.|$)" + } + } +}