carloea2 commented on code in PR #5043:
URL: https://github.com/apache/texera/pull/5043#discussion_r3271431500


##########
frontend/src/app/workspace/service/code-editor/ui-udf-parameters-parser.service.ts:
##########
@@ -0,0 +1,217 @@
+/**
+ * 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 { Injectable } from "@angular/core";
+import { parser } from "@lezer/python";
+import { AttributeType, SchemaAttribute } from 
"../../types/workflow-compiling.interface";
+
+export interface UiUdfParameter {
+  attribute: SchemaAttribute;
+  value: string;
+}
+
+const CLASSES = new Set(["ProcessTupleOperator", "ProcessBatchOperator", 
"ProcessTableOperator", "GenerateOperator"]);
+
+// Java enum constant names (AttributeType.java)
+const JAVA_ATTRIBUTE_TYPE_NAMES = [
+  "STRING",
+  "INTEGER",
+  "LONG",
+  "DOUBLE",
+  "BOOLEAN",
+  "TIMESTAMP",
+  "BINARY",
+  "LARGE_BINARY",
+] as const;
+
+type JavaAttributeTypeName = (typeof JAVA_ATTRIBUTE_TYPE_NAMES)[number];
+
+// Python enum constant names (core.models.AttributeType)
+const PYTHON_ATTRIBUTE_TYPE_NAMES = [
+  "STRING",
+  "INT",
+  "LONG",
+  "DOUBLE",
+  "BOOL",
+  "TIMESTAMP",
+  "BINARY",
+  "LARGE_BINARY",
+] as const;
+
+type PythonAttributeTypeName = (typeof PYTHON_ATTRIBUTE_TYPE_NAMES)[number];
+
+type ParserAttributeTypeToken = JavaAttributeTypeName | 
PythonAttributeTypeName;
+type UnsupportedParserAttributeTypeToken = "BINARY" | "LARGE_BINARY";
+type SupportedParserAttributeTypeToken = Exclude<ParserAttributeTypeToken, 
UnsupportedParserAttributeTypeToken>;
+type ParserSyntaxNode = ReturnType<typeof parser.parse>["topNode"];
+
+const TYPES: Readonly<Record<SupportedParserAttributeTypeToken, 
AttributeType>> = {
+  STRING: "string",
+  INTEGER: "integer",
+  INT: "integer",
+  LONG: "long",
+  DOUBLE: "double",
+  BOOLEAN: "boolean",
+  BOOL: "boolean",
+  TIMESTAMP: "timestamp",
+};
+
+const JAVA_ATTRIBUTE_TYPE_NAME_SET = new 
Set<string>(JAVA_ATTRIBUTE_TYPE_NAMES);
+const PYTHON_ATTRIBUTE_TYPE_NAME_SET = new 
Set<string>(PYTHON_ATTRIBUTE_TYPE_NAMES);
+const SUPPORTED_UI_PARAMETER_ATTRIBUTE_TYPES = new Set<AttributeType>([
+  "string",
+  "integer",
+  "long",
+  "double",
+  "boolean",
+  "timestamp",
+]);
+
+@Injectable({ providedIn: "root" })
+export class UiUdfParametersParserService {
+  parse(code: string): UiUdfParameter[] {
+    if (!code) return [];
+
+    const result: UiUdfParameter[] = [];
+    const seen = new Set<string>();
+    const add = (parameter?: UiUdfParameter): void => {
+      const name = parameter?.attribute.attributeName;
+      if (parameter && name && !seen.has(name)) {
+        seen.add(name);
+        result.push(parameter);
+      }
+    };
+
+    parser.parse(code).iterate({
+      enter: ({ name, node }) => {
+        const className = node.getChild("VariableName");
+        if (name !== "ClassDefinition" || !className || 
!CLASSES.has(code.slice(className.from, className.to))) return;
+        node
+          .cursor()
+          .iterate(ref => (ref.name === "CallExpression" ? 
(add(readCall(ref.node, code)), false) : undefined));
+        return false;

Review Comment:
   Fixed. I rewrote the Lezer traversal callback as an explicit block so the 
`return false` is clearly intentional.
   
   Change: `ui-udf-parameters-parser.service.ts`
   
   ```ts
   node.cursor().iterate(cursorReference => {
     if (cursorReference.name !== "CallExpression") return;
     addParameter(readCall(cursorReference.node, code));
     return false;
   });



-- 
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]

Reply via email to