diff --git a/syntaxes/effekt.tmLanguage.json b/syntaxes/effekt.tmLanguage.json index 2dba4f1..cbcb51d 100644 --- a/syntaxes/effekt.tmLanguage.json +++ b/syntaxes/effekt.tmLanguage.json @@ -1,123 +1,303 @@ { "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", "name": "Effekt", + "foldingStartMarker": "(?))", + "captures": { + "1": { "name": "storage.modifier.extern.effekt" }, + "2": { "patterns": [{ "include": "#capabilities" }] }, + "3": { "name": "keyword.declaration.function.extern.effekt" }, + "4": { "name": "entity.name.function.effekt" } + }, + "patterns": [{ "include": "#parameters" }] + }, { + "begin": "\\s*(def)\\s+([a-zA-Z][a-z-A-Z0-9_$]*)\\b", + "end": "(?=\\n)|(?<=\\S)\\s*(?==(?!>))", + "captures": { + "1": { "name": "keyword.declaration.function.effekt" }, + "2": { "name": "entity.name.function.effekt" } }, "patterns": [{ "include": "#parameters" }] }, { "match": "\\s*(val)\\s+([a-zA-Z][a-z-A-Z0-9_$]*)\\b", "captures": { - "1": { "name": "keyword.declaration.val" }, - "2": { "name": "variable" } + "1": { "name": "keyword.declaration.val.effekt" }, + "2": { "name": "variable.other.effekt" } } }, { - "match": "\\s*(var)\\s+([a-zA-Z][a-z-A-Z0-9_$]*)\\b", + "begin": "\\s*(var)\\s+([a-zA-Z][a-z-A-Z0-9_$]*)\\b", + "beginCaptures": { + "1": { "name": "keyword.declaration.var.effekt" }, + "2": { "name": "variable.other.effekt" } + }, + "end": "(?:;|(?=\\n)|(?<=\\S)\\s*(?==(?!>)))", + "patterns": [{ + "match": "\\s+(in)\\s+([a-zA-Z][a-z-A-Z0-9_$]*)\\b", + "captures": { + "1": { "name": "keyword.other.in.effekt" }, + "2": { + "patterns": [{ + "match": "global", + "name": "support.constant.effekt variable.other.capability.effekt entity.name.region.effekt" + }, { + "match": "[a-zA-Z][a-z-A-Z0-9_$]*", + "name": "variable.other.capability.effekt entity.name.region.effekt" + }] + } + } + }, { + "include": "#parameters" + }] + }, { + "match": "\\s*(extern)?\\s*(type|effect|interface|resource)\\s+([a-zA-Z][a-z-A-Z0-9_$]*)\\b", "captures": { - "1": { "name": "keyword.declaration.var" }, - "2": { "name": "variable" } + "1": { "name": "storage.modifier.extern.effekt" }, + "2": { "name": "keyword.declaration.type.effekt" }, + "3": { "name": "entity.name.type.effekt" } } }, { - "match": "\\s*(extern)?\\s*(type|effect|interface|resource)\\s+([a-zA-Z][a-z-A-Z0-9_$]*)\\b", + "match": "\\s*(namespace)\\s+([a-zA-Z][a-z-A-Z0-9_$]*)\\b", + "captures": { + "1": { "name": "keyword.declaration.namespace.effekt" }, + "2": { "name": "entity.name.namespace.effekt" } + } + }, { + "match": "\\s*(module)\\s+((?:[a-zA-Z][a-zA-Z0-9_]*(?:/[a-zA-Z][a-zA-Z0-9_]*)*))\\b", + "captures": { + "1": { "name": "keyword.declaration.module.effekt" }, + "2": { "name": "entity.name.module.effekt" } + } + }, { + "match": "\\s*(import)\\s+((?:[a-zA-Z][a-zA-Z0-9_]*(?:/[a-zA-Z][a-zA-Z0-9_]*)*))\\b", "captures": { - "1": { "name": "keyword.declaration.type" }, - "2": { "name": "keyword.declaration.type" }, - "3": { "name": "entity.name.type" } + "1": { "name": "keyword.other.import.effekt" }, + "2": { "name": "entity.name.module.import.effekt" } } }] }, + "boxed_types": { + "comment": "Used for boxed types like 'at {}', 'at {io}', 'at {io, global}', etc.", + "patterns": [{ + "begin": "\\b(at)\\s*\\{", + "beginCaptures": { + "1": { "name": "keyword.other.at.effekt" } + }, + "end": "\\}", + "patterns": [{ + "include": "#capabilities" + }] + }] + }, "parameters": { "patterns": [{ + "include": "#boxed_types" + }, { "match": "\\b([a-z][a-zA-Z0-9_$]*)(?:)", - "name": "variable.parameter" + "name": "variable.parameter.effekt" }, { "match": "\\b([A-Z][a-zA-Z0-9_$]*)(?:)", - "name": "entity.name.type" + "name": "entity.name.type.effekt" + }] + }, + "capabilities": { + "patterns": [{ + "match": "\\b(pure)\\b", + "name": "keyword.other.capability.pure.effekt" + }, { + "match": "\\b(io)\\b", + "name": "support.constant.effekt variable.other.capability.effekt" + }, { + "match": "\\b(global)\\b", + "name": "support.constant.effekt variable.other.capability.effekt entity.name.region.effekt" + }, { + "match": "\\b([a-z][a-zA-Z0-9_]*)\\b", + "name": "variable.other.capability.effekt" + }, { + "match": ",", + "name": "punctuation.separator.capability.effekt" }] }, "keywords": { "patterns": [{ - "match": "\\b(module|import|def|fun|val|var|effect|type|match|case|record|extern|include|box|unbox|in|region|new|resource|interface|namespace|module|include|export|as)\\b", - "name": "keyword.syntax" + "match": "\\b(module|import|def|fun|val|var|effect|type|record|box|unbox|region|new|resource|interface|namespace|module|include|export)\\b", + "name": "keyword.other.effekt" + }, { + "match": "\\b(return)\\b", + "name": "keyword.control.jump.effekt" }, { - "match": "\\b(resume|while|try|with|if|else|do|return|is|and)\\b", - "name": "keyword.control" + "match": "\\b(do|resume|try|with)\\b", + "name": "keyword.control.effect.effekt" + }, { + "match": "\\b(while|match|case|if|else|is|and)\\b", + "name": "keyword.control.flow.effekt" + }, { + "match": "\\b(extern)\\b", + "name": "storage.modifier.extern.effekt" }] }, - "names": { + "literals": { "patterns": [{ "match": "\\b(true|false)\\b", - "name": "constant.language" + "name": "constant.language.boolean.effekt" }, { - "match": "\\b([a-z][a-zA-Z0-9_]*)\\b[\\s]*[({\\[]", - "captures": { - "1": { "name": "entity.name.function" } - } + "match": "\\b([0-9]+\\.[0-9]+)\\b", + "name": "constant.numeric.float.effekt" }, { - "match": "\\b[a-z][a-zA-Z0-9_]*\\b", - "name": "variable" + "match": "\\b([0-9]+)\\b", + "name": "constant.numeric.integer.effekt" }, { - "match": "\\b[A-Z][a-zA-Z0-9_]*\\b", - "name": "entity.name.type" + "include": "#characters" + }, { + "include": "#strings" + }] + }, + "characters": { + "name": "string.quoted.single.effekt", + "begin": "'", + "end": "'", + "patterns": [{ + "include": "#escapes" + }, { + "include": "#invalidEscapes" }] }, "strings": { "patterns": [{ + "name": "string.quoted.triple.effekt", + "begin": "\"\"\"", + "end": "\"\"\"", + "comment": "Important: only single-line strings can have escapes!", + "patterns": [{ + "include": "#stringTemplates" + }] + }, { + "name": "string.quoted.double.effekt", "begin": "\"", "end": "\"", - "name": "string.quoted.double.literal" + "patterns": [{ + "include": "#escapes" + }, { + "include": "#invalidEscapes" + }, { + "include": "#stringTemplates" + }] }] }, - "numbers": { + "escapes": { + "match": "\\\\([btnfr\\\\\"']|u[0-9A-Fa-f]{4})", + "name": "constant.character.escape.effekt" + }, + "invalidEscapes": { + "match": "\\\\.", + "name": "invalid.illegal.unknown-escape.effekt", + "comment": "Represents any possible escape, therefore should always be used _after_ #escapes!" + }, + "names": { "patterns": [{ - "match": "\\b[0-9]+", - "name": "constant.numeric" + "match": "\\b([a-z][a-zA-Z0-9_]*)\\b[\\s]*[({\\[]", + "captures": { + "1": { "name": "entity.name.function.effekt" } + } + }, { + "match": "\\b[a-z][a-zA-Z0-9_]*\\b", + "name": "variable.other.effekt" + }, { + "match": "\\b[A-Z][a-zA-Z0-9_]*\\b", + "name": "entity.name.type.effekt" }] }, + "stringTemplates": { + "begin": "\\$\\{", + "beginCaptures": { + "0": { "name": "punctuation.definition.template-expression.begin.effekt" } + }, + "end": "\\}", + "endCaptures": { + "0": { "name": "punctuation.definition.template-expression.end.effekt" } + }, + "name": "meta.embedded.line.effekt", + "patterns": [ + { "include": "$self" } + ] + }, "punctuation": { "patterns": [{ "match": "[{}\\(\\)\\[\\];,]", - "name": "punctuation.separator" + "name": "punctuation.separator.effekt" }] }, "holes": { + "begin": "<{", + "end": "}>", + "name": "meta.hole.effekt", "patterns": [{ - "begin": "<{", - "end" : "}>", - "name": "effekt.hole", - "patterns": [{ - "include": "source.effekt" - }] + "include": "$self" + }] + }, + "operators": { + "patterns": [{ + "match": "\\|\\||&&", + "name": "keyword.operator.logical.effekt" + }, { + "match": "==|!=|<=|>=|<|>", + "name": "keyword.operator.comparison.effekt" + }, { + "match": "\\+\\+", + "name": "keyword.operator.concatenation.effekt" + }, { + "match": "\\+|-|\\*|/", + "name": "keyword.operator.arithmetic.effekt" + }, { + "match": "::", + "name": "keyword.operator.namespace.effekt" + }, { + "match": "=>", + "name": "keyword.operator.arrow.effekt" + }] + }, + "regions": { + "patterns": [{ + "match": "\\b(region)\\s+([a-zA-Z][a-zA-Z0-9_]*)\\b", + "captures": { + "1": { "name": "keyword.other.region.effekt" }, + "2": { "name": "variable.other.capability.effekt entity.name.region.effekt" } + } }] } },