Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion org.omg.sysml.jupyter.installer/install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ call java -version || goto :error

echo --- Step 3: Installing Jupyter SysML kernel and dependencies ---
call jupyter kernelspec remove sysml -f >nul 2>&1
call conda install "jupyter-sysml-kernel=%SYSML_VERSION%" python=3.* jupyterlab=3.* graphviz=2.* nodejs="<17" -c conda-forge -y || goto:error
call conda install "jupyter-sysml-kernel=%SYSML_VERSION%" python=3.* jupyterlab=4.* graphviz=2.* nodejs -c conda-forge -y || goto:error

echo --- Step 4: Installing JupyterLab SysML extension ---
call jupyter labextension uninstall @systems-modeling/jupyterlab-sysml
Expand Down
2 changes: 1 addition & 1 deletion org.omg.sysml.jupyter.installer/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ java -version

echo "--- Step 3: Installing Jupyter SysML kernel and dependencies ---"
jupyter kernelspec remove sysml -f > /dev/null 2>&1 || true
conda install "jupyter-sysml-kernel=$SYSML_VERSION" python=3.* jupyterlab=3.* graphviz=2.* nodejs="<17" -c conda-forge -y
conda install "jupyter-sysml-kernel=$SYSML_VERSION" python=3.* jupyterlab=4.* graphviz=2.* nodejs -c conda-forge -y

