pzampino commented on a change in pull request #537:
URL: https://github.com/apache/knox/pull/537#discussion_r814235328



##########
File path: 
gateway-util-common/src/main/java/org/apache/knox/gateway/plang/Ast.java
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.
+ */
+package org.apache.knox.gateway.plang;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Ast {
+    private final List<Ast> children = new ArrayList<>();
+    private final String token;
+
+    public Ast(String token) {
+        this.token = token;
+    }
+
+    public void addChild(Ast child) {
+        children.add(child);
+    }
+
+    @Override
+    public String toString() {
+        return isAtom() ? token : children.toString();
+    }
+
+    public String token() {
+        return token;
+    }
+
+    public boolean isStr() {
+        return token != null && token.startsWith("'") && token.endsWith("'");

Review comment:
       Are tokens allowed to be empty (i.e., '')?

##########
File path: 
gateway-util-common/src/main/java/org/apache/knox/gateway/plang/Ast.java
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.
+ */
+package org.apache.knox.gateway.plang;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Ast {
+    private final List<Ast> children = new ArrayList<>();
+    private final String token;
+
+    public Ast(String token) {
+        this.token = token;
+    }
+
+    public void addChild(Ast child) {
+        children.add(child);
+    }
+
+    @Override
+    public String toString() {
+        return isAtom() ? token : children.toString();
+    }
+
+    public String token() {
+        return token;
+    }
+
+    public boolean isStr() {
+        return token != null && token.startsWith("'") && token.endsWith("'");
+    }
+
+    public boolean isNumber() {
+        if (token == null) {

Review comment:
       I personally prefer single return statements whenever possible.
   ```suggestion
   boolean result = false;
   if (token !=null) {
     try {
        numValue();
        result = true;
      } catch (NumberFormatException e) {
        // NaN
      }
   }
   return result;

##########
File path: 
gateway-util-common/src/main/java/org/apache/knox/gateway/plang/Ast.java
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.
+ */
+package org.apache.knox.gateway.plang;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Ast {
+    private final List<Ast> children = new ArrayList<>();
+    private final String token;
+
+    public Ast(String token) {
+        this.token = token;
+    }
+
+    public void addChild(Ast child) {
+        children.add(child);
+    }
+
+    @Override
+    public String toString() {
+        return isAtom() ? token : children.toString();
+    }
+
+    public String token() {
+        return token;
+    }
+
+    public boolean isStr() {
+        return token != null && token.startsWith("'") && token.endsWith("'");
+    }
+
+    public boolean isNumber() {
+        if (token == null) {
+            return false;
+        }
+        try {
+            numValue();
+            return true;
+        } catch (NumberFormatException e) {
+            return false;
+        }
+    }
+
+    public Number numValue() {
+        try {
+            return Long.parseLong(token);
+        } catch (NumberFormatException e) {
+            return Double.parseDouble(token);
+        }
+    }
+
+    public String strValue() {
+        return token.substring(1, token.length() -1);

Review comment:
       Would it be overkill to wrap this in a call to isStr() for validation?

##########
File path: 
gateway-util-common/src/main/java/org/apache/knox/gateway/plang/Ast.java
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.
+ */
+package org.apache.knox.gateway.plang;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Ast {

Review comment:
       I would still like to see this class name spelled out as 
AbstractSyntaxtTree.




-- 
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: dev-unsubscr...@knox.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to