Skip to content

Commit 6231e9b

Browse files
committed
ST6RI-521 Added semantic highlighting for prefix metadata.
1 parent 99b3a57 commit 6231e9b

12 files changed

Lines changed: 113 additions & 35 deletions

File tree

org.omg.sysml.jupyter.kernel/src/main/resources/kernel/kernel.js

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ var enableMode = function (CodeMirror) {
5454
"analysis", "and", "as", "assert", "assign", "assume", "at", "attribute", "bind", "binding", "by",
5555
"calc", "case", "comment", "concern", "connect", "connection", "constraint", "decide", "def", "default",
5656
"defined", "dependency", "derived", "do", "doc", "else", "end", "entry", "enum", "event", "exhibit",
57-
"exit", "expose", "feature", "filter", "first", "flow", "for", "fork", "frame", "from", "hastype", "if",
58-
"implies", "import", "in", "include", "individual", "inout", "interface", "istype", "item", "join",
59-
"language", "loop", "merge", "message", "metadata", "nonunique", "not", "objective", "occurrence", "of",
60-
"or", "ordered", "out", "package", "parallel", "part", "perform", "port", "private", "protected",
61-
"public", "readonly", "redefines", "ref", "render", "rendering", "rep", "require", "requirement",
62-
"return", "satisfy", "send", "snapshot", "specializes", "stakeholder", "state", "subject", "subsets",
57+
"exit", "expose", "filter", "first", "flow", "for", "fork", "frame", "from", "hastype", "if", "implies",
58+
"import", "in", "include", "individual", "inout", "interface", "istype", "item", "join", "language",
59+
"loop", "merge", "message", "metadata", "nonunique", "not", "objective", "occurrence", "of", "or",
60+
"ordered", "out", "package", "parallel", "part", "perform", "port", "private", "protected", "public",
61+
"readonly", "redefines", "ref", "render", "rendering", "rep", "require", "requirement", "return",
62+
"satisfy", "send", "snapshot", "specializes", "stakeholder", "state", "subject", "subsets",
6363
"succession", "then", "timeslice", "to", "transition", "until", "use", "variant", "variation",
6464
"verification", "verify", "via", "view", "viewpoint", "when", "while", "xor"
6565
]),
@@ -75,21 +75,35 @@ var enableMode = function (CodeMirror) {
7575
modeProps: {fold: ["brace"]},
7676
hooks: {
7777
"'": function (stream) {
78-
var escaped = false, next;
79-
while ((next = stream.next()) != null) {
80-
if (next == "'" && !escaped) {
81-
break;
82-
}
83-
escaped = !escaped && next == "\\";
78+
let b_escaped = false;
79+
let s_next;
80+
while(s_next = stream.next()) {
81+
if(s_next === "'" && !b_escaped) break;
82+
b_escaped = !b_escaped && s_next === '\\';
8483
}
85-
return "variable";
84+
return 'variable';
8685
},
8786
"/": function (stream) {
8887
if (stream.match("/*", false)) {
8988
stream.next();
9089
}
9190
return false;
9291
}
92+
"#": function(stream) {
93+
do {
94+
if (stream.match("'", true)) {
95+
let b_escaped = false;
96+
let s_next;
97+
while(s_next = stream.next()) {
98+
if(s_next === "'" && !b_escaped) break;
99+
b_escaped = !b_escaped && s_next === '\\';
100+
}
101+
} else {
102+
stream.eatWhile(/\w/);
103+
}
104+
} while (stream.match('::', true))
105+
return 'keyword';
106+
},
93107
}
94108
});
95109
});

org.omg.sysml.xtext.ide/xtend-gen/org/omg/sysml/xtext/ide/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
/.SysMLIdeSetup.xtendbin
55
/SysMLIdeModule.java
66
/SysMLIdeSetup.java
7+
/.SysMLUserKeywordHighlightingCalculator.java._trace

org.omg.sysml.xtext.ui/src/org/omg/sysml/xtext/ui/SysMLUiModule.xtend

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor
77
import org.eclipse.xtext.ui.shared.Access
88
import org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProvider
99
import org.omg.sysml.xtext.ui.quickfix.SysMLQuickfixProvider
10+
import org.eclipse.xtext.ide.editor.syntaxcoloring.ISemanticHighlightingCalculator
1011

