zeroflag commented on a change in pull request #537: URL: https://github.com/apache/knox/pull/537#discussion_r814273246
########## 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: Interesting. I like to get over the easy checks (like if the argument is null) first and do an early return if something is trivially invalid. Then everything below that can expect valid arguments. You would probably like Lisp since it's expression based (there are no statements - including explicit `return` - in it). :) I'll change this too. -- 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