qiaojialin commented on a change in pull request #366: [IOTDB-190] upgrade from 
antlr3 to antlr4
URL: https://github.com/apache/incubator-iotdb/pull/366#discussion_r320586869
 
 

 ##########
 File path: server/src/main/antlr4/org/apache/iotdb/db/sql/parse/TSParser.g4
 ##########
 @@ -0,0 +1,535 @@
+//
+// 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.
+//
+
+parser grammar TSParser;
+
+options
+{
+tokenVocab=TSLexer;
+}
+
+// starting rule
+statement
+       : execStatement (SEMICOLON)? EOF
+       ;
+
+nonNegativeInteger
+    : PositiveInteger
+    | UnsignedInteger
+    ;
+
+integer
+    : NegativeInteger
+    | nonNegativeInteger
+    ;
+
+// ATTENTION: DO NOT USE NAME 'float'!
+floatValue
+    : PositiveFloat # x_positiveFloat
+    | NegativeFloat # x_negativeInteger
+    | PositiveInteger DOT   # x_positiveIntegerDot
+    | NegativeInteger DOT   # x_negativeIntegerDot
+    | UnsignedInteger DOT UnsignedInteger # x_unsignedIntegerDotUnsignedInteger
+    | UnsignedInteger DOT # x_unsignedIntegerDot
+    | DOT UnsignedInteger   # x_dotUnsignedInteger
+    | UnsignedInteger DoubleInScientificNotationSuffix # 
x_unsignedIntegerDoubleInScientificNotationSuffix
+    | DoubleInScientificNotationSuffix # x_doubleInScientificNotationSuffix
+    ;
+
+number
+    : integer # integerString
+    | floatValue # floatString
+    | Boolean # booleanString
+    ;
+
+numberOrString // identifier is string or integer
+    : Boolean | floatValue | identifier
+    ;
+
+numberOrStringWidely
+    : number
+    | StringLiteral
+    ;
+
+execStatement
+    : authorStatement  # exeAuthorStat
+    | deleteStatement  # exeDeleteStat
+    | updateStatement  # exeUpdateStat
+    | insertStatement  # exeInsertStat
+    | queryStatement  # exeQueryStat
+    | metadataStatement  # exeMetaStat
+    | mergeStatement  # exeMergeStat
+    | indexStatement  # exeIndexStat
+    | quitStatement  # exeQuitStat
+    | listStatement  # exeListStat
+    ;
+
+
+
+dateFormat
+    : datetime=DATETIME #getDateTime
+    | func=Identifier LPAREN RPAREN #getIdentifier
+    ;
+
+dateFormatWithNumber
+    : dateFormat #getDateTimeFromDateFormat
+    | integer   #getDateTimeFromInteger
+    ;
+
+
+/*
+****
+*************
+metadata
+*************
+****
+*/
+
+
+metadataStatement
+    : createTimeseries
+    | setStorageGroup
+    | deleteStorageGroup // TODO to implement
+    | addAPropertyTree
+    | addALabelProperty
+    | deleteALabelFromPropertyTree
+    | linkMetadataToPropertyTree
+    | unlinkMetadataNodeFromPropertyTree
+    | deleteTimeseries
+    | showMetadata
+    | describePath
+    ;
+
+describePath
+    : KW_DESCRIBE prefixPath
+    ;
+
+showMetadata
+  : KW_SHOW KW_METADATA
+  ;
+
+createTimeseries
+  : KW_CREATE KW_TIMESERIES timeseries KW_WITH propertyClauses
+  ;
+
+timeseries
+  : KW_ROOT (DOT identifier)+
+  ;
+
+propertyClauses
+  : KW_DATATYPE EQUAL propertyName=identifier COMMA KW_ENCODING EQUAL 
pv=propertyValue (COMMA KW_COMPRESSOR EQUAL compressor=propertyValue)? (COMMA 
propertyClause)*
+  ;
+
+propertyClause
+  : propertyName=identifier EQUAL pv=propertyValue
+  ;
+
+propertyValue
+  : numberOrString
+  ;
+
+setStorageGroup
+  : KW_SET KW_STORAGE KW_GROUP KW_TO prefixPath
+  ;
+
+deleteStorageGroup
+  : KW_DELETE KW_STORAGE KW_GROUP prefixPath
+  ;
+
+addAPropertyTree
+  : KW_CREATE KW_PROPERTY property=identifier
+  ;
+
+addALabelProperty
+  : KW_ADD KW_LABEL label=identifier KW_TO KW_PROPERTY property=identifier
+  ;
+
+deleteALabelFromPropertyTree
+  : KW_DELETE KW_LABEL label=identifier KW_FROM KW_PROPERTY property=identifier
+  ;
+
+linkMetadataToPropertyTree
+  : KW_LINK prefixPath KW_TO propertyPath
+  ;
+
+
+propertyPath
+  : property=identifier DOT label=identifier
+  ;
+
+unlinkMetadataNodeFromPropertyTree
+  :KW_UNLINK prefixPath KW_FROM propertyPath
+  ;
+
+deleteTimeseries
+  : KW_DELETE KW_TIMESERIES prefixPath (COMMA prefixPath)*
+  ;
+
+
+/*
+****
+*************
+crud & author
+*************
+****
+*/
+mergeStatement
+    :
+    KW_MERGE
+    ;
+
+quitStatement
+    :
+    KW_QUIT
+    ;
+
+queryStatement
+   :
+   selectClause
+   whereClause?
+   specialClause?
+   ;
+
+specialClause
+    :
+    limitClause slimitClause?
+    |slimitClause limitClause?
+    |groupbyClause limitClause slimitClause?
+    |groupbyClause slimitClause limitClause?
+    |groupbyClause
+    |fillClause slimitClause?
+    ;
+
+
+authorStatement
+    : createUser
+    | dropUser
+    | createRole
+    | dropRole
+    | grantUser
+    | grantRole
+    | revokeUser
+    | revokeRole
+    | grantRoleToUser
+    | revokeRoleFromUser
+    ;
+
+loadStatement
+    : KW_LOAD KW_TIMESERIES (fileName=StringLiteral) identifier (DOT 
identifier)*
+    ;
+
+createUser
+    : KW_CREATE KW_USER
+        userName=Identifier
+        password=numberOrString
+    ;
+
+dropUser
+    : KW_DROP KW_USER userName=Identifier
+    ;
+
+createRole
+    : KW_CREATE KW_ROLE roleName=Identifier
+    ;
+
+dropRole
+    : KW_DROP KW_ROLE roleName=Identifier
+    ;
+
+grantUser
+    : KW_GRANT KW_USER userName = Identifier privileges KW_ON prefixPath
+    ;
+
+grantRole
+    : KW_GRANT KW_ROLE roleName=Identifier privileges KW_ON prefixPath
+    ;
+
+revokeUser
+    : KW_REVOKE KW_USER userName = Identifier privileges KW_ON prefixPath
+    ;
+
+revokeRole
+    : KW_REVOKE KW_ROLE roleName = Identifier privileges KW_ON prefixPath
+    ;
+
+grantRoleToUser
+    : KW_GRANT roleName = Identifier KW_TO userName = Identifier
+    ;
+
+revokeRoleFromUser
+    : KW_REVOKE roleName = Identifier KW_FROM userName = Identifier
+    ;
+
+privileges
+    : KW_PRIVILEGES StringLiteral (COMMA StringLiteral)*
+    ;
+
+listStatement
+    : KW_LIST KW_USER # listUser
+    | KW_LIST KW_ROLE # listRole
+    | KW_LIST KW_PRIVILEGES KW_USER username = Identifier KW_ON prefixPath # 
listPrivilegesUser
+    | KW_LIST KW_PRIVILEGES KW_ROLE roleName = Identifier KW_ON prefixPath # 
listPrivilegesRole
+    | KW_LIST KW_USER KW_PRIVILEGES username = Identifier # listUserPrivileges
+    | KW_LIST KW_ROLE KW_PRIVILEGES roleName = Identifier # listRolePrivileges
+    | KW_LIST KW_ALL KW_ROLE KW_OF KW_USER username = Identifier # listAllRoles
+    | KW_LIST KW_ALL KW_USER KW_OF KW_ROLE roleName = Identifier # listAllUsers
+    ;
+
+prefixPath
+    : KW_ROOT (DOT nodeName)*
+    ;
+
+suffixPath
+    : nodeName (DOT nodeName)*
+    ;
+
+nodeName
+    : identifier
+    | STAR
+    ;
+
+insertStatement
+   : KW_INSERT KW_INTO prefixPath multidentifier KW_VALUES multiValue
+   ;
+
+/*
+Assit to multi insert, target grammar:  insert into 
root.<deviceType>.<deviceName>(time, s1 ,s2) values(timeV, s1V, s2V)
+*/
+
+multidentifier
+       :
+       LPAREN KW_TIMESTAMP (COMMA identifier)* RPAREN
+       ;
+multiValue
+       :
+       LPAREN time=dateFormatWithNumber (COMMA numberOrStringWidely)* RPAREN
+       ;
+
+
+deleteStatement
+   :
+   KW_DELETE KW_FROM prefixPath (COMMA prefixPath)* (whereClause)?
+   ;
+
+updateStatement
+   : KW_UPDATE prefixPath (COMMA prefixPath)* KW_SET setClause (whereClause)? 
# updateRecord
+   | KW_UPDATE KW_USER userName=Identifier KW_SET KW_PASSWORD 
psw=numberOrString # updateAccount
+   ;
+
+setClause
+    : setExpression (COMMA setExpression)*
+    ;
+
+setExpression
+    : suffixPath EQUAL numberOrStringWidely
+    ;
+
+
+/*
+****
+*************
+Index Statment
 
 Review comment:
   ```suggestion
   Index Statement
   ```

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to