1112
/**
1213
* Use this class to register components to be used within the Eclipse IDE.
@@ -15,7 +16,11 @@ import org.omg.sysml.xtext.ui.quickfix.SysMLQuickfixProvider
1516
class SysMLUiModule extends AbstractSysMLUiModule {
1617

1718
override Class<? extends IssueResolutionProvider> bindIssueResolutionProvider() {
18-
return SysMLQuickfixProvider;
19+
return SysMLQuickfixProvider
20+
}
21+
22+
def Class<? extends ISemanticHighlightingCalculator> bindISemanticHighlightingCalculator() {
23+
return SysMLUserKeywordHighlightingCalculator
1924
}
2025

2126
override provideIAllContainersState() {
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*****************************************************************************
2+
* SysML 2 Pilot Implementation
3+
* Copyright (c) 2022 Model Driven Solutions, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
19+
*
20+
* Contributors:
21+
* Ed Seidewitz, MDS
22+
*
23+
*****************************************************************************/
24+
package org.omg.sysml.xtext.ui
25+
26+
import org.eclipse.xtext.ide.editor.syntaxcoloring.ISemanticHighlightingCalculator
27+
import org.eclipse.xtext.resource.XtextResource
28+
import org.eclipse.xtext.ide.editor.syntaxcoloring.IHighlightedPositionAcceptor
29+
import org.eclipse.xtext.util.CancelIndicator
30+
import org.eclipse.xtext.ui.editor.syntaxcoloring.DefaultHighlightingConfiguration
31+
import org.eclipse.xtext.impl.RuleCallImpl
32+
import org.eclipse.xtext.service.OperationCanceledManager
33+
import com.google.inject.Inject
34+
35+
class SysMLUserKeywordHighlightingCalculator implements ISemanticHighlightingCalculator {
36+
37+
@Inject
38+
OperationCanceledManager cancelManager;
39+
40+
override provideHighlightingFor(XtextResource resource, IHighlightedPositionAcceptor acceptor,
41+
CancelIndicator cancelIndicator) {
42+
if (resource !== null && resource.getParseResult() !== null) {
43+
val root = resource.getParseResult().getRootNode();
44+
for (node : root.getAsTreeIterable()) {
45+
cancelManager.checkCanceled(cancelIndicator);
46+
val grammarElement = node.grammarElement
47+
if (grammarElement instanceof RuleCallImpl) {
48+
val name = grammarElement.rule.name;
49+
if ("PrefixMetadataMember".equals(name) || "PrefixMetadataAnnotation".equals(name)) {
50+
acceptor.addPosition(node.getOffset(), node.getLength(), DefaultHighlightingConfiguration.KEYWORD_ID);
51+
}
52+
}
53+
}
54+
}
55+
}
56+
57+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/.SysMLUiModule.java._trace
22
/.SysMLUiModule.xtendbin
33
/SysMLUiModule.java
4+
/.SysMLUserKeywordHighlightingCalculator.java._trace

org.omg.sysml.xtext/.launch/Save SysML with Library.launch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
1414
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.omg.sysml.xtext.util.SysMLRepositorySaveUtil"/>
1515
<stringAttribute key="org.eclipse.jdt.launching.MODULE_NAME" value="org.omg.sysml.xtext"/>
16-
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-b http://sysml2-sst.intercax.com:9000 -d&#10;-l &quot;${workspace_loc:/SysML-v2-Pilot-Implementation/sysml.library}&quot; &#10;&quot;${selected_resource_loc}&quot;&#10;&quot;Kernel Library&quot;&#10;&quot;Systems Library&quot;&#10;&quot;Domain Library&quot;"/>
16+
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-b http://sysml2-dev.intercax.com:9000 -d&#10;-l &quot;${workspace_loc:/SysML-v2-Pilot-Implementation/sysml.library}&quot; &#10;&quot;${selected_resource_loc}&quot;&#10;&quot;Kernel Library&quot;&#10;&quot;Systems Library&quot;&#10;&quot;Domain Library&quot;"/>
1717
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.omg.sysml.xtext"/>
1818
</launchConfiguration>

tool-support/syntax-highlighting/jetbrains/KerML.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<option name="HAS_PARENS" value="true" />
1212
<option name="HAS_STRING_ESCAPES" value="true" />
1313
</options>
14-
<keywords keywords="about;abstract;alias;all;and;as;assoc;behavior;binding;bool;by;class;classifier;comment;composite;conjugate;conjugates;conjugation;connector;datatype;default;derived;disjoining;disjoint;doc;element;else;end;expr;false;feature;featured;featuring;filter;first;flow;for;from;function;hastype;if;implies;import;in;inout;interaction;inv;is;istype;language;member;metadata;multiplicity;namespace;nonunique;not;null;of;or;ordered;out;package;portion;predicate;private;protected;public;readonly;redefines;redefinition;relationship;rep;return;specialization;specializes;step;struct;subclassifier;subset;subsets;subtype;succession;then;to;true;type;typed;typing;xor" ignore_case="false" />
15-
<keywords2 keywords="!;!=;%;&amp;;&amp;&amp;;*;**;+;-;-&gt;;..;/;:;::;:=;:&gt;;:&gt;&gt;;&lt;;&lt;=;=;==;=&gt;;&gt;;&gt;=;?;??;@;^;^^;|;||;~" />
14+
<keywords keywords="about;abstract;alias;all;and;as;assoc;behavior;binding;bool;by;class;classifier;comment;composite;conjugate;conjugates;conjugation;connector;datatype;default;derived;disjoining;disjoint;doc;element;else;end;expr;false;feature;featured;featuring;filter;first;flow;for;from;function;hastype;if;implies;import;in;inout;interaction;inv;is;istype;language;member;metaclass;metadata;multiplicity;namespace;nonunique;not;null;of;or;ordered;out;package;portion;predicate;private;protected;public;readonly;redefines;redefinition;relationship;rep;return;specialization;specializes;step;struct;subclassifier;subset;subsets;subtype;succession;then;to;true;type;typed;typing;xor" ignore_case="false" />
15+
<keywords2 keywords="!;!=;%;&amp;;&amp;&amp;;*;**;+;-;-&gt;;..;.?;/;:;::;:=;:&gt;;:&gt;&gt;;&lt;;&lt;=;=;==;=&gt;;&gt;;&gt;=;?;??;@;^;^^;|;||;~" />
1616
</highlighting>
1717
<extensionMap>
1818
<mapping ext="kerml" />

tool-support/syntax-highlighting/jetbrains/SysML.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<option name="HAS_PARENS" value="true" />
1212
<option name="HAS_STRING_ESCAPES" value="true" />
1313
</options>
14-
<keywords 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;constraint;decide;def;default;defined;dependency;derived;do;doc;else;end;entry;enum;event;exhibit;exit;expose;false;feature;filter;first;flow;for;fork;frame;from;hastype;if;implies;import;in;include;individual;inout;interface;istype;item;join;language;loop;merge;message;metadata;nonunique;not;null;objective;occurrence;of;or;ordered;out;package;parallel;part;perform;port;private;protected;public;readonly;redefines;ref;render;rendering;rep;require;requirement;return;satisfy;send;snapshot;specializes;stakeholder;state;subject;subsets;succession;then;timeslice;to;transition;true;until;use;variant;variation;verification;verify;via;view;viewpoint;when;while;xor" ignore_case="false" />
15-
<keywords2 keywords="!;!=;%;&amp;;&amp;&amp;;*;**;+;-;-&gt;;..;/;:;::;:=;:&gt;;:&gt;&gt;;&lt;;&lt;=;=;==;=&gt;;&gt;;&gt;=;?;??;@;^;^^;|;||;~" />
14+
<keywords 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;constraint;decide;def;default;defined;dependency;derived;do;doc;else;end;entry;enum;event;exhibit;exit;expose;false;filter;first;flow;for;fork;frame;from;hastype;if;implies;import;in;include;individual;inout;interface;istype;item;join;language;loop;merge;message;metadata;nonunique;not;null;objective;occurrence;of;or;ordered;out;package;parallel;part;perform;port;private;protected;public;readonly;redefines;ref;render;rendering;rep;require;requirement;return;satisfy;send;snapshot;specializes;stakeholder;state;subject;subsets;succession;then;timeslice;to;transition;true;until;use;variant;variation;verification;verify;via;view;viewpoint;when;while;xor" ignore_case="false" />
15+
<keywords2 keywords="!;!=;%;&amp;;&amp;&amp;;*;**;+;-;-&gt;;.$;..;.?;/;:;::;:=;:&gt;;:&gt;&gt;;&lt;;&lt;=;=;==;=&gt;;&gt;;&gt;=;?;??;@;^;^^;|;||;~" />
1616
</highlighting>
1717
<extensionMap>
1818
<mapping ext="sysml" />

tool-support/syntax-highlighting/jupyter/kernel.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ var enableMode = function (CodeMirror) {
5454
"analysis", "and", "as", "assert", "assign", "assume", "at", "attribute", "bind", "binding", "by",
5555
"calc", "case", "comment", "concern", "connect", "connection", "constraint", "decide", "def", "default",
5656
"defined", "dependency", "derived", "do", "doc", "else", "end", "entry", "enum", "event", "exhibit",
57-
"exit", "expose", "feature", "filter", "first", "flow", "for", "fork", "frame", "from", "hastype", "if",
58-
"implies", "import", "in", "include", "individual", "inout", "interface", "istype", "item", "join",
59-
"language", "loop", "merge", "message", "metadata", "nonunique", "not", "objective", "occurrence", "of",
60-
"or", "ordered", "out", "package", "parallel", "part", "perform", "port", "private", "protected",
61-
"public", "readonly", "redefines", "ref", "render", "rendering", "rep", "require", "requirement",
62-
"return", "satisfy", "send", "snapshot", "specializes", "stakeholder", "state", "subject", "subsets",
57+
"exit", "expose", "filter", "first", "flow", "for", "fork", "frame", "from", "hastype", "if", "implies",
58+
"import", "in", "include", "individual", "inout", "interface", "istype", "item", "join", "language",
59+
"loop", "merge", "message", "metadata", "nonunique", "not", "objective", "occurrence", "of", "or",
60+
"ordered", "out", "package", "parallel", "part", "perform", "port", "private", "protected", "public",
61+
"readonly", "redefines", "ref", "render", "rendering", "rep", "require", "requirement", "return",
62+
"satisfy", "send", "snapshot", "specializes", "stakeholder", "state", "subject", "subsets",
6363
"succession", "then", "timeslice", "to", "transition", "until", "use", "variant", "variation",
6464
"verification", "verify", "via", "view", "viewpoint", "when", "while", "xor"
6565
]),

