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



##########
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:
       AST stands for Abstract Syntax Tree, it is language implementation 
terminology. The parser produces the AST, which is a tree structure that 
represents the source code. In our cases it's list of lists (which is also a 
tree). 
   
   Fr example this is the text:
   
   ```
   (or true (and false true))
   ```
   
   This is the AST emitted by the parser. `See the AST>>toString`
   
   ```
   [or, true, [and, false, true]]
   ```
   
   It's a homoiconic language so there is 1 to 1 mapping between the text and 
the AST. It has the exact same structure, we just put everything into Java 
types, like `java.util.ArrayLists` and `java.lang.Booleans`.
   
   We could have represented the AST as arbitrarily nested a `java.util.List`, 
but the Java's type system doesn't handle this nesting very well: 
`List<List<List<..> or Atom> or Atom>`, that's why we have a dedicated class.
   
   The interpreter gets the AST and evaluates it. In our case the interpreter 
is a simple tree walking interpreter so it just recursively  evaluates the tree.
   
   In the filter we store the AST not the text, so every time a request comes 
in, we just need to interpret, without using the parser.
   




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