Ring-k commented on a change in pull request #366: upgrade from antlr3 to antlr4 URL: https://github.com/apache/incubator-iotdb/pull/366#discussion_r320559664
########## File path: server/src/main/antlr4/org/apache/iotdb/db/sql/parse/TSParser.g4 ########## @@ -0,0 +1,761 @@ +// +// 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; +} + +@header { +//package org.apache.iotdb.db.sql.parse; + +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import org.apache.iotdb.db.qp.logical.crud.SelectOperator; + +} + + +@members{ + + public static int type; + + public int getType(){ + return this.type; + } + + public void setType(int type){ + this.type = type; + } + +//ArrayList<ParseError> errors = new ArrayList<ParseError>(); +// Stack msgs = new Stack<String>(); +// +// private static HashMap<String, String> xlateMap; +// static { +// //this is used to support auto completion in CLI +// xlateMap = new HashMap<String, String>(); +// +// // Keywords +// // xlateMap.put("KW_TRUE", "TRUE"); +// // xlateMap.put("KW_FALSE", "FALSE"); +// +// xlateMap.put("KW_AND", "AND"); +// xlateMap.put("KW_OR", "OR"); +// xlateMap.put("KW_NOT", "NOT"); +// xlateMap.put("KW_LIKE", "LIKE"); +// +// xlateMap.put("KW_BY", "BY"); +// xlateMap.put("KW_GROUP", "GROUP"); +// xlateMap.put("KW_FILL", "FILL"); +// xlateMap.put("KW_LINEAR", "LINEAR"); +// xlateMap.put("KW_PREVIOUS", "PREVIOUS"); +// xlateMap.put("KW_WHERE", "WHERE"); +// xlateMap.put("KW_FROM", "FROM"); +// +// xlateMap.put("KW_SELECT", "SELECT"); +// xlateMap.put("KW_INSERT", "INSERT"); +// +// xlateMap.put("KW_LIMIT","LIMIT"); +// xlateMap.put("KW_OFFSET","OFFSET"); +// xlateMap.put("KW_SLIMIT","SLIMIT"); +// xlateMap.put("KW_SOFFSET","SOFFSET"); +// +// xlateMap.put("KW_ON", "ON"); +// xlateMap.put("KW_ROOT", "ROOT"); +// +// xlateMap.put("KW_SHOW", "SHOW"); +// +// xlateMap.put("KW_CLUSTER", "CLUSTER"); +// +// xlateMap.put("KW_LOAD", "LOAD"); +// +// xlateMap.put("KW_NULL", "NULL"); +// xlateMap.put("KW_CREATE", "CREATE"); +// +// xlateMap.put("KW_DESCRIBE", "DESCRIBE"); +// +// xlateMap.put("KW_TO", "TO"); +// xlateMap.put("KW_ON", "ON"); +// xlateMap.put("KW_USING", "USING"); +// +// xlateMap.put("KW_DATETIME", "DATETIME"); +// xlateMap.put("KW_TIMESTAMP", "TIMESTAMP"); +// xlateMap.put("KW_TIME", "TIME"); +// xlateMap.put("KW_CLUSTERED", "CLUSTERED"); +// +// xlateMap.put("KW_INTO", "INTO"); +// +// xlateMap.put("KW_ROW", "ROW"); +// xlateMap.put("KW_STORED", "STORED"); +// xlateMap.put("KW_OF", "OF"); +// xlateMap.put("KW_ADD", "ADD"); +// xlateMap.put("KW_FUNCTION", "FUNCTION"); +// xlateMap.put("KW_WITH", "WITH"); +// xlateMap.put("KW_SET", "SET"); +// xlateMap.put("KW_UPDATE", "UPDATE"); +// xlateMap.put("KW_VALUES", "VALUES"); +// xlateMap.put("KW_KEY", "KEY"); +// xlateMap.put("KW_ENABLE", "ENABLE"); +// xlateMap.put("KW_DISABLE", "DISABLE"); +// xlateMap.put("KW_ALL", "ALL"); +// +// // Operators +// xlateMap.put("DOT", "."); +// xlateMap.put("COLON", ":"); +// xlateMap.put("COMMA", ","); +// xlateMap.put("SEMICOLON", ");"); +// +// xlateMap.put("LPAREN", "("); +// xlateMap.put("RPAREN", ")"); +// xlateMap.put("LSQUARE", "["); +// xlateMap.put("RSQUARE", "]"); +// +// xlateMap.put("EQUAL", "="); +// xlateMap.put("NOTEQUAL", "<>"); +// xlateMap.put("EQUAL_NS", "<=>"); +// xlateMap.put("LESSTHANOREQUALTO", "<="); +// xlateMap.put("LESSTHAN", "<"); +// xlateMap.put("GREATERTHANOREQUALTO", ">="); +// xlateMap.put("GREATERTHAN", ">"); +// +// xlateMap.put("CharSetLiteral", "\\'"); +// xlateMap.put("KW_LIST", "LIST"); +// } +// +// public static Collection<String> getKeywords() { +// return xlateMap.values(); +// } +// +// private static String xlate(String name) { +// +// String ret = xlateMap.get(name); +// if (ret == null) { +// ret = name; +// } +// +// return ret; +// } +// +// @Override +// public Object recoverFromMismatchedSet(IntStream input, +// RecognitionException re, BitSet follow) throws RecognitionException { +// throw re; +// } +// +// @Override +// public void displayRecognitionError(String[] tokenNames, +// RecognitionException e) { +// errors.add(new ParseError(this, e, tokenNames)); +// } +// +// @Override +// public String getErrorHeader(RecognitionException e) { +// String header = null; +// if (e.charPositionInLine < 0 && input.LT(-1) != null) { +// Token t = input.LT(-1); +// header = "line " + t.getLine() + ":" + t.getCharPositionInLine(); +// } else { +// header = super.getErrorHeader(e); +// } +// +// return header; +// } +// +// @Override +// public String getErrorMessage(RecognitionException e, String[] tokenNames) { +// String msg = null; +// +// // Translate the token names to something that the user can understand +// String[] xlateNames = new String[tokenNames.length]; +// for (int i = 0; i < tokenNames.length; ++i) { +// xlateNames[i] = TSParser.xlate(tokenNames[i]); +// } +// +// if (e instanceof NoViableAltException) { +// @SuppressWarnings("unused") +// NoViableAltException nvae = (NoViableAltException) e; +// // for development, can add +// // "decision=<<"+nvae.grammarDecisionDescription+">>" +// // and "(decision="+nvae.decisionNumber+") and +// // "state "+nvae.stateNumber +// msg = "cannot recognize input near " +// + input.LT(1) != null ? " " + getTokenErrorDisplay(input.LT(1)) : "" +// + input.LT(1) != null ? " " + getTokenErrorDisplay(input.LT(1)) : "" +// + input.LT(3) != null ? " " + getTokenErrorDisplay(input.LT(3)) : ""; +// +// } else if (e instanceof MismatchedTokenException) { +// MismatchedTokenException mte = (MismatchedTokenException) e; +// msg = super.getErrorMessage(e, xlateNames) + (input.LT(-1) == null ? "":" near '" + input.LT(-1).getText()) + "'" +// + ". Please refer to SQL document and check if there is any keyword conflict."; +// } else if (e instanceof FailedPredicateException) { +// FailedPredicateException fpe = (FailedPredicateException) e; +// msg = "Failed to recognize predicate '" + fpe.token.getText() + "'. Failed rule: '" + fpe.ruleName + "'"; +// } else { +// if(xlateMap.containsKey("KW_"+e.token.getText().toUpperCase())){ +// msg = e.token.getText() + " is a key word. Please refer to SQL document and check whether it can be used here or not."; +// } else { +// msg = super.getErrorMessage(e, xlateNames); +// } +// } +// +// if (msgs.size() > 0) { +// msg = msg + " in " + msgs.peek(); +// } +// return msg; +// } +// +// // counter to generate unique union aliases Review comment: Thanks for your suggestion. I removed the useless comments. ---------------------------------------------------------------- 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: [email protected] With regards, Apache Git Services
