From 0c8e036de8d668b68d7676cceb5650c467b9a43c Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 7 Nov 2022 09:44:26 +0000 Subject: [PATCH] Added vscode syntax highlighting under /tools --- scripts/fib.toy | 4 +- .../.vscode/launch.json | 17 ++++ .../toylang.vscode-highlighting/.vscodeignore | 4 + .../toylang.vscode-highlighting/CHANGELOG.md | 2 + tools/toylang.vscode-highlighting/README.md | 8 ++ .../language-configuration.json | 28 ++++++ .../toylang.vscode-highlighting/package.json | 25 ++++++ .../syntaxes/toy.tmLanguage.json | 85 +++++++++++++++++++ 8 files changed, 171 insertions(+), 2 deletions(-) create mode 100644 tools/toylang.vscode-highlighting/.vscode/launch.json create mode 100644 tools/toylang.vscode-highlighting/.vscodeignore create mode 100644 tools/toylang.vscode-highlighting/CHANGELOG.md create mode 100644 tools/toylang.vscode-highlighting/README.md create mode 100644 tools/toylang.vscode-highlighting/language-configuration.json create mode 100644 tools/toylang.vscode-highlighting/package.json create mode 100644 tools/toylang.vscode-highlighting/syntaxes/toy.tmLanguage.json diff --git a/scripts/fib.toy b/scripts/fib.toy index 1020a13..0c3e342 100644 --- a/scripts/fib.toy +++ b/scripts/fib.toy @@ -6,7 +6,7 @@ fn fib(n : int) { return fib(n-1) + fib(n-2); } -for (var i = 0; i < 40; i++) { +for (var i = 0; i < 20; i++) { var res = fib(i); - print (string)i + ": " + (string)res; + print string i + ": " + string res; } \ No newline at end of file diff --git a/tools/toylang.vscode-highlighting/.vscode/launch.json b/tools/toylang.vscode-highlighting/.vscode/launch.json new file mode 100644 index 0000000..0e191b5 --- /dev/null +++ b/tools/toylang.vscode-highlighting/.vscode/launch.json @@ -0,0 +1,17 @@ +// A launch configuration that launches the extension inside a new window +// Use IntelliSense to learn about possible attributes. +// Hover to view descriptions of existing attributes. +// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Extension", + "type": "extensionHost", + "request": "launch", + "args": [ + "--extensionDevelopmentPath=${workspaceFolder}" + ] + } + ] +} \ No newline at end of file diff --git a/tools/toylang.vscode-highlighting/.vscodeignore b/tools/toylang.vscode-highlighting/.vscodeignore new file mode 100644 index 0000000..f369b5e --- /dev/null +++ b/tools/toylang.vscode-highlighting/.vscodeignore @@ -0,0 +1,4 @@ +.vscode/** +.vscode-test/** +.gitignore +vsc-extension-quickstart.md diff --git a/tools/toylang.vscode-highlighting/CHANGELOG.md b/tools/toylang.vscode-highlighting/CHANGELOG.md new file mode 100644 index 0000000..293c568 --- /dev/null +++ b/tools/toylang.vscode-highlighting/CHANGELOG.md @@ -0,0 +1,2 @@ +# Change Log + diff --git a/tools/toylang.vscode-highlighting/README.md b/tools/toylang.vscode-highlighting/README.md new file mode 100644 index 0000000..ae5f800 --- /dev/null +++ b/tools/toylang.vscode-highlighting/README.md @@ -0,0 +1,8 @@ +# Toy vscode Highlighting + +This is included in the core repo under `/tools`, and is supposed to make your time writing Toy code easier. + +## Installing + +Just copy the whole folder into the extensions folder for VSCode. + diff --git a/tools/toylang.vscode-highlighting/language-configuration.json b/tools/toylang.vscode-highlighting/language-configuration.json new file mode 100644 index 0000000..bdf8382 --- /dev/null +++ b/tools/toylang.vscode-highlighting/language-configuration.json @@ -0,0 +1,28 @@ +{ + "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/tools/toylang.vscode-highlighting/package.json b/tools/toylang.vscode-highlighting/package.json new file mode 100644 index 0000000..69f4bd2 --- /dev/null +++ b/tools/toylang.vscode-highlighting/package.json @@ -0,0 +1,25 @@ +{ + "name": "toy-syntax-highlighting", + "displayName": "Toy Syntax Highlighting", + "description": "A toy programming language", + "version": "0.0.1", + "engines": { + "vscode": "^1.73.0" + }, + "categories": [ + "Programming Languages" + ], + "contributes": { + "languages": [{ + "id": "toy", + "aliases": ["Toy", "toy"], + "extensions": [".toy"], + "configuration": "./language-configuration.json" + }], + "grammars": [{ + "language": "toy", + "scopeName": "source.toy", + "path": "./syntaxes/toy.tmLanguage.json" + }] + } +} diff --git a/tools/toylang.vscode-highlighting/syntaxes/toy.tmLanguage.json b/tools/toylang.vscode-highlighting/syntaxes/toy.tmLanguage.json new file mode 100644 index 0000000..743a5a4 --- /dev/null +++ b/tools/toylang.vscode-highlighting/syntaxes/toy.tmLanguage.json @@ -0,0 +1,85 @@ +{ + "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", + "name": "Toy", + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#keywords" + }, + { + "include": "#strings" + }, + { + "include": "#numbers" + }, + { + "include": "#booleans" + }, + { + "include": "#null" + }, + { + "include": "#reserved" + } + ], + "repository": { + "comments": { + "patterns": [{ + "name": "comment.line.toy", + "begin": "\/\/", + "end": "\\n" + }, + { + "name": "comment.block.toy", + "begin": "/\\*", + "end": "\\*/" + }] + }, + "keywords": { + "patterns": [{ + "name": "keyword.control.toy", + "match": "\\b(if|else|while|for|return|break|continue)\\b" + }, + { + "name": "keyword.type.toy", + "match": "\\b(any|bool|const|float|int|string|type)\\b" + }, + { + "name": "keyword.other.toy", + "match": "\\b(as|astype|assert|export|fn|import|print|typeof|var)\\b" + }] + }, + "strings": { + "name": "string.quoted.double.toy", + "begin": "\"", + "end": "\"" + }, + "numbers": { + "patterns": [{ + "match": "[-]?[0-9]+(.[0-9]+)?", + "name": "constant.numeric.toy" + }] + }, + "booleans": { + "patterns": [{ + "match": "\\b(true|false)\\b", + "name": "constant.numeric.toy" + }] + }, + "null": { + "patterns": [{ + "match": "\\b(null)\\b", + "name": "constant.numeric.toy" + }] + }, + "reserved": { + "patterns": [{ + "name": "keyword.reserved.toy", + "match": "\\b(class|do|foreach|in|of)\\b" + }] + } + }, + "scopeName": "source.toy" +} \ No newline at end of file