tool-support/syntax-highlighting/jupyter/mode.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ export function defineSysMLv2Mode(): void {
4242
"analysis", "and", "as", "assert", "assign", "assume", "at", "attribute", "bind", "binding", "by",
4343
"calc", "case", "comment", "concern", "connect", "connection", "constraint", "decide", "def", "default",
4444
"defined", "dependency", "derived", "do", "doc", "else", "end", "entry", "enum", "event", "exhibit",
45-
"exit", "expose", "feature", "filter", "first", "flow", "for", "fork", "frame", "from", "hastype", "if",
46-
"implies", "import", "in", "include", "individual", "inout", "interface", "istype", "item", "join",
47-
"language", "loop", "merge", "message", "metadata", "nonunique", "not", "objective", "occurrence", "of",
48-
"or", "ordered", "out", "package", "parallel", "part", "perform", "port", "private", "protected",
49-
"public", "readonly", "redefines", "ref", "render", "rendering", "rep", "require", "requirement",
50-
"return", "satisfy", "send", "snapshot", "specializes", "stakeholder", "state", "subject", "subsets",
45+
"exit", "expose", "filter", "first", "flow", "for", "fork", "frame", "from", "hastype", "if", "implies",
46+
"import", "in", "include", "individual", "inout", "interface", "istype", "item", "join", "language",
47+
"loop", "merge", "message", "metadata", "nonunique", "not", "objective", "occurrence", "of", "or",
48+
"ordered", "out", "package", "parallel", "part", "perform", "port", "private", "protected", "public",
49+
"readonly", "redefines", "ref", "render", "rendering", "rep", "require", "requirement", "return",
50+
"satisfy", "send", "snapshot", "specializes", "stakeholder", "state", "subject", "subsets",
5151
"succession", "then", "timeslice", "to", "transition", "until", "use", "variant", "variation",
5252
"verification", "verify", "via", "view", "viewpoint", "when", "while", "xor"
5353
].reduce(f_wordify, {}),

0 commit comments

Comments
 (0)