sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jso...@apache.org
Subject [sis] branch geoapi-4.0 updated: CQL : move all antlr specific methods in internal package
Date Fri, 16 Aug 2019 09:17:30 GMT
This is an automated email from the ASF dual-hosted git repository.

jsorel pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 804cd1a  CQL : move all antlr specific methods in internal package
804cd1a is described below

commit 804cd1a42b0a6fa7c6a2d21f5ef2458d17f3b6c4
Author: jsorel <johann.sorel@geomatys.com>
AuthorDate: Fri Aug 16 11:17:14 2019 +0200

    CQL : move all antlr specific methods in internal package
---
 .../src/main/java/org/apache/sis/cql/CQL.java      |  89 +-----------------
 .../java/org/apache/sis/internal/cql/AntlrCQL.java | 100 +++++++++++++++++++++
 2 files changed, 103 insertions(+), 86 deletions(-)

diff --git a/core/sis-cql/src/main/java/org/apache/sis/cql/CQL.java b/core/sis-cql/src/main/java/org/apache/sis/cql/CQL.java
index 8ae0bd0..8adfe41 100644
--- a/core/sis-cql/src/main/java/org/apache/sis/cql/CQL.java
+++ b/core/sis-cql/src/main/java/org/apache/sis/cql/CQL.java
@@ -19,17 +19,10 @@ package org.apache.sis.cql;
 import java.time.temporal.TemporalAccessor;
 import java.util.ArrayList;
 import java.util.List;
-import javax.swing.tree.DefaultMutableTreeNode;
-import org.antlr.v4.runtime.CharStreams;
-import org.antlr.v4.runtime.CodePointCharStream;
-import org.antlr.v4.runtime.CommonTokenStream;
-import org.antlr.v4.runtime.RecognitionException;
-import org.antlr.v4.runtime.TokenStream;
 import org.antlr.v4.runtime.tree.ParseTree;
 import org.antlr.v4.runtime.tree.TerminalNode;
 import org.apache.sis.filter.DefaultFilterFactory;
-import org.apache.sis.internal.cql.CQLLexer;
-import org.apache.sis.internal.cql.CQLParser;
+import org.apache.sis.internal.cql.AntlrCQL;
 import static org.apache.sis.internal.cql.CQLParser.*;
 import org.apache.sis.internal.cql.CQLParser.CoordinateContext;
 import org.apache.sis.internal.cql.CQLParser.CoordinateSerieContext;
@@ -42,7 +35,6 @@ import org.apache.sis.internal.cql.CQLParser.ExpressionTermContext;
 import org.apache.sis.internal.cql.CQLParser.ExpressionUnaryContext;
 import org.apache.sis.internal.cql.CQLParser.FilterContext;
 import org.apache.sis.internal.cql.CQLParser.FilterGeometryContext;
-import org.apache.sis.internal.cql.CQLParser.FilterOrExpressionContext;
 import org.apache.sis.internal.cql.CQLParser.FilterTermContext;
 import org.apache.sis.internal.util.StandardDateFormat;
 import org.locationtech.jts.geom.Coordinate;
