From cc8278b4f5177fa4234c4858dba266151baefb21 Mon Sep 17 00:00:00 2001 From: Andreas <38031952+AnHeuermann@users.noreply.github.com> Date: Fri, 30 Jun 2023 16:06:52 +0200 Subject: [PATCH] String escape and mos snippets (#3) * String escape for modelica * Better template definition highlighting * MOS scripting highlighting improved - MOS script snippets - MOS script API functions highlighting --- CHANGELOG.md | 6 + README.md | 2 +- package.json | 6 +- snippets/snippets_script.json | 139 ++++++ syntaxes/modelica.tmGrammar.yaml | 12 +- syntaxes/script.tmGrammar.yaml | 710 ++++++++++++++++++++++++++++++- syntaxes/susan.tmGrammar.yaml | 61 ++- 7 files changed, 899 insertions(+), 37 deletions(-) create mode 100644 snippets/snippets_script.json diff --git a/CHANGELOG.md b/CHANGELOG.md index c8aea05..9e2cef3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Change Log All notable changes to the "MetaModelica" extension will be documented in this file. +## [1.1.0] - 2023-06-30 + + - MOS script snippets + - MOS script API functions highlighting + - Fixed string escapes + ## [1.0.0] - 2023-06-29 - Fixed syntax highlighting for Susan template language diff --git a/README.md b/README.md index 239373d..0726901 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ possible snippets to choose from. Use the provided dev container to build and publish the extension. See [https://code.visualstudio.com/api/working-with-extensions/publishing-extension#installation](code.visualstudio.com/api/working-with-extensions/publishing-extension). -Generate .vsix pacakge file: +Generate .vsix package file: ```bash npx vsce package ``` diff --git a/package.json b/package.json index 4296884..96a77a0 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "metamodelica", "displayName": "MetaModelica", "description": "MetaModelica, Susan and Modelica language support.", - "version": "1.0.0", + "version": "1.1.0", "publisher": "AnHeuermann", "license": "See LICENSE.txt", "engines": { @@ -118,6 +118,10 @@ { "language": "metamodelica", "path": "./snippets/snippets.json" + }, + { + "language": "openmodelica-script", + "path": "./snippets/snippets_script.json" } ] }, diff --git a/snippets/snippets_script.json b/snippets/snippets_script.json new file mode 100644 index 0000000..94b8879 --- /dev/null +++ b/snippets/snippets_script.json @@ -0,0 +1,139 @@ +{ + "API function getErrorString": { + "prefix": "getErrorString", + "body": "getErrorString();", + "scope": "source.openmodelica-script" + }, + + "Minimal Working Example": { + "prefix": "loadModel", + "body": [ + "loadModel(Modelica, {\"4.0\"}); getErrorString();", + "loadString(\"", + " model M", + " $1", + " end M;", + "\"); getErrorString();", + "simulate(M); getErrorString();" + ], + "scope": "source.openmodelica-script" + }, + + "API function simulate (full)": { + "prefix": "simulate", + "body": [ + "simulate($1,", + " startTime = 0.0,", + " stopTime = 1.0,", + " numberOfIntervals = 500", + " tolerance = 1e-6", + " method = \"dassl\"", + " fileNamePrefix = \"\"", + " options = \"\"", + " outputFormat = \"mat\"", + " variableFilter = \".*\"", + " cflags = \"\"", + " simflags = \"\");", + "getErrorString();" + ], + "scope": "source.openmodelica-script" + }, + + "API function simulate": { + "prefix": "simulate", + "body": [ + "simulate($1);", + "getErrorString();" + ], + "scope": "source.openmodelica-script" + }, + + "API function buildModel (full)": { + "prefix": "buildModel", + "body": [ + "buildModel($1,", + " startTime = \"\",", + " stopTime = 1.0,", + " numberOfIntervals = 500,", + " tolerance = 1e-6,", + " method = \"dassl\",", + " fileNamePrefix = \"\",", + " options = \"\",", + " outputFormat = \"mat\",", + " variableFilter = \".*\",", + " cflags = \"\",", + " simflags = \"\");", + "getErrorString();" + ], + "scope": "source.openmodelica-script" + }, + + "API function buildModel": { + "prefix": "buildModel", + "body": [ + "buildModel($1);", + "getErrorString();" + ], + "scope": "source.openmodelica-script" + }, + + "API function buildModelFMU (full)": { + "prefix": "buildModelFMU", + "body": [ + "buildModelFMU($1", + " version = \"2.0\",", + " fmuType = \"me\"", + " fileNamePrefix = \"\",", + " platforms = {\"static\"},", + " includeResources = false);", + "getErrorString();" + ], + "scope": "source.openmodelica-script" + }, + + "API function buildModelFMU": { + "prefix": "buildModelFMU", + "body": [ + "buildModelFMU($1);", + "getErrorString();" + ], + "scope": "source.openmodelica-script" + }, + + "API function loadFile": { + "prefix": "loadFile", + "body": [ + "loadFile(\"$1\");", + "getErrorString();" + ], + "scope": "source.openmodelica-script" + }, + + "API function loadModel (full)": { + "prefix": "loadModel", + "body": [ + "loadModel($1,", + " priorityVersion = {\"default\"});", + "getErrorString();" + ], + "scope": "source.openmodelica-script" + }, + + "API function loadModel": { + "prefix": "loadModel", + "body": [ + "loadModel($1, {\"$2\"});", + "getErrorString();" + ], + "scope": "source.openmodelica-script" + }, + + "API function setCommandLineOptions": { + "prefix": "setCommandLineOptions", + "body": [ + "setCommandLineOptions(\"$1\");", + "getErrorString();" + ], + "scope": "source.openmodelica-script" + } +} \ No newline at end of file diff --git a/syntaxes/modelica.tmGrammar.yaml b/syntaxes/modelica.tmGrammar.yaml index 09f38c5..7bfadc7 100644 --- a/syntaxes/modelica.tmGrammar.yaml +++ b/syntaxes/modelica.tmGrammar.yaml @@ -68,15 +68,19 @@ patterns: name: comment.line # Strings - - begin: '"' - end: '"' + - begin: '(?' - name: storage.type - match: \b(uniontype)\s+(\w+)\s*(".*")* captures: 1: @@ -35,7 +27,7 @@ patterns: name: string.quoted.double # Keywords - - match: ::=|\|\>|=\> + - match: \|\>|=\> name: keyword.control - match: \=|\+\= name: keyword.operator.assignment @@ -51,22 +43,30 @@ patterns: name: storage.modifier # Block definitions - - match: (\b(template)\b\s+\w+\s*(".*")*) - captures: - 1: + - begin: \b(template)\b + beginCaptures: + - name: keyword + end: "::=" + endCaptures: + - name: keyword.control + patterns: + - match: \b(\w+)\b\( name: entity.name.function - 2: - name: keyword - 3: - name: comment.line - - match: \b(end)\b(\s+\w+\s*); + - begin: '\(' + end: '\)' + name: keyword + - include: '#comments' + - include: '#types' + + - begin: '(?' + name: storage.type + strings: patterns: - begin: '<<' @@ -130,6 +148,7 @@ repository: name: meta.embedded patterns: - include: $self + escapes: match: '\\(x\h{2}|[0-2][0-7]{0,2}|3[0-6][0-7]|37[0-7]?|[4-7][0-7]?|.)' name: constant.character.escape