ljmotta commented on code in PR #3397:
URL: 
https://github.com/apache/incubator-kie-tools/pull/3397#discussion_r2756161526


##########
packages/dmn-feel-antlr4-parser/src/parser/FeelFunctionReturningTypes.ts:
##########
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { DataType } from "./DataType";
+import { BuiltInTypes } from "./BuiltInTypes";
+
+export class FeelFunctionReturningTypes {
+  public static readonly Index: ReadonlyMap<string, DataType> = new 
Map<string, DataType>([
+    ["abs", BuiltInTypes.Number],
+    ["after", BuiltInTypes.Boolean],
+    ["all", BuiltInTypes.Boolean],
+    ["any", BuiltInTypes.Boolean],
+    ["append", BuiltInTypes.List],
+    ["before", BuiltInTypes.Boolean],
+    ["ceiling", BuiltInTypes.Number],
+    ["code", BuiltInTypes.Number],
+    ["coincides", BuiltInTypes.Boolean],
+    ["concatenate", BuiltInTypes.String],
+    ["contains", BuiltInTypes.Boolean],
+    ["context", BuiltInTypes.Context],
+    ["context put", BuiltInTypes.Context],
+    ["context merge", BuiltInTypes.Context],
+    ["count", BuiltInTypes.Number],
+    ["date", BuiltInTypes.Date],
+    ["date and time", BuiltInTypes.DateAndTime],
+    ["day of week", BuiltInTypes.String],
+    ["day of year", BuiltInTypes.Number],
+    ["decimal", BuiltInTypes.Number],
+    ["decision table", BuiltInTypes.Any],
+    ["distinct values", BuiltInTypes.List],
+    ["duration", BuiltInTypes.DaysAndTimeDuration],
+    ["during", BuiltInTypes.Boolean],
+    ["ends with", BuiltInTypes.Boolean],
+    ["even", BuiltInTypes.Boolean],
+    ["exp", BuiltInTypes.Number],
+    ["finished by", BuiltInTypes.Boolean],
+    ["finishes", BuiltInTypes.Boolean],
+    ["flatten", BuiltInTypes.List],
+    ["floor", BuiltInTypes.Number],
+    ["get entries", BuiltInTypes.List],
+    ["get value", BuiltInTypes.Any],
+    ["includes", BuiltInTypes.Boolean],
+    ["index of", BuiltInTypes.List],
+    ["insert before", BuiltInTypes.List],
+    ["invoke", BuiltInTypes.Any],
+    ["is", BuiltInTypes.Boolean],
+    ["list contains", BuiltInTypes.Boolean],
+    ["list replace", BuiltInTypes.List],
+    ["log", BuiltInTypes.Number],
+    ["lower case", BuiltInTypes.String],
+    ["matches", BuiltInTypes.Boolean],
+    ["max", BuiltInTypes.Number],
+    ["mean", BuiltInTypes.Number],
+    ["median", BuiltInTypes.Number],
+    ["meets", BuiltInTypes.Boolean],
+    ["met by", BuiltInTypes.Boolean],
+    ["min", BuiltInTypes.Number],
+    ["mode", BuiltInTypes.Number],
+    ["modulo", BuiltInTypes.Number],
+    ["month of year", BuiltInTypes.String],
+    ["nn all", BuiltInTypes.Boolean],
+    ["nn any", BuiltInTypes.Boolean],
+    ["nn count", BuiltInTypes.Number],
+    ["nn max", BuiltInTypes.Number],
+    ["nn mean", BuiltInTypes.Number],
+    ["nn median", BuiltInTypes.Number],
+    ["nn min", BuiltInTypes.Number],
+    ["nn mode", BuiltInTypes.Number],
+    ["nn stddev", BuiltInTypes.Number],
+    ["nn sum", BuiltInTypes.Number],
+    ["not", BuiltInTypes.Boolean],
+    ["now", BuiltInTypes.DateAndTime],
+    ["Number", BuiltInTypes.Number],
+    ["odd", BuiltInTypes.Boolean],
+    ["overlaps after", BuiltInTypes.Boolean],
+    ["overlaps before", BuiltInTypes.Boolean],
+    ["overlaps", BuiltInTypes.Boolean],
+    ["product", BuiltInTypes.Number],
+    ["range", BuiltInTypes.Range],
+    ["remove", BuiltInTypes.List],
+    ["replace", BuiltInTypes.String],
+    ["reverse", BuiltInTypes.List],
+    ["round down", BuiltInTypes.Number],
+    ["round half down", BuiltInTypes.Number],
+    ["round half up", BuiltInTypes.Number],
+    ["round up", BuiltInTypes.Number],
+    ["sort", BuiltInTypes.List],
+    ["split", BuiltInTypes.List],
+    ["sqrt", BuiltInTypes.Number],
+    ["started by", BuiltInTypes.Boolean],
+    ["starts with", BuiltInTypes.Boolean],
+    ["starts", BuiltInTypes.Boolean],
+    ["stddev", BuiltInTypes.Number],
+    ["string", BuiltInTypes.String],
+    ["string join", BuiltInTypes.String],
+    ["string length", BuiltInTypes.Number],
+    ["subList", BuiltInTypes.List],
+    ["subString after", BuiltInTypes.String],
+    ["subString before", BuiltInTypes.String],
+    ["subString", BuiltInTypes.String],

Review Comment:
   `substring`



##########
packages/dmn-feel-antlr4-parser/src/parser/FeelFunctionReturningTypes.ts:
##########
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { DataType } from "./DataType";
+import { BuiltInTypes } from "./BuiltInTypes";
+
+export class FeelFunctionReturningTypes {
+  public static readonly Index: ReadonlyMap<string, DataType> = new 
Map<string, DataType>([
+    ["abs", BuiltInTypes.Number],
+    ["after", BuiltInTypes.Boolean],
+    ["all", BuiltInTypes.Boolean],
+    ["any", BuiltInTypes.Boolean],
+    ["append", BuiltInTypes.List],
+    ["before", BuiltInTypes.Boolean],
+    ["ceiling", BuiltInTypes.Number],
+    ["code", BuiltInTypes.Number],
+    ["coincides", BuiltInTypes.Boolean],
+    ["concatenate", BuiltInTypes.String],
+    ["contains", BuiltInTypes.Boolean],
+    ["context", BuiltInTypes.Context],
+    ["context put", BuiltInTypes.Context],
+    ["context merge", BuiltInTypes.Context],
+    ["count", BuiltInTypes.Number],
+    ["date", BuiltInTypes.Date],
+    ["date and time", BuiltInTypes.DateAndTime],
+    ["day of week", BuiltInTypes.String],
+    ["day of year", BuiltInTypes.Number],
+    ["decimal", BuiltInTypes.Number],
+    ["decision table", BuiltInTypes.Any],
+    ["distinct values", BuiltInTypes.List],
+    ["duration", BuiltInTypes.DaysAndTimeDuration],
+    ["during", BuiltInTypes.Boolean],
+    ["ends with", BuiltInTypes.Boolean],
+    ["even", BuiltInTypes.Boolean],
+    ["exp", BuiltInTypes.Number],
+    ["finished by", BuiltInTypes.Boolean],
+    ["finishes", BuiltInTypes.Boolean],
+    ["flatten", BuiltInTypes.List],
+    ["floor", BuiltInTypes.Number],
+    ["get entries", BuiltInTypes.List],
+    ["get value", BuiltInTypes.Any],
+    ["includes", BuiltInTypes.Boolean],
+    ["index of", BuiltInTypes.List],
+    ["insert before", BuiltInTypes.List],
+    ["invoke", BuiltInTypes.Any],
+    ["is", BuiltInTypes.Boolean],
+    ["list contains", BuiltInTypes.Boolean],
+    ["list replace", BuiltInTypes.List],
+    ["log", BuiltInTypes.Number],
+    ["lower case", BuiltInTypes.String],
+    ["matches", BuiltInTypes.Boolean],
+    ["max", BuiltInTypes.Number],
+    ["mean", BuiltInTypes.Number],
+    ["median", BuiltInTypes.Number],
+    ["meets", BuiltInTypes.Boolean],
+    ["met by", BuiltInTypes.Boolean],
+    ["min", BuiltInTypes.Number],
+    ["mode", BuiltInTypes.Number],
+    ["modulo", BuiltInTypes.Number],
+    ["month of year", BuiltInTypes.String],
+    ["nn all", BuiltInTypes.Boolean],
+    ["nn any", BuiltInTypes.Boolean],
+    ["nn count", BuiltInTypes.Number],
+    ["nn max", BuiltInTypes.Number],
+    ["nn mean", BuiltInTypes.Number],
+    ["nn median", BuiltInTypes.Number],
+    ["nn min", BuiltInTypes.Number],
+    ["nn mode", BuiltInTypes.Number],
+    ["nn stddev", BuiltInTypes.Number],
+    ["nn sum", BuiltInTypes.Number],
+    ["not", BuiltInTypes.Boolean],
+    ["now", BuiltInTypes.DateAndTime],
+    ["Number", BuiltInTypes.Number],

Review Comment:
   `number`?



##########
packages/dmn-feel-antlr4-parser/src/parser/FeelFunctionReturningTypes.ts:
##########
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { DataType } from "./DataType";
+import { BuiltInTypes } from "./BuiltInTypes";
+
+export class FeelFunctionReturningTypes {
+  public static readonly Index: ReadonlyMap<string, DataType> = new 
Map<string, DataType>([
+    ["abs", BuiltInTypes.Number],
+    ["after", BuiltInTypes.Boolean],
+    ["all", BuiltInTypes.Boolean],
+    ["any", BuiltInTypes.Boolean],
+    ["append", BuiltInTypes.List],
+    ["before", BuiltInTypes.Boolean],
+    ["ceiling", BuiltInTypes.Number],
+    ["code", BuiltInTypes.Number],
+    ["coincides", BuiltInTypes.Boolean],
+    ["concatenate", BuiltInTypes.String],
+    ["contains", BuiltInTypes.Boolean],
+    ["context", BuiltInTypes.Context],
+    ["context put", BuiltInTypes.Context],
+    ["context merge", BuiltInTypes.Context],
+    ["count", BuiltInTypes.Number],
+    ["date", BuiltInTypes.Date],
+    ["date and time", BuiltInTypes.DateAndTime],
+    ["day of week", BuiltInTypes.String],
+    ["day of year", BuiltInTypes.Number],
+    ["decimal", BuiltInTypes.Number],
+    ["decision table", BuiltInTypes.Any],
+    ["distinct values", BuiltInTypes.List],
+    ["duration", BuiltInTypes.DaysAndTimeDuration],
+    ["during", BuiltInTypes.Boolean],
+    ["ends with", BuiltInTypes.Boolean],
+    ["even", BuiltInTypes.Boolean],
+    ["exp", BuiltInTypes.Number],
+    ["finished by", BuiltInTypes.Boolean],
+    ["finishes", BuiltInTypes.Boolean],
+    ["flatten", BuiltInTypes.List],
+    ["floor", BuiltInTypes.Number],
+    ["get entries", BuiltInTypes.List],
+    ["get value", BuiltInTypes.Any],
+    ["includes", BuiltInTypes.Boolean],
+    ["index of", BuiltInTypes.List],
+    ["insert before", BuiltInTypes.List],
+    ["invoke", BuiltInTypes.Any],
+    ["is", BuiltInTypes.Boolean],
+    ["list contains", BuiltInTypes.Boolean],
+    ["list replace", BuiltInTypes.List],
+    ["log", BuiltInTypes.Number],
+    ["lower case", BuiltInTypes.String],
+    ["matches", BuiltInTypes.Boolean],
+    ["max", BuiltInTypes.Number],
+    ["mean", BuiltInTypes.Number],
+    ["median", BuiltInTypes.Number],
+    ["meets", BuiltInTypes.Boolean],
+    ["met by", BuiltInTypes.Boolean],
+    ["min", BuiltInTypes.Number],
+    ["mode", BuiltInTypes.Number],
+    ["modulo", BuiltInTypes.Number],
+    ["month of year", BuiltInTypes.String],
+    ["nn all", BuiltInTypes.Boolean],
+    ["nn any", BuiltInTypes.Boolean],
+    ["nn count", BuiltInTypes.Number],
+    ["nn max", BuiltInTypes.Number],
+    ["nn mean", BuiltInTypes.Number],
+    ["nn median", BuiltInTypes.Number],
+    ["nn min", BuiltInTypes.Number],
+    ["nn mode", BuiltInTypes.Number],
+    ["nn stddev", BuiltInTypes.Number],
+    ["nn sum", BuiltInTypes.Number],
+    ["not", BuiltInTypes.Boolean],
+    ["now", BuiltInTypes.DateAndTime],
+    ["Number", BuiltInTypes.Number],
+    ["odd", BuiltInTypes.Boolean],
+    ["overlaps after", BuiltInTypes.Boolean],
+    ["overlaps before", BuiltInTypes.Boolean],
+    ["overlaps", BuiltInTypes.Boolean],
+    ["product", BuiltInTypes.Number],
+    ["range", BuiltInTypes.Range],
+    ["remove", BuiltInTypes.List],
+    ["replace", BuiltInTypes.String],
+    ["reverse", BuiltInTypes.List],
+    ["round down", BuiltInTypes.Number],
+    ["round half down", BuiltInTypes.Number],
+    ["round half up", BuiltInTypes.Number],
+    ["round up", BuiltInTypes.Number],
+    ["sort", BuiltInTypes.List],
+    ["split", BuiltInTypes.List],
+    ["sqrt", BuiltInTypes.Number],
+    ["started by", BuiltInTypes.Boolean],
+    ["starts with", BuiltInTypes.Boolean],
+    ["starts", BuiltInTypes.Boolean],
+    ["stddev", BuiltInTypes.Number],
+    ["string", BuiltInTypes.String],
+    ["string join", BuiltInTypes.String],
+    ["string length", BuiltInTypes.Number],
+    ["subList", BuiltInTypes.List],

Review Comment:
   `sublist`



##########
packages/dmn-feel-antlr4-parser/src/parser/FeelFunctionReturningTypes.ts:
##########
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { DataType } from "./DataType";
+import { BuiltInTypes } from "./BuiltInTypes";
+
+export class FeelFunctionReturningTypes {
+  public static readonly Index: ReadonlyMap<string, DataType> = new 
Map<string, DataType>([
+    ["abs", BuiltInTypes.Number],
+    ["after", BuiltInTypes.Boolean],
+    ["all", BuiltInTypes.Boolean],
+    ["any", BuiltInTypes.Boolean],
+    ["append", BuiltInTypes.List],
+    ["before", BuiltInTypes.Boolean],
+    ["ceiling", BuiltInTypes.Number],
+    ["code", BuiltInTypes.Number],
+    ["coincides", BuiltInTypes.Boolean],
+    ["concatenate", BuiltInTypes.String],
+    ["contains", BuiltInTypes.Boolean],
+    ["context", BuiltInTypes.Context],
+    ["context put", BuiltInTypes.Context],
+    ["context merge", BuiltInTypes.Context],
+    ["count", BuiltInTypes.Number],
+    ["date", BuiltInTypes.Date],
+    ["date and time", BuiltInTypes.DateAndTime],
+    ["day of week", BuiltInTypes.String],
+    ["day of year", BuiltInTypes.Number],
+    ["decimal", BuiltInTypes.Number],
+    ["decision table", BuiltInTypes.Any],
+    ["distinct values", BuiltInTypes.List],
+    ["duration", BuiltInTypes.DaysAndTimeDuration],
+    ["during", BuiltInTypes.Boolean],
+    ["ends with", BuiltInTypes.Boolean],
+    ["even", BuiltInTypes.Boolean],
+    ["exp", BuiltInTypes.Number],
+    ["finished by", BuiltInTypes.Boolean],
+    ["finishes", BuiltInTypes.Boolean],
+    ["flatten", BuiltInTypes.List],
+    ["floor", BuiltInTypes.Number],
+    ["get entries", BuiltInTypes.List],
+    ["get value", BuiltInTypes.Any],
+    ["includes", BuiltInTypes.Boolean],
+    ["index of", BuiltInTypes.List],
+    ["insert before", BuiltInTypes.List],
+    ["invoke", BuiltInTypes.Any],
+    ["is", BuiltInTypes.Boolean],
+    ["list contains", BuiltInTypes.Boolean],
+    ["list replace", BuiltInTypes.List],
+    ["log", BuiltInTypes.Number],
+    ["lower case", BuiltInTypes.String],
+    ["matches", BuiltInTypes.Boolean],
+    ["max", BuiltInTypes.Number],
+    ["mean", BuiltInTypes.Number],
+    ["median", BuiltInTypes.Number],
+    ["meets", BuiltInTypes.Boolean],
+    ["met by", BuiltInTypes.Boolean],
+    ["min", BuiltInTypes.Number],

Review Comment:
   Same as `max`



##########
packages/dmn-feel-antlr4-parser/src/parser/FeelFunctionReturningTypes.ts:
##########
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { DataType } from "./DataType";
+import { BuiltInTypes } from "./BuiltInTypes";
+
+export class FeelFunctionReturningTypes {
+  public static readonly Index: ReadonlyMap<string, DataType> = new 
Map<string, DataType>([
+    ["abs", BuiltInTypes.Number],
+    ["after", BuiltInTypes.Boolean],
+    ["all", BuiltInTypes.Boolean],
+    ["any", BuiltInTypes.Boolean],
+    ["append", BuiltInTypes.List],
+    ["before", BuiltInTypes.Boolean],
+    ["ceiling", BuiltInTypes.Number],
+    ["code", BuiltInTypes.Number],
+    ["coincides", BuiltInTypes.Boolean],
+    ["concatenate", BuiltInTypes.String],
+    ["contains", BuiltInTypes.Boolean],
+    ["context", BuiltInTypes.Context],
+    ["context put", BuiltInTypes.Context],
+    ["context merge", BuiltInTypes.Context],
+    ["count", BuiltInTypes.Number],
+    ["date", BuiltInTypes.Date],
+    ["date and time", BuiltInTypes.DateAndTime],
+    ["day of week", BuiltInTypes.String],
+    ["day of year", BuiltInTypes.Number],
+    ["decimal", BuiltInTypes.Number],
+    ["decision table", BuiltInTypes.Any],
+    ["distinct values", BuiltInTypes.List],
+    ["duration", BuiltInTypes.DaysAndTimeDuration],
+    ["during", BuiltInTypes.Boolean],
+    ["ends with", BuiltInTypes.Boolean],
+    ["even", BuiltInTypes.Boolean],
+    ["exp", BuiltInTypes.Number],
+    ["finished by", BuiltInTypes.Boolean],
+    ["finishes", BuiltInTypes.Boolean],
+    ["flatten", BuiltInTypes.List],
+    ["floor", BuiltInTypes.Number],
+    ["get entries", BuiltInTypes.List],
+    ["get value", BuiltInTypes.Any],
+    ["includes", BuiltInTypes.Boolean],
+    ["index of", BuiltInTypes.List],
+    ["insert before", BuiltInTypes.List],
+    ["invoke", BuiltInTypes.Any],
+    ["is", BuiltInTypes.Boolean],
+    ["list contains", BuiltInTypes.Boolean],
+    ["list replace", BuiltInTypes.List],
+    ["log", BuiltInTypes.Number],
+    ["lower case", BuiltInTypes.String],
+    ["matches", BuiltInTypes.Boolean],
+    ["max", BuiltInTypes.Number],

Review Comment:
   `max` returns `any` as it will return the same type of the list elements.



##########
packages/dmn-feel-antlr4-parser/src/parser/grammar/visitor/FeelVisitorImpl.ts:
##########
@@ -0,0 +1,299 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import FEEL_1_1Visitor from "../generated-parser/FEEL_1_1Visitor";
+import {
+  AddExpressionContext,
+  FilterPathExpressionContext,
+  FnInvocationContext,
+  NameRefContext,
+  ParametersEmptyContext,
+  ParametersNamedContext,
+  ParametersPositionalContext,
+  PrimaryParensContext,
+  QualifiedNameContext,
+  UenpmPrimaryContext,
+} from "../generated-parser/FEEL_1_1Parser";
+import { SemanticToken } from "./SemanticToken";
+import { ParserRuleContext, ParseTree, TerminalNode } from "antlr4";
+import { FeelFunctionReturningTypes } from "../../FeelFunctionReturningTypes";
+import { FeelSyntacticSymbolNature } from "../../FeelSyntacticSymbolNature";
+import { VisitorResult } from "./VisitorResult";
+import { BuiltInTypes } from "../../BuiltInTypes";
+import { DataType } from "../../DataType";
+import FEEL_1_1Lexer from "../generated-parser/FEEL_1_1Lexer";
+
+export class FeelVisitorImpl extends FEEL_1_1Visitor<VisitorResult> {
+  private readonly handlers: Map<Function, (node: ParseTree) => VisitorResult>;
+  private readonly _semanticTokens: Array<SemanticToken>;
+  private readonly _normalizedFeelFunctionReturningTypes: ReadonlyMap<string, 
DataType>;
+
+  public constructor() {
+    super();
+    this._semanticTokens = new Array<SemanticToken>();
+    this.handlers = new Map<Function, (node: ParseTree) => VisitorResult>([
+      [FilterPathExpressionContext, this.visitFilterPathExpression.bind(this)],
+      [FnInvocationContext, this.visitFnInvocation.bind(this)],
+      [NameRefContext, this.visitNameRef.bind(this)],
+      [AddExpressionContext, this.visitAddExpression.bind(this)],
+      [PrimaryParensContext, this.visitPrimaryParens.bind(this)],
+      [UenpmPrimaryContext, this.visitUenpmPrimary.bind(this)],
+    ]);
+
+    this._normalizedFeelFunctionReturningTypes = new Map(
+      Array.from(FeelFunctionReturningTypes.Index, ([key, value]) => 
[key.replaceAll(" ", ""), value])
+    );
+  }
+
+  private getSpecializedHandlerIfPresent(tree: ParseTree) {
+    for (const [klass, handler] of this.handlers) {
+      if (tree instanceof klass) {
+        return handler;
+      }
+    }
+  }
+
+  get semanticTokens(): Array<SemanticToken> {
+    return this._semanticTokens;
+  }
+
+  private resolveNames(nameContext: QualifiedNameContext | NameRefContext) {
+    const resolvedNames: VisitorResult[] = [];
+    if (!nameContext.children) {
+      return resolvedNames;
+    }
+
+    for (let i = 0; i < nameContext.children.length; i++) {
+      const child = nameContext.getChild(i);
+      if (child instanceof NameRefContext || child instanceof 
QualifiedNameContext) {
+        resolvedNames.push(...this.resolveNames(child));
+      } else {
+        resolvedNames.push(this.visit(child));
+      }
+    }
+
+    return resolvedNames;
+  }
+
+  public override visit = (tree: ParseTree) => {
+    // If there is a specialized handler for that kind of node, we use it, 
because it will know how to handle it.
+    // Otherwise, we just go through they children.
+    const specializedHandler = this.getSpecializedHandlerIfPresent(tree);
+    if (specializedHandler) {
+      return specializedHandler(tree);
+    } else if (tree instanceof ParserRuleContext) {
+      return this.visitChildren(tree);
+    } else if (tree instanceof TerminalNode) {
+      return new VisitorResult({ text: tree.getText(), dataType: 
this.getBuiltInTypeFromNodeType(tree.symbol.type) });
+    }
+    return undefined!;
+  };
+
+  public override visitChildren(ctx: ParserRuleContext) {
+    if (!ctx.children) {
+      return undefined!;
+    }
+
+    const result = new Array<VisitorResult>();
+    const count = ctx.children?.length ?? 0;
+    for (let i = 0; i < count; i++) {
+      result.push(this.visit(ctx.children[i])!);
+    }
+
+    // In case of multiple children, probably we need a specialized handler to 
deal with,
+    // but we are not doing that now because is one of the cases that we don't
+    // use in the autocomplete or colorize.
+    return result[0];
+  }
+
+  public override visitUenpmPrimary = (ctx: UenpmPrimaryContext) => {
+    if (ctx.primary() === null || ctx.qualifiedName() === null || ctx.children 
=== null) {
+      return this.visitChildren(ctx);
+    }
+
+    // something DOT property
+    const beforeDot = this.visit(ctx.primary());
+    const afterDot = this.resolveNames(ctx.qualifiedName());
+
+    // Here, we care about the first result after dot
+    if (beforeDot.dataType.properties.has(afterDot[0].text)) {
+      const startIndex = ctx.qualifiedName().start.start - 1;
+      this._semanticTokens.push(
+        new SemanticToken({
+          startIndex: startIndex,
+          endIndex: startIndex + afterDot[0].text.length,
+          startLine: ctx.qualifiedName().start.line,
+          endLine: ctx.qualifiedName().start.line,
+          symbolNature: FeelSyntacticSymbolNature.LocalVariable,
+          dataTypeReturn: beforeDot.dataType.properties.get(afterDot[0].text)!,
+          text: afterDot[0].text,
+        })
+      );
+    }
+
+    const lastChildren = ctx.children[ctx.children.length - 1];
+    if (
+      lastChildren instanceof ParametersPositionalContext ||
+      lastChildren instanceof ParametersEmptyContext ||
+      lastChildren instanceof ParametersNamedContext
+    ) {
+      const text = afterDot[afterDot.length - 1].text;
+
+      // Each expression has a type of expected parameters.
+      if (this._normalizedFeelFunctionReturningTypes.has(text)) {
+        this._semanticTokens.push(
+          new SemanticToken({
+            startIndex: lastChildren.LPAREN().symbol.start,
+            endIndex: lastChildren.RPAREN().symbol.start,
+            startLine: lastChildren.LPAREN().symbol.line,
+            endLine: lastChildren.RPAREN().symbol.line,
+            symbolNature: FeelSyntacticSymbolNature.FunctionCall,
+            dataTypeReturn: 
this._normalizedFeelFunctionReturningTypes.get(text)!,
+            text: "", // Empty string. It doesn't have a text.
+          })
+        );
+
+        return new VisitorResult({
+          text: ctx.getText(),
+          dataType: this._normalizedFeelFunctionReturningTypes.get(text),
+        });
+      }
+    }
+
+    return new VisitorResult({ text: ctx.getText(), dataType: 
beforeDot.dataType.properties.get(afterDot[0].text) });
+  };
+
+  public override visitPrimaryParens = (ctx: PrimaryParensContext) => {
+    const innerExpressionResult = this.visit(ctx.expression());
+
+    this._semanticTokens.push(
+      new SemanticToken({
+        startIndex: ctx.RPAREN().symbol.start - 1,
+        endIndex: ctx.RPAREN().symbol.start,
+        startLine: ctx.RPAREN().symbol.line,
+        endLine: ctx.RPAREN().symbol.line,
+        symbolNature: FeelSyntacticSymbolNature.FunctionCall,
+        dataTypeReturn: innerExpressionResult.dataType,
+        text: ")",
+      })
+    );
+
+    return innerExpressionResult;
+  };
+
+  public override visitAddExpression = (ctx: AddExpressionContext) => {
+    const additiveExpression = ctx.additiveExpression();
+    const multiplicativeExpression = ctx.multiplicativeExpression();
+
+    const addResult = this.visit(additiveExpression);
+    const multResult = this.visit(multiplicativeExpression);
+
+    if (addResult.dataType === multResult.dataType) {
+      if (addResult.dataType === BuiltInTypes.Date) {
+        return new VisitorResult({ text: ctx.getText(), dataType: 
BuiltInTypes.DaysAndTimeDuration });
+      } else {
+        return new VisitorResult({ text: ctx.getText(), dataType: 
addResult.dataType });
+      }
+    } else {
+      // We return he right-most result, because the expression is 
inconsistent.
+      // In this case, we can assume that the user is typing.
+      return new VisitorResult({ text: ctx.getText(), dataType: 
multResult.dataType });
+    }
+  };
+
+  public override visitNameRef = (ctx: NameRefContext) => {
+    return this.visitChildren(ctx);
+  };
+
+  public override visitFilterPathExpression = (ctx: 
FilterPathExpressionContext) => {
+    if (ctx.filterPathExpression() === null || ctx.qualifiedName() === null || 
ctx.qualifiedName().children === null) {
+      return this.visitChildren(ctx);
+    }
+
+    const beforeDot = this.visit(ctx.filterPathExpression());
+    const afterDot = this.resolveNames(ctx.qualifiedName());
+
+    // Here, we care about the first result after dot
+    if (beforeDot.dataType.properties.has(afterDot[0].text)) {
+      const startIndex = ctx.qualifiedName().start.start - 1;
+      this._semanticTokens.push(
+        new SemanticToken({
+          startIndex: startIndex,
+          endIndex: startIndex + afterDot[0].text.length,
+          startLine: ctx.qualifiedName().start.line,
+          endLine: ctx.qualifiedName().start.line,
+          symbolNature: FeelSyntacticSymbolNature.LocalVariable,
+          dataTypeReturn: beforeDot.dataType.properties.get(afterDot[0].text)!,
+          text: afterDot[0].text,
+        })
+      );
+    }
+
+    return new VisitorResult({ text: ctx.getText(), dataType: 
beforeDot.dataType.properties.get(afterDot[0].text) });
+  };
+
+  public override visitFnInvocation = (ctx: FnInvocationContext) => {
+    if (ctx.children?.length != 2) {
+      return undefined!;
+    }

Review Comment:
   Shouldn't this throw an error instead of returning `undefined!`? Could you 
please add a comment for this scenario?



##########
packages/dmn-feel-antlr4-parser/src/parser/FeelFunctionReturningTypes.ts:
##########
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { DataType } from "./DataType";
+import { BuiltInTypes } from "./BuiltInTypes";
+
+export class FeelFunctionReturningTypes {
+  public static readonly Index: ReadonlyMap<string, DataType> = new 
Map<string, DataType>([
+    ["abs", BuiltInTypes.Number],
+    ["after", BuiltInTypes.Boolean],
+    ["all", BuiltInTypes.Boolean],
+    ["any", BuiltInTypes.Boolean],
+    ["append", BuiltInTypes.List],
+    ["before", BuiltInTypes.Boolean],
+    ["ceiling", BuiltInTypes.Number],
+    ["code", BuiltInTypes.Number],
+    ["coincides", BuiltInTypes.Boolean],
+    ["concatenate", BuiltInTypes.String],
+    ["contains", BuiltInTypes.Boolean],
+    ["context", BuiltInTypes.Context],
+    ["context put", BuiltInTypes.Context],
+    ["context merge", BuiltInTypes.Context],
+    ["count", BuiltInTypes.Number],
+    ["date", BuiltInTypes.Date],
+    ["date and time", BuiltInTypes.DateAndTime],
+    ["day of week", BuiltInTypes.String],
+    ["day of year", BuiltInTypes.Number],
+    ["decimal", BuiltInTypes.Number],
+    ["decision table", BuiltInTypes.Any],
+    ["distinct values", BuiltInTypes.List],
+    ["duration", BuiltInTypes.DaysAndTimeDuration],

Review Comment:
   I believe this could return `YearsAndMonthsDuration` too, or not?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to