From 012f258fa206d130f8ea3ed95d80ac7606e1e77a Mon Sep 17 00:00:00 2001 From: pyxel Date: Tue, 21 Dec 2021 16:50:33 -0500 Subject: [PATCH] add vscode syntax plugin --- resources/editor_plugins/vscode/.vscodeignore | 4 + resources/editor_plugins/vscode/example.c3 | 35 ++++ .../vscode/language-configuration.json | 30 ++++ resources/editor_plugins/vscode/package.json | 25 +++ .../vscode/syntaxes/c3.tmLanguage.json | 150 ++++++++++++++++++ 5 files changed, 244 insertions(+) create mode 100644 resources/editor_plugins/vscode/.vscodeignore create mode 100644 resources/editor_plugins/vscode/example.c3 create mode 100644 resources/editor_plugins/vscode/language-configuration.json create mode 100644 resources/editor_plugins/vscode/package.json create mode 100644 resources/editor_plugins/vscode/syntaxes/c3.tmLanguage.json diff --git a/resources/editor_plugins/vscode/.vscodeignore b/resources/editor_plugins/vscode/.vscodeignore new file mode 100644 index 000000000..f369b5e55 --- /dev/null +++ b/resources/editor_plugins/vscode/.vscodeignore @@ -0,0 +1,4 @@ +.vscode/** +.vscode-test/** +.gitignore +vsc-extension-quickstart.md diff --git a/resources/editor_plugins/vscode/example.c3 b/resources/editor_plugins/vscode/example.c3 new file mode 100644 index 000000000..d4670d485 --- /dev/null +++ b/resources/editor_plugins/vscode/example.c3 @@ -0,0 +1,35 @@ +module stack ; +// Above: the parameterized type is applied to the entire module. +import std::mem; + +struct Stack +{ + usize capacity; + usize size; + Type* elems; +} + +// The type methods offers dot syntax calls, +// so this function can either be called +// Stack.push(&my_stack, ...) or +// my_stack.push(...) +fn void Stack.push(Stack* this, Type element) +{ + if (this.capacity == this.size) + { + this.capacity *= 2; + this.elems = mem::realloc(this.elems, $sizeof(Type) * this.capacity); + } + this.elems[this.size++] = element; +} + +fn Type Stack.pop(Stack* this) +{ + assert(this.size > 0); + return this.elems[--this.size]; +} + +fn bool Stack.empty(Stack* this) +{ + return !this.size; +} diff --git a/resources/editor_plugins/vscode/language-configuration.json b/resources/editor_plugins/vscode/language-configuration.json new file mode 100644 index 000000000..8f162a0c4 --- /dev/null +++ b/resources/editor_plugins/vscode/language-configuration.json @@ -0,0 +1,30 @@ +{ + "comments": { + // 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": [ "/*", "*/" ] + }, + // symbols used as brackets + "brackets": [ + ["{", "}"], + ["[", "]"], + ["(", ")"] + ], + // symbols that are auto closed when typing + "autoClosingPairs": [ + ["{", "}"], + ["[", "]"], + ["(", ")"], + ["\"", "\""], + ["'", "'"] + ], + // symbols that can be used to surround a selection + "surroundingPairs": [ + ["{", "}"], + ["[", "]"], + ["(", ")"], + ["\"", "\""], + ["'", "'"] + ] +} \ No newline at end of file diff --git a/resources/editor_plugins/vscode/package.json b/resources/editor_plugins/vscode/package.json new file mode 100644 index 000000000..a41f9825b --- /dev/null +++ b/resources/editor_plugins/vscode/package.json @@ -0,0 +1,25 @@ +{ + "name": "c3-vscode", + "displayName": "c3-vscode", + "description": "C3 Language Support for VSCode", + "version": "0.0.1", + "engines": { + "vscode": "^1.63.0" + }, + "categories": [ + "Programming Languages" + ], + "contributes": { + "languages": [{ + "id": "c3", + "aliases": ["C3", "c3"], + "extensions": ["c3"], + "configuration": "./language-configuration.json" + }], + "grammars": [{ + "language": "c3", + "scopeName": "source.c3", + "path": "./syntaxes/c3.tmLanguage.json" + }] + } +} \ No newline at end of file diff --git a/resources/editor_plugins/vscode/syntaxes/c3.tmLanguage.json b/resources/editor_plugins/vscode/syntaxes/c3.tmLanguage.json new file mode 100644 index 000000000..ed74ba568 --- /dev/null +++ b/resources/editor_plugins/vscode/syntaxes/c3.tmLanguage.json @@ -0,0 +1,150 @@ +{ + "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", + "name": "C3", + "patterns": [ + { "include": "#keywords" }, + { "include": "#comments" }, + { "include": "#strings" }, + { "include": "#numbers" }, + { "include": "#types" }, + { "include": "#support" }, + { "include": "#operators" } + ], + "repository": { + "keywords": { + "patterns": [ + { + "name": "keyword", + "match": "\\b(extern|break|case|const|continue|default)\\b" + }, + { + "name": "keyword", + "match": "\\b(do|else|for|goto|if|return|null)\\b" + }, + { + "name": "keyword", + "match": "\\b(define|local|errtype|module|as|import)\\b" + }, + { + "name": "keyword", + "match": "\\b(generic|switch|typedef|volatile)\\b" + }, + { + "name": "keyword", + "match": "\\b(while|fn|nil|next|in|$for|$case)\\b" + }, + { + "name": "keyword", + "match": "\\b(%switch|$default|$if|$elif|$else)\\b" + }, + { + "name": "keyword", + "match": "\\b(true|false)\\b" + } + ] + }, + "comments": { + "patterns": [ + { + "name": "comment.line", + "begin": "//", + "end": "$" + }, + { + "name": "comment.block", + "begin": "/\\*", + "end": "\\*/" + } + ] + }, + "strings": { + "patterns": [ + { + "name": "string.quoted.double", + "patterns": [ {"include": "#stringcontent"} ], + "begin": "\"", + "end": "\"" + }, + { + "name": "string.quoted.double", + "patterns": [ {"include": "#stringcontent"} ], + "begin": "b64\"", + "end": "\"" + }, + { + "name": "string.quoted.double", + "patterns": [ {"include": "#stringcontent"} ], + "begin": "x\"", + "end": "\"" + }, + { + "name": "string.quoted.single", + "patterns": [ {"include": "#stringcontent"} ], + "begin": "'", + "end": "'" + }, + { + "name": "string.quoted.single", + "patterns": [ {"include": "#stringcontent"} ], + "begin": "b64'", + "end": "'" + }, + { + "name": "string.quoted.single", + "patterns": [ {"include": "#stringcontent"} ], + "begin": "x'", + "end": "'" + } + ] + }, + "stringcontent": { + "patterns": [ + { + "name": "constant.character.escape", + "match": "\\\\([nrt'\"\\\\]|(x[0-9a-fA-F]{2})|(u\\{[0-9a-fA-F]+\\}))" + }, + { + "name": "invalid.illegal.unrecognized-string-escape", + "match": "\\\\." + } + ] + }, + "numbers": { + "patterns": [ + { + "name": "constant.numeric", + "match": "\\b[0-9]\\.[0-9]+\\b" + }, + { + "name": "constant.numeric", + "match": "\\b[0-9]+\\b" + }, + { + "name": "constant.numeric", + "match": "\\b0x[a-fA-F0-9_]+\\b" + }, + { + "name": "constant.numeric", + "match": "\\b0o[0-7_]+\\b" + }, + { + "name": "constant.numeric", + "match": "\\b0b[01_]+\\b" + } + ] + }, + "types": { + "name": "storage.type", + "match": "\\b(double|usize|type|Type|bool|char|enum|float|int|uint|long|ulong|short|ushort|struct|void)\\b" + }, + "support": { + "name": "support.function.builtin", + "match": "\\$[_a-zA-Z][_a-zA-Z0-9]*" + }, + "operators": { + "name": "keyword.operator", + "match": "(\\+|-|\\.|%|&|\\||=|<|>|!|\\^|\\*|/|::)=?" + } + }, + "scopeName": "source.c3" +}