echo "--- Step 4: Installing JupyterLab SysML extension ---"
jupyter labextension uninstall @systems-modeling/jupyterlab-sysml > /dev/null 2>&1 || true
Expand Down
3 changes: 2 additions & 1 deletion org.omg.sysml.jupyter.jupyterlab/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ build
data
log
scrap
.gradle
.gradle
yarn.lock
21 changes: 6 additions & 15 deletions org.omg.sysml.jupyter.jupyterlab/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,23 @@
"repository": "github:Systems-Modeling/SysML-v2-Pilot-Implementation",
"author": "SysML v2 Submission Team",
"license": "LGPL-3.0-or-later",
"main": "build/plugin.js",
"keywords": [
"jupyter",
"jupyterlab",
"jupyterlab-extension"
],
"dependencies": {
"@jupyterlab/application": "3.x"
"@jupyterlab/application": "4.x"
},
"devDependencies": {
"@types/codemirror": "^0.0.98",
"@codemirror/legacy-modes": "^6.3.2",
"@jupyterlab/codemirror": ">=4.0",
"@types/json-schema": "*",
"typescript": "<4.4.0"
"typescript": "~5.8.3"
},
"resolutions": {
"@lumino/coreutils": "^1.11.0",
"@lumino/widgets": "^1.37.2",
"lib0": "0.2.108"
},
"peerDependencies": {
"codemirror": "^5.58.1"
},
"files": [
"build/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}"
],
"jupyterlab": {
"extension": "build/plugin.js"
"extension": true
},
"scripts": {
"build": "tsc",
Expand Down
141 changes: 61 additions & 80 deletions org.omg.sysml.jupyter.jupyterlab/src/main/mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,89 +24,70 @@
*/

// tslint:disable-next-line
import 'codemirror/addon/mode/simple';
//import 'codemirror/addon/mode/simple';

import * as CodeMirror from 'codemirror';

const SI_MODE = 'sysml';
const P_MIME = 'text/x-sysml'
import {StringStream} from "@codemirror/language"
import { clike } from '@codemirror/legacy-modes/mode/clike';

const f_wordify = (h: any, s: string) => ({...h, [s]: true});

export function defineSysMLv2Mode(): void {
CodeMirror.defineMode(SI_MODE, (gc_mode, gc_parser) => {
return CodeMirror.getMode(gc_mode, {
name: 'clike',
keywords: [
"about", "abstract", "accept", "action", "actor", "after", "alias", "all", "allocate", "allocation",
"analysis", "and", "as", "assert", "assign", "assume", "at", "attribute", "bind", "binding", "by",
"calc", "case", "comment", "concern", "connect", "connection", "constant", "constraint", "crosses",
"decide", "def", "default", "defined", "dependency", "derived", "do", "doc", "else", "end", "entry",
"enum", "event", "exhibit", "exit", "expose", "filter", "first", "flow", "for", "fork", "frame", "from",
"hastype", "if", "implies", "import", "in", "include", "individual", "inout", "interface", "istype",
"item", "join", "language", "library", "locale", "loop", "merge", "message", "meta", "metadata", "new",
"nonunique", "not", "objective", "occurrence", "of", "or", "ordered", "out", "package", "parallel",
"part", "perform", "port", "private", "protected", "public", "redefines", "ref", "references", "render",
"rendering", "rep", "require", "requirement", "return", "satisfy", "send", "snapshot", "specializes",
"stakeholder", "standard", "state", "subject", "subsets", "succession", "terminate", "then",
"timeslice", "to", "transition", "until", "use", "variant", "variation", "verification", "verify",
"via", "view", "viewpoint", "when", "while", "xor"
].reduce(f_wordify, {}),
defKeywords: [
"action", "allocation", "analysis", "attribute", "binding", "calc", "case", "comment", "concern",
"connection", "constraint", "def", "doc", "enum", "flow", "interface", "item", "metadata", "objective",
"occurrence", "package", "part", "port", "ref", "rendering", "rep", "requirement", "snapshot", "state",
"subject", "succession", "timeslice", "transition", "verification", "view", "viewpoint"
].reduce(f_wordify, {}),
typeFirstDefinitions: true,
atoms: ['true', 'false', 'null'].reduce(f_wordify),
number: /^(?:0x[a-f\d_]+|0b[01_]+|(?:[\d_]+\.?\d*|\.\d+)(?:e[-+]?[\d_]+)?)(u|ll?|l|f)?/i,
modeProps: {
fold: ['brace'],
export const sysmlparser = clike({
name: 'clike',
keywords: [
"about", "abstract", "accept", "action", "actor", "after", "alias", "all", "allocate", "allocation",
"analysis", "and", "as", "assert", "assign", "assume", "at", "attribute", "bind", "binding", "by",
"calc", "case", "comment", "concern", "connect", "connection", "constant", "constraint", "crosses",
"decide", "def", "default", "defined", "dependency", "derived", "do", "doc", "else", "end", "entry",
"enum", "event", "exhibit", "exit", "expose", "filter", "first", "flow", "for", "fork", "frame", "from",
"hastype", "if", "implies", "import", "in", "include", "individual", "inout", "interface", "istype",
"item", "join", "language", "library", "locale", "loop", "merge", "message", "meta", "metadata", "new",
"nonunique", "not", "objective", "occurrence", "of", "or", "ordered", "out", "package", "parallel",
"part", "perform", "port", "private", "protected", "public", "redefines", "ref", "references", "render",
"rendering", "rep", "require", "requirement", "return", "satisfy", "send", "snapshot", "specializes",
"stakeholder", "standard", "state", "subject", "subsets", "succession", "terminate", "then",
"timeslice", "to", "transition", "until", "use", "variant", "variation", "verification", "verify",
"via", "view", "viewpoint", "when", "while", "xor"
].reduce(f_wordify, {}),
types: [
"action", "allocation", "analysis", "attribute", "binding", "calc", "case", "comment", "concern",
"connection", "constraint", "def", "doc", "enum", "flow", "interface", "item", "metadata", "objective",
"occurrence", "package", "part", "port", "ref", "rendering", "rep", "requirement", "snapshot", "state",
"subject", "succession", "timeslice", "transition", "verification", "view", "viewpoint"
].reduce(f_wordify, {}),
atoms: ['true', 'false', 'null'].reduce(f_wordify, {}),
number: /^(?:0x[a-f\d_]+|0b[01_]+|(?:[\d_]+\.?\d*|\.\d+)(?:e[-+]?[\d_]+)?)(u|ll?|l|f)?/i,
hooks: {
"'": function(stream: StringStream) {
let b_escaped = false;
let s_next;
while(s_next = stream.next()) {
if(s_next === "'" && !b_escaped) break;
b_escaped = !b_escaped && s_next === '\\';
}
return 'variable';
},
'/': function(stream: StringStream) {
if(stream.match('/*', false)) stream.next();
return false;
},
hooks: {
"'": function(stream: CodeMirror.StringStream) {
let b_escaped = false;
let s_next;
while(s_next = stream.next()) {
if(s_next === "'" && !b_escaped) break;
b_escaped = !b_escaped && s_next === '\\';
"#": function(stream: StringStream) {
let b_first = true;
do {
if (stream.match("'", true)) {
let b_escaped = false;
let s_next;
while(s_next = stream.next()) {
if(s_next === "'" && !b_escaped) break;
b_escaped = !b_escaped && s_next === '\\';
}
} else if (stream.match(/\w/, true)) {
stream.eatWhile(/\w/);
} else if (b_first) {
return 'operator';
}
return 'variable';
},
'/': function(stream: CodeMirror.StringStream) {
if(stream.match('/*', false)) stream.next();
return false;
},
"#": function(stream: CodeMirror.StringStream) {
let b_first = true;
do {
if (stream.match("'", true)) {
let b_escaped = false;
let s_next;
while(s_next = stream.next()) {
if(s_next === "'" && !b_escaped) break;
b_escaped = !b_escaped && s_next === '\\';
}
} else if (stream.match(/\w/, true)) {
stream.eatWhile(/\w/);
} else if (b_first) {
return 'operator';
}
b_first = false;
} while (stream.match('::', true))
return 'keyword';
},
b_first = false;
} while (stream.match('::', true))
return 'keyword';
},
});
});

CodeMirror.defineMIME(P_MIME, SI_MODE);

(CodeMirror as any).modeInfo.push({
ext: ['sysml'],
mime: P_MIME,
mode: SI_MODE,
name: 'sysml',
});
}
},
}
);
40 changes: 20 additions & 20 deletions org.omg.sysml.jupyter.jupyterlab/src/main/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
*/

import {
JupyterLab,
JupyterFrontEndPlugin,
} from '@jupyterlab/application';
import { JupyterFrontEndPlugin, JupyterFrontEnd} from '@jupyterlab/application';
import { IEditorLanguageRegistry, EditorLanguageRegistry} from "@jupyterlab/codemirror";
import { sysmlparser } from './mode';

import {
defineSysMLv2Mode,
} from './mode';
const plugin: JupyterFrontEndPlugin<void> = {
id: 'jupyterlab-sysml:plugin',
description: 'A JupyterLab extension adding a syntax highlight for SysMLv2 language.',
autoStart: true,
requires: [IEditorLanguageRegistry],
activate: (app: JupyterFrontEnd, languages: IEditorLanguageRegistry) => {

function activate(app: JupyterLab) {
defineSysMLv2Mode();
}
languages.addLanguage({
name: 'sysml',
displayName: 'sysml',
mime: 'text/x-sysml',
extensions: ['sysml'],
load: async () => {
return EditorLanguageRegistry.legacy(sysmlparser)
}
})
}}

/**
* Initialization data for extension
*/
const extension: JupyterFrontEndPlugin<void> = {
activate,
autoStart: true,
id: 'jupyterlab-sysml:plugin',
};

export default extension;
export default plugin;
2 changes: 1 addition & 1 deletion org.omg.sysml.jupyter.jupyterlab/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"allowJs": true,
"esModuleInterop": true,
"lib": ["es2018", "dom"],
"lib": ["es2023", "dom"],
"module": "commonjs",
"moduleResolution": "node",
"noEmitOnError": true,
Expand Down
Loading