From 9a59f2c4f6402002877a9ce6c7e79897b54b72cf Mon Sep 17 00:00:00 2001 From: Andrew Hodges Date: Tue, 3 Sep 2019 15:53:38 -0400 Subject: [PATCH] It's working, but still needs a lot of work --- language-configuration.json | 88 +++- package.json | 39 +- syntaxes/cue.tmLanguage.json | 848 ++++++++++++++++++++++++++++++++++- 3 files changed, 934 insertions(+), 41 deletions(-) diff --git a/language-configuration.json b/language-configuration.json index aa25710..559cfe5 100644 --- a/language-configuration.json +++ b/language-configuration.json @@ -3,28 +3,86 @@ // symbol used for single line comment. Remove this entry if your language does not support line comments "lineComment": "//", // symbols used for start and end a block comment. Remove this entry if your language does not support block comments - "blockComment": [ "/*", "*/" ] + "blockComment": [ + "/*", + "*/" + ] }, // symbols used as brackets "brackets": [ - ["{", "}"], - ["[", "]"], - ["(", ")"] + [ + "{", + "}" + ], + [ + "[", + "]" + ], + [ + "(", + ")" + ], + [ + "<", + ">" + ] ], // symbols that are auto closed when typing "autoClosingPairs": [ - ["{", "}"], - ["[", "]"], - ["(", ")"], - ["\"", "\""], - ["'", "'"] + [ + "{", + "}" + ], + [ + "[", + "]" + ], + [ + "(", + ")" + ], + [ + "\"", + "\"" + ], + [ + "'", + "'" + ], + [ + "`", + "`" + ] ], // symbols that that can be used to surround a selection "surroundingPairs": [ - ["{", "}"], - ["[", "]"], - ["(", ")"], - ["\"", "\""], - ["'", "'"] + [ + "{", + "}" + ], + [ + "[", + "]" + ], + [ + "(", + ")" + ], + [ + "\"", + "\"" + ], + [ + "'", + "'" + ], + [ + "`", + "`" + ], + [ + "#", + "#" + ], ] -} \ No newline at end of file +} diff --git a/package.json b/package.json index 97ce302..4cf205b 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,9 @@ { "name": "cue", "displayName": "CUE", - "description": "Basic support for the CUE configuration language.", + "description": "CUE language support for Visual Studio Code", "version": "0.0.1", + "publisher": "cuelang.org", "engines": { "vscode": "^1.37.0" }, @@ -10,16 +11,28 @@ "Programming Languages" ], "contributes": { - "languages": [{ - "id": "cue", - "aliases": ["CUE", "cue"], - "extensions": [".cue"], - "configuration": "./language-configuration.json" - }], - "grammars": [{ - "language": "cue", - "scopeName": "source.cue", - "path": "./syntaxes/cue.tmLanguage.json" - }] + "languages": [ + { + "id": "cue", + "aliases": [ + "CUE", + "cue" + ], + "extensions": [ + ".cue" + ], + "configuration": "./language-configuration.json" + } + ], + "grammars": [ + { + "language": "cue", + "scopeName": "source.cue", + "path": "./syntaxes/cue.tmLanguage.json", + "embeddedLanguages": { + "source.cue.embedded": "source.cue" + } + } + ] } -} \ No newline at end of file +} diff --git a/syntaxes/cue.tmLanguage.json b/syntaxes/cue.tmLanguage.json index 9963b0a..5b15465 100644 --- a/syntaxes/cue.tmLanguage.json +++ b/syntaxes/cue.tmLanguage.json @@ -3,30 +3,852 @@ "name": "CUE", "patterns": [ { - "include": "#keywords" + "include": "#comment" }, { - "include": "#strings" + "include": "#package" + }, + { + "include": "#import" + }, + { + "include": "#declaration" + }, + { + "include": "#comma" + }, + { + "include": "#ellipsis" + }, + { + "include": "#invalid" } ], "repository": { - "keywords": { - "patterns": [{ - "name": "keyword.control.cue", - "match": "\\b(if|while|for|return)\\b" - }] + "arrow": { + "match": "<-", + "name": "keyword.operator" + }, + "attribute": { + "patterns": [ + { + "begin": "(@)([_\\p{L}][_\\p{L}\\p{Nd}]*)(\\()", + "beginCaptures": { + "1": { + "name": "punctuation.definition.annotation" + }, + "2": { + "name": "meta.annotation.identifier" + }, + "3": { + "name": "punctuation.definition.annotation" + } + }, + "end": "\\)", + "endCaptures": { + "0": { + "name": "punctuation.definition.annotation" + } + }, + "contentName": "meta.annotation.parameters", + "patterns": [ + { + "include": "#attribute_element" + } + ], + "name": "meta.annotation" + }, + { + "match": "@[^,/]+", + "name": "invalid.illegal" + } + ] }, - "strings": { - "name": "string.quoted.double.cue", - "begin": "\"", - "end": "\"", + "attribute_element": { "patterns": [ { - "name": "constant.character.escape.cue", + "include": "#attribute_nested" + }, + { + "include": "#attribute_label" + }, + { + "include": "#attribute_string" + }, + { + "match": "[^,\\)]+", + "name": "invalid.illegal" + }, + { + "match": ",", + "name": "punctuation.separator" + } + ] + }, + "attribute_label": { + "match": "([_\\p{L}][_\\p{L}\\p{Nd}]*)(=)([^,\\)]+)", + "captures": { + "1": { + "name": "meta.annotation.identifier" + }, + "2": { + "name": "punctuation.definition.annotation" + }, + "3": { + "patterns": [ + { + "include": "#attribute_string" + }, + { + "include": "#invalid" + } + ], + "name": "meta.annotation.parameters" + } + } + }, + "attribute_nested": { + "begin": "([_\\p{L}][_\\p{L}\\p{Nd}]*)(\\()", + "beginCaptures": { + "1": { + "name": "meta.annotation.identifier" + }, + "2": { + "name": "punctuation.definition.annotation" + } + }, + "end": "\\)", + "endCaptures": { + "0": { + "name": "punctuation.definition.annotation" + } + }, + "contentName": "meta.annotation.parameters", + "patterns": [ + { + "include": "#attribute_element" + } + ] + }, + "attribute_string": { + "patterns": [ + { + "match": "[^\\n,\"'#=()]+", + "name": "string.unquoted" + }, + { + "include": "#string" + } + ] + }, + "bool": { + "match": "\\b(true|false)\\b", + "name": "constant.language.boolean" + }, + "bottom": { + "match": "_\\|_", + "name": "constant.language.bottom" + }, + "call": { + "begin": "\\b(len|close|and|or)(\\()", + "beginCaptures": { + "1": { + "name": "support.function" + }, + "2": { + "name": "punctuation.section.parens.begin" + } + }, + "end": "\\)", + "endCaptures": { + "0": { + "name": "punctuation.section.parens.end" + } + }, + "patterns": [ + { + "include": "#expression" + } + ], + "name": "meta.function-call" + }, + "comma": { + "match": ",", + "name": "punctuation.separator" + }, + "comment": { + "patterns": [ + { + "include": "#comment_line" + }, + { + "include": "#comment_block" + } + ] + }, + "comment_block": { + "begin": "/\\*", + "end": "\\*/", + "captures": { + "0": { + "name": "punctuation.definition.comment" + } + }, + "name": "comment.block" + }, + "comment_line": { + "match": "(//).*$\\n?", + "captures": { + "1": { + "name": "punctuation.definition.comment" + } + }, + "name": "comment.line" + }, + "comprehension": {}, + "declaration": { + "patterns": [ + { + "include": "#field" + }, + { + "include": "#definition" + }, + { + "include": "#alias" + }, + { + "include": "#comprehension" + }, + { + "include": "#embedding" + } + ] + }, + "definition": { + "begin": "([^:?]+)(\\?)?(::)", + "beginCaptures": { + "1": { + "patterns": [ + { + "include": "#identifier" + }, + { + "include": "#string" + } + ] + }, + "2": { + "name": "punctuation" + }, + "3": { + "name": "punctuation" + } + }, + "end": "(,)|(?=//)|$", + "endCaptures": { + "1": { + "name": "punctuation.separator" + } + }, + "patterns": [ + { + "include": "#expression" + }, + { + "include": "#attribute" + }, + { + "include": "#invalid" + } + ] + }, + "ellipsis": { + "match": "\\.{3}", + "name": "punctuation" + }, + "embedding": {}, + "escape_0": { + "patterns": [ + { + "name": "constant.character.escape", + "match": "\\\\(?:[abfnrtv]|\\\\|\\/|x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8}|[0-7]{3})" + }, + { + "begin": "\\\\\\(", + "beginCaptures": { + "0": { + "name": "punctuation.section.interpolation.begin" + } + }, + "end": "\\)", + "endCaptures": { + "0": { + "name": "punctuation.section.interpolation.end" + } + }, + "patterns": [ + { + "include": "$self" + } + ], + "contentName": "source.cue.embedded", + "name": "meta.interpolation" + }, + { + "name": "invalid.illegal", "match": "\\\\." } ] + }, + "escape_0_double": { + "name": "constant.character.escape", + "match": "\\\\\"" + }, + "escape_0_single": { + "name": "constant.character.escape", + "match": "\\\\'" + }, + "escape_1": { + "patterns": [ + { + "name": "constant.character.escape", + "match": "\\\\#(?:[abfnrtv]|\\\\|\\/|x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8}|[0-7]{3})" + }, + { + "begin": "\\\\#\\(", + "beginCaptures": { + "0": { + "name": "punctuation.section.interpolation.begin" + } + }, + "end": "\\)", + "endCaptures": { + "0": { + "name": "punctuation.section.interpolation.end" + } + }, + "patterns": [ + { + "include": "$self" + } + ], + "contentName": "source.cue.embedded", + "name": "meta.interpolation" + }, + { + "name": "invalid.illegal", + "match": "\\\\#." + } + ] + }, + "escape_1_double": { + "name": "constant.character.escape", + "match": "\\\\#\"" + }, + "escape_1_single": { + "name": "constant.character.escape", + "match": "\\\\#'" + }, + "expression": { + "patterns": [ + { + "include": "#literal" + }, + { + "include": "#operator" + }, + { + "include": "#type" + }, + { + "include": "#identifier" + } + ] + }, + "field": { + "begin": "([^:?]+)(\\?)?(:)(?!:)", + "beginCaptures": { + "1": { + "patterns": [ + { + "include": "#identifier" + }, + { + "include": "#string" + } + ] + }, + "2": { + "name": "punctuation" + }, + "3": { + "name": "punctuation" + } + }, + "end": "(,)|(?=//)|$", + "endCaptures": { + "1": { + "name": "punctuation.separator" + } + }, + "patterns": [ + { + "include": "#expression" + }, + { + "include": "#attribute" + }, + { + "include": "#invalid" + } + ] + }, + "float": { + "patterns": [ + { + "match": "(?=?|[=!]~", + "name": "keyword.operator" + }, + { + "match": "!", + "name": "keyword.operator.logical" + }, + { + "match": "[\\-\\+\\*\\/]", + "name": "keyword.operator.arithmetic" + }, + { + "match": "\\b(div|mod|quo|rem)\\b", + "name": "keyword.operator.word" + } + ] + }, + "package": { + "match": "\\b(package)[ \\t]+([_\\p{L}][_\\p{L}\\p{Nd}]*)", + "captures": { + "1": { + "name": "keyword.other.package" + }, + "2": { + "name": "entity.name.namespace" + } + } + }, + "string": { + "patterns": [ + { + "include": "#string_1_double" + }, + { + "include": "#string_1_single" + }, + { + "include": "#string_0_double" + }, + { + "include": "#string_0_single" + } + ] + }, + "string_0_double": { + "begin": "\"{3}|\"", + "beginCaptures": { + "0": { + "name": "punctuation.definition.string.begin" + } + }, + "end": "\\0", + "endCaptures": { + "0": { + "name": "punctuation.definition.string.end" + } + }, + "patterns": [ + { + "include": "#escape_0_double" + }, + { + "include": "#escape_0" + } + ], + "contentName": "string.quoted.double", + "name": "meta.string" + }, + "string_0_single": { + "begin": "'{3}|'", + "beginCaptures": { + "0": { + "name": "punctuation.definition.string.begin" + } + }, + "end": "\\0", + "endCaptures": { + "0": { + "name": "punctuation.definition.string.end" + } + }, + "patterns": [ + { + "include": "#escape_0_single" + }, + { + "include": "#escape_0" + } + ], + "contentName": "string.quoted.single", + "name": "meta.string" + }, + "string_1_double": { + "begin": "#(\"{3}|\")", + "beginCaptures": { + "0": { + "name": "punctuation.definition.string.begin" + } + }, + "end": "\\1#", + "endCaptures": { + "0": { + "name": "punctuation.definition.string.end" + } + }, + "patterns": [ + { + "include": "#escape_1_double" + }, + { + "include": "#escape_1" + } + ], + "contentName": "string.quoted.other", + "name": "meta.string" + }, + "string_1_single": { + "begin": "#('{3}|')", + "beginCaptures": { + "0": { + "name": "punctuation.definition.string.begin" + } + }, + "end": "\\1#", + "endCaptures": { + "0": { + "name": "punctuation.definition.string.end" + } + }, + "patterns": [ + { + "include": "#escape_1_single" + }, + { + "include": "#escape_1" + } + ], + "contentName": "string.quoted.other", + "name": "meta.string" + }, + "struct": { + "begin": "\\{", + "beginCaptures": { + "0": { + "name": "punctuation.section.block.begin" + } + }, + "end": "\\}", + "endCaptures": { + "0": { + "name": "punctuation.section.block.end" + } + }, + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#declaration" + }, + { + "include": "#comma" + }, + { + "include": "#ellipsis" + }, + { + "include": "#invalid" + } + ], + "name": "meta.block" + }, + "top": { + "match": "_(?![_\\|\\p{L}\\p{Nd}])", + "name": "constant.language.top" + }, + "type": { + "match": "\\b(bool|u?int(?:8|16|32|64|128)?|float(?:32|64)?|string|bytes|number|rune)\\b", + "name": "storage.type" } }, "scopeName": "source.cue" -} \ No newline at end of file +}