You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kie.apache.org by po...@apache.org on 2023/10/11 17:25:10 UTC
[incubator-kie-tools-temporary-rnd-do-not-use] 29/32: kie-issues#603: Colorize Decision Services call in FEEL expressions in DMN Editor's Boxed Expression Editor (#2005)
This is an automated email from the ASF dual-hosted git repository.
porcelli pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-tools-temporary-rnd-do-not-use.git
commit 424fb4abe46182dde2e28705a91dd6f3ae16745e
Author: Daniel José dos Santos <da...@users.noreply.github.com>
AuthorDate: Fri Oct 6 14:26:33 2023 -0300
kie-issues#603: Colorize Decision Services call in FEEL expressions in DMN Editor's Boxed Expression Editor (#2005)
---
packages/dmn-feel-antlr4-parser/src/index.ts | 2 +-
.../src/parser/FeelVariable.ts | 8 ++---
.../src/parser/{VariableType.ts => SymbolType.ts} | 31 ++++++++++++++----
.../dmn-feel-antlr4-parser/src/parser/Variable.ts | 4 +--
.../src/parser/VariablesRepository.ts | 38 +++++++++++++++-------
.../src/parser/grammar/ParserHelper.ts | 12 +++----
.../src/parser/grammar/VariableSymbol.ts | 12 +++----
packages/feel-input-component/src/FeelConfigs.ts | 2 +-
packages/feel-input-component/src/FeelInput.tsx | 18 +++++-----
.../feel-input-component/src/themes/Element.ts | 2 +-
10 files changed, 82 insertions(+), 47 deletions(-)
diff --git a/packages/dmn-feel-antlr4-parser/src/index.ts b/packages/dmn-feel-antlr4-parser/src/index.ts
index 34ad78d198..e50927c1c1 100644
--- a/packages/dmn-feel-antlr4-parser/src/index.ts
+++ b/packages/dmn-feel-antlr4-parser/src/index.ts
@@ -20,6 +20,6 @@
export * from "./FeelVariables";
export * from "./parser/FeelVariable";
export * from "./parser/ReservedWords";
-export * from "./parser/VariableType";
+export * from "./parser/SymbolType";
export * from "./parser/FeelVariablesParser";
export * from "./parser/VariablesRepository";
diff --git a/packages/dmn-feel-antlr4-parser/src/parser/FeelVariable.ts b/packages/dmn-feel-antlr4-parser/src/parser/FeelVariable.ts
index 8c567fb07d..46f77188c7 100644
--- a/packages/dmn-feel-antlr4-parser/src/parser/FeelVariable.ts
+++ b/packages/dmn-feel-antlr4-parser/src/parser/FeelVariable.ts
@@ -17,15 +17,15 @@
* under the License.
*/
-import { VariableType } from "./VariableType";
+import { SymbolType } from "./SymbolType";
export class FeelVariable {
private readonly _text: string;
private readonly _startIndex: number;
- private readonly _variableType: VariableType;
+ private readonly _variableType: SymbolType;
private readonly _length: number;
- constructor(startIndex: number, length: number, variableType: VariableType, text: string) {
+ constructor(startIndex: number, length: number, variableType: SymbolType, text: string) {
this._startIndex = startIndex;
this._length = length;
this._variableType = variableType;
@@ -40,7 +40,7 @@ export class FeelVariable {
return this._startIndex;
}
- get variableType(): VariableType {
+ get variableType(): SymbolType {
return this._variableType;
}
diff --git a/packages/dmn-feel-antlr4-parser/src/parser/VariableType.ts b/packages/dmn-feel-antlr4-parser/src/parser/SymbolType.ts
similarity index 69%
rename from packages/dmn-feel-antlr4-parser/src/parser/VariableType.ts
rename to packages/dmn-feel-antlr4-parser/src/parser/SymbolType.ts
index 0747195c24..c17c7959f8 100644
--- a/packages/dmn-feel-antlr4-parser/src/parser/VariableType.ts
+++ b/packages/dmn-feel-antlr4-parser/src/parser/SymbolType.ts
@@ -17,10 +17,29 @@
* under the License.
*/
-export enum VariableType {
- Unknown = 0,
- Input = 1,
- BusinessKnowledgeModel = 2,
- LocalVariable = 3,
- Parameter = 4,
+export enum SymbolType {
+ /**
+ * Symbol not recognized.
+ */
+ Unknown,
+
+ /**
+ * A symbol defined in a Decision or Input node.
+ */
+ GlobalVariable,
+
+ /**
+ * Decision Service and Business Knowledge Model are invocable.
+ */
+ Invocable,
+
+ /**
+ * Local variables.
+ */
+ LocalVariable,
+
+ /**
+ * Parameters of functions.
+ */
+ Parameter,
}
diff --git a/packages/dmn-feel-antlr4-parser/src/parser/Variable.ts b/packages/dmn-feel-antlr4-parser/src/parser/Variable.ts
index 0e68a77004..98d5ee09a1 100644
--- a/packages/dmn-feel-antlr4-parser/src/parser/Variable.ts
+++ b/packages/dmn-feel-antlr4-parser/src/parser/Variable.ts
@@ -18,7 +18,7 @@
*/
import { DataType } from "./DataType";
-import { VariableType } from "./VariableType";
+import { SymbolType } from "./SymbolType";
/**
* Describe a variable in FEEL.
@@ -32,7 +32,7 @@ export interface Variable {
/**
* The source of the variable.
*/
- variableType: VariableType;
+ variableType: SymbolType;
/**
* Some variables are of one of the custom data types defined by user.
diff --git a/packages/dmn-feel-antlr4-parser/src/parser/VariablesRepository.ts b/packages/dmn-feel-antlr4-parser/src/parser/VariablesRepository.ts
index 1481d4afbe..1e22acb0bd 100644
--- a/packages/dmn-feel-antlr4-parser/src/parser/VariablesRepository.ts
+++ b/packages/dmn-feel-antlr4-parser/src/parser/VariablesRepository.ts
@@ -19,13 +19,14 @@
import { getMarshaller } from "@kie-tools/dmn-marshaller";
import { DataType } from "./DataType";
-import { VariableType } from "./VariableType";
+import { SymbolType } from "./SymbolType";
import { VariableContext } from "./VariableContext";
import {
DMN15__tBusinessKnowledgeModel,
DMN15__tContext,
DMN15__tContextEntry,
DMN15__tDecision,
+ DMN15__tDecisionService,
DMN15__tDecisionTable,
DMN15__tDefinitions,
DMN15__tFunctionDefinition,
@@ -69,6 +70,7 @@ type DmnItemDefinition = DMN15__tItemDefinition;
type DmnContextEntry = DMN15__tContextEntry;
type DmnInputData = DMN15__tInputData;
type DmnInformationRequirement = DMN15__tInformationRequirement;
+type DmnDecisionService = DMN15__tDecisionService;
export class VariablesRepository {
private readonly variablesIndexedByUuid: Map<string, VariableContext>;
@@ -96,7 +98,7 @@ export class VariablesRepository {
if (parentContext) {
const newVariable = {
value: variableName,
- variableType: VariableType.Input,
+ variableType: SymbolType.GlobalVariable,
typeRef: undefined,
};
@@ -188,6 +190,10 @@ export class VariablesRepository {
this.createVariablesFromBkm(drg);
break;
+ case "decisionService":
+ this.createVariablesFromDecisionService(drg);
+ break;
+
default:
// Do nothing because it is an element that does not declare variables
break;
@@ -196,14 +202,24 @@ export class VariablesRepository {
}
private createVariablesFromInputData(drg: DmnInputData) {
- this.addVariable(drg["@_id"] ?? "", drg["@_name"], VariableType.Input, undefined, drg.variable?.["@_typeRef"]);
+ this.addVariable(
+ drg["@_id"] ?? "",
+ drg["@_name"],
+ SymbolType.GlobalVariable,
+ undefined,
+ drg.variable?.["@_typeRef"]
+ );
+ }
+
+ private createVariablesFromDecisionService(drg: DmnDecisionService) {
+ this.addVariable(drg["@_id"] ?? "", drg["@_name"], SymbolType.Invocable, undefined, drg.variable?.["@_typeRef"]);
}
private createVariablesFromBkm(drg: DmnBusinessKnowledgeModel) {
const parent = this.addVariable(
drg["@_id"] ?? "",
drg["@_name"],
- VariableType.BusinessKnowledgeModel,
+ SymbolType.Invocable,
undefined,
drg.variable?.["@_typeRef"]
);
@@ -216,7 +232,7 @@ export class VariablesRepository {
parentElement = this.addVariable(
parameter["@_id"] ?? "",
parameter["@_name"] ?? "<parameter>",
- VariableType.Parameter,
+ SymbolType.Parameter,
parentElement
);
}
@@ -232,7 +248,7 @@ export class VariablesRepository {
const parent = this.addVariable(
drg["@_id"] ?? "",
drg["@_name"],
- VariableType.Input,
+ SymbolType.GlobalVariable,
undefined,
drg.variable?.["@_typeRef"]
);
@@ -257,7 +273,7 @@ export class VariablesRepository {
private addVariable(
uuid: string,
name: string,
- variableType: VariableType,
+ variableType: SymbolType,
parent?: VariableContext,
typeRef?: string
) {
@@ -271,7 +287,7 @@ export class VariablesRepository {
private createVariableNode(
uuid: string,
name: string,
- variableType: VariableType,
+ variableType: SymbolType,
parent: VariableContext | undefined,
typeRef: string | undefined
) {
@@ -322,7 +338,7 @@ export class VariablesRepository {
}
private addLiteralExpression(parent: VariableContext, element: DmnLiteralExpression) {
- this.addVariable(element["@_id"] ?? "", "<literalExpression>", VariableType.LocalVariable, parent);
+ this.addVariable(element["@_id"] ?? "", "<literalExpression>", SymbolType.LocalVariable, parent);
}
private addInvocation(parent: VariableContext, element: DmnInvocation) {
@@ -348,7 +364,7 @@ export class VariablesRepository {
const variableNode = this.addVariable(
contextEntry.variable?.["@_id"] ?? "",
contextEntry.variable?.["@_name"] ?? "",
- VariableType.LocalVariable,
+ SymbolType.LocalVariable,
parentNode,
contextEntry.variable?.["@_typeRef"]
);
@@ -372,7 +388,7 @@ export class VariablesRepository {
parentElement = this.addVariable(
parameter["@_id"] ?? "",
parameter["@_name"] ?? "<parameter>",
- VariableType.Parameter,
+ SymbolType.Parameter,
parentElement
);
}
diff --git a/packages/dmn-feel-antlr4-parser/src/parser/grammar/ParserHelper.ts b/packages/dmn-feel-antlr4-parser/src/parser/grammar/ParserHelper.ts
index 66351db69e..c242392c38 100644
--- a/packages/dmn-feel-antlr4-parser/src/parser/grammar/ParserHelper.ts
+++ b/packages/dmn-feel-antlr4-parser/src/parser/grammar/ParserHelper.ts
@@ -27,7 +27,7 @@ import { NameQueue } from "./NameQueue";
import { FeelVariable } from "../FeelVariable";
import { Scopes } from "./Scopes";
import { ReservedWords } from "../ReservedWords";
-import { VariableType } from "../VariableType";
+import { SymbolType } from "../SymbolType";
import { MapBackedType } from "./MapBackedType";
export class ParserHelper {
@@ -94,7 +94,7 @@ export class ParserHelper {
return key;
}
- defineVariable(variable: string | ParserRuleContext, type?: Type, variableType?: VariableType) {
+ defineVariable(variable: string | ParserRuleContext, type?: Type, variableType?: SymbolType) {
const variableSymbol = new VariableSymbol(
variable instanceof ParserRuleContext ? this.getName(variable) : variable,
type,
@@ -165,18 +165,18 @@ export class ParserHelper {
const length = end - start + 1;
if (this.currentScope?.getChildScopes().has(name)) {
- this.variables.push(new FeelVariable(start, length, VariableType.Input, name));
+ this.variables.push(new FeelVariable(start, length, SymbolType.GlobalVariable, name));
} else {
const symbol = this.currentScope?.resolve(name);
if (symbol) {
if (symbol instanceof VariableSymbol) {
- this.variables.push(new FeelVariable(start, length, symbol.variableType ?? VariableType.Input, name));
+ this.variables.push(new FeelVariable(start, length, symbol.symbolType ?? SymbolType.GlobalVariable, name));
} else {
- this.variables.push(new FeelVariable(start, length, VariableType.Input, name));
+ this.variables.push(new FeelVariable(start, length, SymbolType.GlobalVariable, name));
}
} else {
if (!ReservedWords.FeelFunctions.has(name) && !ReservedWords.FeelKeywords.has(name)) {
- this.variables.push(new FeelVariable(start, length, VariableType.Unknown, name));
+ this.variables.push(new FeelVariable(start, length, SymbolType.Unknown, name));
}
}
}
diff --git a/packages/dmn-feel-antlr4-parser/src/parser/grammar/VariableSymbol.ts b/packages/dmn-feel-antlr4-parser/src/parser/grammar/VariableSymbol.ts
index 4fb83b52c7..4b53640a03 100644
--- a/packages/dmn-feel-antlr4-parser/src/parser/grammar/VariableSymbol.ts
+++ b/packages/dmn-feel-antlr4-parser/src/parser/grammar/VariableSymbol.ts
@@ -20,17 +20,17 @@
import { BaseSymbol } from "./BaseSymbol";
import { Type } from "./Type";
-import { VariableType } from "../VariableType";
+import { SymbolType } from "../SymbolType";
export class VariableSymbol extends BaseSymbol {
- private readonly _variableType: VariableType | undefined;
+ private readonly _symbolType: SymbolType | undefined;
- constructor(id?: string, type?: Type, variableType?: VariableType) {
+ constructor(id?: string, type?: Type, variableType?: SymbolType) {
super(id, type);
- this._variableType = variableType;
+ this._symbolType = variableType;
}
- get variableType(): VariableType | undefined {
- return this._variableType;
+ get symbolType(): SymbolType | undefined {
+ return this._symbolType;
}
}
diff --git a/packages/feel-input-component/src/FeelConfigs.ts b/packages/feel-input-component/src/FeelConfigs.ts
index 2b3479a18e..631e5c30ec 100644
--- a/packages/feel-input-component/src/FeelConfigs.ts
+++ b/packages/feel-input-component/src/FeelConfigs.ts
@@ -36,7 +36,7 @@ export const feelTheme = (): Monaco.editor.IStandaloneThemeData => {
{ token: Element[Element.FeelString], foreground: "#067D17" },
{ token: Element[Element.FeelFunction], foreground: "#00627A" },
{ token: Element[Element.InputDataVariable], foreground: "#917632", fontStyle: "underline" },
- { token: Element[Element.BkmVariable], foreground: "#917632", fontStyle: "underline italic" },
+ { token: Element[Element.FunctionCall], foreground: "#917632", fontStyle: "underline italic" },
{ token: Element[Element.UnknownVariable], foreground: "#ff0000", fontStyle: "underline bold" },
{ token: Element[Element.FunctionParameterVariable], foreground: "#036e9b", fontStyle: "italic" },
],
diff --git a/packages/feel-input-component/src/FeelInput.tsx b/packages/feel-input-component/src/FeelInput.tsx
index 83bd32b6ca..e134b09ad2 100644
--- a/packages/feel-input-component/src/FeelInput.tsx
+++ b/packages/feel-input-component/src/FeelInput.tsx
@@ -29,7 +29,7 @@ import {
MONACO_FEEL_THEME,
} from "./FeelConfigs";
-import { VariableType, FeelVariables } from "@kie-tools/dmn-feel-antlr4-parser";
+import { SymbolType, FeelVariables } from "@kie-tools/dmn-feel-antlr4-parser";
import { Element } from "./themes/Element";
export type SuggestionProvider = (
@@ -74,17 +74,17 @@ Monaco.editor.defineTheme(MONACO_FEEL_THEME, feelTheme());
// Don't remove this mechanism. It's necessary for Monaco to initialize correctly and display correct colors for FEEL.
let __firstTimeInitializingMonacoToEnableColorizingCorrectly = true;
-function getTokenTypeIndex(variableType: VariableType) {
- switch (variableType) {
+function getTokenTypeIndex(symbolType: SymbolType) {
+ switch (symbolType) {
default:
- case VariableType.LocalVariable:
- case VariableType.Input:
+ case SymbolType.LocalVariable:
+ case SymbolType.GlobalVariable:
return Element.InputDataVariable;
- case VariableType.Unknown:
+ case SymbolType.Unknown:
return Element.UnknownVariable;
- case VariableType.BusinessKnowledgeModel:
- return Element.BkmVariable;
- case VariableType.Parameter:
+ case SymbolType.Invocable:
+ return Element.FunctionCall;
+ case SymbolType.Parameter:
return Element.FunctionParameterVariable;
}
}
diff --git a/packages/feel-input-component/src/themes/Element.ts b/packages/feel-input-component/src/themes/Element.ts
index bf711d4976..1080e01be2 100644
--- a/packages/feel-input-component/src/themes/Element.ts
+++ b/packages/feel-input-component/src/themes/Element.ts
@@ -24,7 +24,7 @@ export enum Element {
FeelString,
FeelFunction,
InputDataVariable,
- BkmVariable,
+ FunctionCall,
UnknownVariable,
FunctionParameterVariable,
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org