Browse Source

feat: VS Code support

Matthias Ladkau 3 years ago
parent
commit
f2ab07c742

+ 14 - 0
ecal-support/.vscode/launch.json

@@ -0,0 +1,14 @@
+// A launch configuration that launches the extension inside a new window
+{
+	"version": "0.2.0",
+    "configurations": [
+        {
+            "name": "Extension",
+            "type": "extensionHost",
+            "request": "launch",
+            "args": [
+                "--extensionDevelopmentPath=${workspaceFolder}"
+            ]
+        }
+    ]
+}

+ 3 - 0
ecal-support/.vscodeignore

@@ -0,0 +1,3 @@
+.vscode/**
+.vscode-test/**
+.gitignore

+ 11 - 0
ecal-support/README.md

@@ -0,0 +1,11 @@
+# VSCode extension for ECAL
+
+## Folder content
+
+* `package.json` - manifest file
+* `syntaxes/ecal.tmLanguage.json` - Text mate grammar file
+* `language-configuration.json` - language configuration for VSCode
+
+## Install the extension
+
+To start using your extension with Visual Studio Code copy it into the `<user home>/.vscode/extensions` folder and restart Code.

+ 28 - 0
ecal-support/language-configuration.json

@@ -0,0 +1,28 @@
+{
+    "comments": {
+        "lineComment": "#",
+        "blockComment": [ "/*", "*/" ]
+    },
+    // symbols used as brackets
+    "brackets": [
+        ["{", "}"],
+        ["[", "]"],
+        ["(", ")"]
+    ],
+    // symbols that are auto closed when typing
+    "autoClosingPairs": [
+        ["{", "}"],
+        ["[", "]"],
+        ["(", ")"],
+        ["\"", "\""],
+        ["'", "'"]
+    ],
+    // symbols that can be used to surround a selection
+    "surroundingPairs": [
+        ["{", "}"],
+        ["[", "]"],
+        ["(", ")"],
+        ["\"", "\""],
+        ["'", "'"]
+    ]
+}

+ 25 - 0
ecal-support/package.json

@@ -0,0 +1,25 @@
+{
+    "name": "ecal-support",
+    "displayName": "ECAL Support",
+    "description": "Support for the Event Condition Action Language (ECAL).",
+    "version": "0.0.1",
+    "engines": {
+        "vscode": "^1.50.0"
+    },
+    "categories": [
+        "Programming Languages"
+    ],
+    "contributes": {
+        "languages": [{
+            "id": "ecal",
+            "aliases": ["Event Condition Action Language", "ecal"],
+            "extensions": [".ecal"],
+            "configuration": "./ecal-support/language-configuration.json"
+        }],
+        "grammars": [{
+            "language": "ecal",
+            "scopeName": "source.ecal",
+            "path": "./ecal-support/syntaxes/ecal.tmLanguage.json"
+        }]
+    }
+}

+ 113 - 0
ecal-support/syntaxes/ecal.tmLanguage.json

@@ -0,0 +1,113 @@
+{
+	"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
+	"name": "Event Condition Action Language",
+	"patterns": [
+		{
+			"include": "#keywords"
+		}, {
+			"include": "#identifiers"
+		}, {
+			"include": "#strings"
+		}, {
+			"include": "#comments"
+		}
+	],
+	"repository": {
+		"keywords": {
+			"patterns": [{
+				"name": "keyword.control.import.ecal",
+				"match": "\\b(import|as)\\b"
+			}, {
+				"name": "keyword.control.sink.ecal",
+				"match": "\\b(sink|kindmatch|scopematch|statematch|priority|suppresses)\\b"
+			}, {
+				"name": "keyword.control.function.ecal",
+				"match": "\\b(func|return)\\b"
+			}, {
+				"name": "keyword.operator.boolean.ecal",
+				"match": "\\b(and|or|not)\\b"
+			}, {
+				"name": "keyword.operator.string.ecal",
+				"match": "\\b(like|hasprefix|hassuffic)\\b"
+			}, {
+				"name": "keyword.operator.list.ecal",
+				"match": "\\b(in|notin)\\b"
+			}, {
+				"name": "constant.language.terminals.ecal",
+				"match": "\\b(false|true|null)\\b"
+			}, {
+				"name": "keyword.control.conditional.ecal",
+				"match": "\\b(if|elif|else)\\b"
+			}, {
+				"name": "keyword.control.loop.ecal",
+				"match": "\\b(for|break|continue)\\b"
+			}, {
+				"name": "keyword.control.try.ecal",
+				"match": "\\b(try|except|finally)\\b"
+			}]
+		},
+		"identifiers": {
+			"patterns": [{
+				"match": "([a-z]+)\\(",
+				"captures": {
+					"1": {
+						"name": "entity.name.function.ecal"
+					}
+				}
+			}, {
+				"match": "([a-z]+) :?=",
+				"captures": {
+					"1": {
+						"name": "storage.type.var.ecal"
+					}
+				}
+			}]
+		},
+		"strings": {
+			"patterns": [{
+				"name": "string.quoted.double.ecal",
+				"begin": "r?\"",
+				"end": "\"",
+				"patterns": [{
+					"include" : "#escapes"
+				}]
+			}, {
+				"name": "string.quoted.single.ecal",
+				"begin": "r?'",
+				"end": "'",
+				"patterns": [{
+					"include" : "#escapes"
+				}]
+			}],
+			"repository" : {
+				"escapes" : {
+					"patterns": [
+						{
+							"name": "constant.character.escape.ecal",
+							"match": "\\\\."
+						}, {
+							"name": "constant.character.escape.ecal",
+							"begin": "{{",
+							"end": "}}"
+						}
+					]
+				}
+			}
+		},
+		"comments": {
+			"patterns": [
+				{
+					"name": "comment.block.ecal",
+					"begin": "/\\*",
+					"end": "\\*/"
+				},
+				{
+					"name": "comment.line.ecal",
+					"begin": "#",
+					"end": "\\n"
+				}
+			]
+		}
+	},
+	"scopeName": "source.ecal"
+}

+ 2 - 0
examples/fib/fib.ecal

@@ -1,5 +1,7 @@
 import "lib.ecal" as lib
 
+/* Print out fibonacci sequence */
+
 for a in range(2, 20, 2) {
   log("fib({{a}}) = ", lib.fib(a))
 }