You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/07/28 09:58:24 UTC

[shardingsphere] branch master updated: Create new definition and visitors (#6489)

This is an automated email from the ASF dual-hosted git repository.

zhangyonglun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 00e24e0  Create new definition and visitors (#6489)
00e24e0 is described below

commit 00e24e049bb2f0505ccdfc78461b673e105ae718
Author: Juan Pan(Trista) <pa...@apache.org>
AuthorDate: Tue Jul 28 17:58:11 2020 +0800

    Create new definition and visitors (#6489)
---
 .../shardingsphere-rdl-parser-sql/pom.xml          |  7 +++-
 .../src/main/antlr4/imports/Literals.g4            |  2 +-
 .../src/main/antlr4/imports/RDLStatement.g4        | 41 +++++++++++++++++--
 .../src/main/antlr4/imports/Symbol.g4              |  1 +
 .../parser/sql/autogen/ShardingSphereStatement.g4} | 36 +++--------------
 .../parser/sql/visitor/ShardingSphereVisitor.java} | 47 ++++++++--------------
 .../shardingsphere-rdl-parser-statement/pom.xml    |  8 ++++
 7 files changed, 75 insertions(+), 67 deletions(-)

diff --git a/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/pom.xml b/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/pom.xml
index 957e4d6..37145bd 100644
--- a/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/pom.xml
+++ b/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/pom.xml
@@ -36,6 +36,11 @@
             <groupId>org.antlr</groupId>
             <artifactId>antlr4-runtime</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-sql-parser-spi</artifactId>
+            <version>${project.version}</version>
+        </dependency>
     </dependencies>
 
     <build>
@@ -47,7 +52,7 @@
                     <execution>
                         <id>antlr</id>
                         <configuration>
-                            <libDirectory>src/main/antlr4/imports/mysql/</libDirectory>
+                            <libDirectory>src/main/antlr4/imports/</libDirectory>
                             <listener>false</listener>
                             <visitor>true</visitor>
                         </configuration>
diff --git a/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/Literals.g4 b/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/Literals.g4
index 263cd93..c6483e3 100644
--- a/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/Literals.g4
+++ b/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/Literals.g4
@@ -21,7 +21,7 @@ import Alphabet, Symbol;
 
 IDENTIFIER
     : [A-Za-z$0-9]*?[A-Za-z$]+?[A-Za-z$0-9]*
-    |  BQ ~'`'+ BQ
+    | BQ ~'`'+ BQ
     | (DQ ( '\\'. | '""' | ~('"'| '\\') )* DQ)
     ;
     
diff --git a/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/RDLStatement.g4 b/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/RDLStatement.g4
index 89fd428..7f7be77 100644
--- a/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/RDLStatement.g4
+++ b/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/RDLStatement.g4
@@ -20,9 +20,17 @@ grammar RDLStatement;
 import Keyword, Literals, Symbol;
 
 createDatasource
-    : CREATE DATASOURCE datasource (COMMA datasource)* SEMI*
+    : CREATE DATASOURCE datasource (COMMA datasource)*
     ;
-    
+
+createShardingrule
+    : CREATE SHARDINGRULE shardingrule (COMMA shardingrule)*
+    ;
+
+shardingrule
+    : key EQ shardingruleValue
+    ;
+
 datasource
     : key EQ datasourceValue
     ;
@@ -34,7 +42,34 @@ key
 datasourceValue
     : hostName COLON port COLON dbName
     ;
-    
+
+shardingruleValue
+    : strategyType LP strategyValue RP
+    ;
+
+strategyType
+    : IDENTIFIER
+    ;
+
+strategyValue
+    : tableName COMMA columName COMMA strategyProps+
+    ;
+
+strategyProps
+    : strategyProp (COMMA strategyProp)*
+    ;
+strategyProp
+    : IDENTIFIER | NUMBER | INT
+    ;
+
+tableName
+    : IDENTIFIER UL* IDENTIFIER*
+    ;
+
+columName
+    : IDENTIFIER UL* IDENTIFIER*
+    ;
+
 hostName
     : ip | IDENTIFIER
     ;
diff --git a/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/Symbol.g4 b/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/Symbol.g4
index 86d7933..a332bdd 100644
--- a/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/Symbol.g4
+++ b/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/Symbol.g4
@@ -58,3 +58,4 @@ QUESTION:           '?';
 AT:                 '@';
 SEMI:               ';';
 JSONSEPARATOR:      '->>';
+UL:                 '_';
diff --git a/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/RDLStatement.g4 b/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/org/apache/shardingsphere/rdl/parser/sql/autogen/ShardingSphereStatement.g4
similarity index 65%
copy from shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/RDLStatement.g4
copy to shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/org/apache/shardingsphere/rdl/parser/sql/autogen/ShardingSphereStatement.g4
index 89fd428..4e25fc0 100644
--- a/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/RDLStatement.g4
+++ b/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/org/apache/shardingsphere/rdl/parser/sql/autogen/ShardingSphereStatement.g4
@@ -15,37 +15,11 @@
  * limitations under the License.
  */
 
-grammar RDLStatement;
+grammar ShardingSphereStatement;
 
-import Keyword, Literals, Symbol;
+import Symbol, RDLStatement;
 
-createDatasource
-    : CREATE DATASOURCE datasource (COMMA datasource)* SEMI*
-    ;
-    
-datasource
-    : key EQ datasourceValue
-    ;
-    
-key
-    : IDENTIFIER
-    ;
-    
-datasourceValue
-    : hostName COLON port COLON dbName
-    ;
-    
-hostName
-    : ip | IDENTIFIER
-    ;
-
-ip
-    : NUMBER+ INT
-    ;
-port
-    : INT
-    ;
-    
-dbName
-    : IDENTIFIER | NUMBER
+execute
+    : (createDatasource
+    ) SEMI?
     ;
diff --git a/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/Literals.g4 b/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/java/org/apache/shardingsphere/rdl/parser/sql/visitor/ShardingSphereVisitor.java
similarity index 54%
copy from shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/Literals.g4
copy to shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/java/org/apache/shardingsphere/rdl/parser/sql/visitor/ShardingSphereVisitor.java
index 263cd93..5b6ddbe 100644
--- a/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/Literals.g4
+++ b/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/java/org/apache/shardingsphere/rdl/parser/sql/visitor/ShardingSphereVisitor.java
@@ -15,37 +15,22 @@
  * limitations under the License.
  */
 
-lexer grammar Literals;
+package org.apache.shardingsphere.rdl.parser.sql.visitor;
 
-import Alphabet, Symbol;
+import lombok.AccessLevel;
+import lombok.Getter;
+import org.apache.shardingsphere.rdl.parser.sql.autogen.ShardingSphereStatementBaseVisitor;
+import org.apache.shardingsphere.rdl.parser.sql.autogen.ShardingSphereStatementParser;
+import org.apache.shardingsphere.sql.parser.api.ASTNode;
 
-IDENTIFIER
-    : [A-Za-z$0-9]*?[A-Za-z$]+?[A-Za-z$0-9]*
-    |  BQ ~'`'+ BQ
-    | (DQ ( '\\'. | '""' | ~('"'| '\\') )* DQ)
-    ;
-    
-STRING
-    : (DQ ( '\\'. | '""' | ~('"'| '\\') )* DQ)
-    | (SQ ('\\'. | '\'\'' | ~('\'' | '\\'))* SQ)
-    ;
-
-INT
-    : [0-9]+
-    ;
-
-HEX
-    : [0-9a-fA-F]
-    ;
-
-NUMBER
-    : INT? DOT? INT (E (PLUS | MINUS)? INT)?
-    ;
-
-HEXDIGIT
-    : '0x' HEX+ | 'X' SQ HEX+ SQ
-    ;
+/**
+ * MySQL visitor.
+ */
+@Getter(AccessLevel.PROTECTED)
+public final class ShardingSphereVisitor extends ShardingSphereStatementBaseVisitor<ASTNode> {
     
-BITNUM
-    : '0b' ('0' | '1')+ | B SQ ('0' | '1')+ SQ
-    ;
+    @Override
+    public ASTNode visitCreateDatasource(final ShardingSphereStatementParser.CreateDatasourceContext ctx) {
+        return super.visitCreateDatasource(ctx);
+    }
+}
diff --git a/shardingsphere-rdl-parser/shardingsphere-rdl-parser-statement/pom.xml b/shardingsphere-rdl-parser/shardingsphere-rdl-parser-statement/pom.xml
index dba2243..7b42583 100644
--- a/shardingsphere-rdl-parser/shardingsphere-rdl-parser-statement/pom.xml
+++ b/shardingsphere-rdl-parser/shardingsphere-rdl-parser-statement/pom.xml
@@ -27,4 +27,12 @@
     </parent>
     <artifactId>shardingsphere-rdl-parser-statement</artifactId>
     <name>${project.artifactId}</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-sql-parser-statement</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+    </dependencies>
 </project>