@@ -73,73 +65,12 @@ public final class CQL {
     private CQL() {
     }
 
-    private static Object compileExpression(String cql) {
-        try {
-            //lexer splits input into tokens
-            final CodePointCharStream input = CharStreams.fromString(cql);
-            final TokenStream tokens = new CommonTokenStream(new CQLLexer(input));
-
-            //parser generates abstract syntax tree
-            final CQLParser parser = new CQLParser(tokens);
-            final ExpressionContext ctx = parser.expression();
-            return ctx;
-
-        } catch (RecognitionException e) {
-            throw new IllegalStateException("Recognition exception is never thrown, only
declared.");
-        }
-    }
-
-    private static Object compileFilter(String cql) {
-        try {
-            //lexer splits input into tokens
-            final CodePointCharStream input = CharStreams.fromString(cql);
-            final TokenStream tokens = new CommonTokenStream(new CQLLexer(input));
-
-            //parser generates abstract syntax tree
-            final CQLParser parser = new CQLParser(tokens);
-            final FilterContext retfilter = parser.filter();
-
-            return retfilter;
-
-        } catch (RecognitionException e) {
-            throw new IllegalStateException("Recognition exception is never thrown, only
declared.");
-        }
-    }
-
-    private static Object compileFilterOrExpression(String cql) {
-        try {
-            //lexer splits input into tokens
-            final CodePointCharStream input = CharStreams.fromString(cql);
-            final TokenStream tokens = new CommonTokenStream(new CQLLexer(input));
-
-            //parser generates abstract syntax tree
-            final CQLParser parser = new CQLParser(tokens);
-            final FilterOrExpressionContext retfilter = parser.filterOrExpression();
-
-            return retfilter;
-
-        } catch (RecognitionException e) {
-            throw new IllegalStateException("Recognition exception is never thrown, only
declared.");
-        }
-    }
-
-    public static ParseTree compile(String cql) {
-        final Object obj = compileFilterOrExpression(cql);
-
-        ParseTree tree = null;
-        if (obj instanceof ParseTree) {
-            tree = (ParseTree) obj;
-        }
-
-        return tree;
-    }
-
     public static Expression parseExpression(String cql) throws CQLException {
         return parseExpression(cql, null);
     }
 
     public static Expression parseExpression(String cql, FilterFactory2 factory) throws CQLException
{
-        final Object obj = compileExpression(cql);
+        final Object obj = AntlrCQL.compileExpression(cql);
 
         ParseTree tree = null;
         Expression result = null;
@@ -166,7 +97,7 @@ public final class CQL {
             return Filter.INCLUDE;
         }
 
-        final Object obj = compileFilter(cql);
+        final Object obj = AntlrCQL.compileFilter(cql);
 
         ParseTree tree = null;
         Filter result = null;
@@ -202,20 +133,6 @@ public final class CQL {
     }
 
     /**
-     * Create a TreeNode for the given tree. method is recursive.
-     */
-    private static DefaultMutableTreeNode explore(ParseTree tree) {
-        final DefaultMutableTreeNode node = new DefaultMutableTreeNode(tree);
-
-        final int nb = tree.getChildCount();
-        for (int i = 0; i < nb; i++) {
-            final DefaultMutableTreeNode n = explore((ParseTree) tree.getChild(i));
-            node.add(n);
-        }
-        return node;
-    }
-
-    /**
      * Convert the given tree in an Expression.
      */
     private static Expression convertExpression(ParseTree tree, FilterFactory2 ff) throws
CQLException {
diff --git a/core/sis-cql/src/main/java/org/apache/sis/internal/cql/AntlrCQL.java b/core/sis-cql/src/main/java/org/apache/sis/internal/cql/AntlrCQL.java
new file mode 100644
index 0000000..f63ddc8
--- /dev/null
+++ b/core/sis-cql/src/main/java/org/apache/sis/internal/cql/AntlrCQL.java
@@ -0,0 +1,100 @@
+/*
+ * 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.sis.internal.cql;
+
+import org.antlr.v4.runtime.CharStreams;
+import org.antlr.v4.runtime.CodePointCharStream;
+import org.antlr.v4.runtime.CommonTokenStream;
+import org.antlr.v4.runtime.RecognitionException;
+import org.antlr.v4.runtime.TokenStream;
+import org.antlr.v4.runtime.tree.ParseTree;
+
+/**
+ * ANTLR CQL parser methods.
+ * 
+ * @author Johann Sorel (Geomatys)
+ * @version 1.0
+ * @since 1.0
+ * @module
+ */
+public final class AntlrCQL {
+
+    private AntlrCQL() {
+    }
+
+    public static ParseTree compile(String cql) {
+        final Object obj = compileFilterOrExpression(cql);
+
+        ParseTree tree = null;
+        if (obj instanceof ParseTree) {
+            tree = (ParseTree) obj;
+        }
+
+        return tree;
+    }
+
+    public static Object compileExpression(String cql) {
+        try {
+            //lexer splits input into tokens
+            final CodePointCharStream input = CharStreams.fromString(cql);
+            final TokenStream tokens = new CommonTokenStream(new CQLLexer(input));
+
+            //parser generates abstract syntax tree
+            final CQLParser parser = new CQLParser(tokens);
+            final CQLParser.ExpressionContext ctx = parser.expression();
+            return ctx;
+
+        } catch (RecognitionException e) {
+            throw new IllegalStateException("Recognition exception is never thrown, only
declared.");
+        }
+    }
+
+    public static Object compileFilter(String cql) {
+        try {
+            //lexer splits input into tokens
+            final CodePointCharStream input = CharStreams.fromString(cql);
+            final TokenStream tokens = new CommonTokenStream(new CQLLexer(input));
+
+            //parser generates abstract syntax tree
+            final CQLParser parser = new CQLParser(tokens);
+            final CQLParser.FilterContext retfilter = parser.filter();
+
+            return retfilter;
+
+        } catch (RecognitionException e) {
+            throw new IllegalStateException("Recognition exception is never thrown, only
declared.");
+        }
+    }
+
+    public static Object compileFilterOrExpression(String cql) {
+        try {
+            //lexer splits input into tokens
+            final CodePointCharStream input = CharStreams.fromString(cql);
+            final TokenStream tokens = new CommonTokenStream(new CQLLexer(input));
+
+            //parser generates abstract syntax tree
+            final CQLParser parser = new CQLParser(tokens);
+            final CQLParser.FilterOrExpressionContext retfilter = parser.filterOrExpression();
+
+            return retfilter;
+
+        } catch (RecognitionException e) {
+            throw new IllegalStateException("Recognition exception is never thrown, only
declared.");
+        }
+    }
+
+}


Mime
View raw message