📄 mysqlparser.jj
字号:
/*@bgen(jjtree) Generated By:JJTree: Do not edit this line. sql\MysqlParser.jj */
/*@egen*/options {
JDK_VERSION = "1.5";
IGNORE_CASE=true ;
DEBUG_PARSER=false ;
STATIC = false;
}
PARSER_BEGIN(MysqlParser)
/*
* Copyright (C) 2008 Struct chen <piratebase@sina.com>
* This program is free software; you can redistribute it and/or modify it under the terms of
* the GNU General Public License as published by the Free Software Foundation; either version 3 of the License,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package com.meidusa.amoeba.mysql.parser.sql;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import com.meidusa.amoeba.parser.dbobject.*;
import com.meidusa.amoeba.parser.expression.*;
import com.meidusa.amoeba.parser.function.*;
import com.meidusa.amoeba.parser.Parser;
import com.meidusa.amoeba.parser.statment.*;
import java.math.BigDecimal;
import java.util.Map;
import java.util.HashMap;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;
import java.util.Calendar;
import java.sql.Connection;
import com.meidusa.amoeba.sqljep.function.Comparative;
public class MysqlParser implements/*@bgen(jjtree)*/ MysqlParserTreeConstants, /*@egen*/ com.meidusa.amoeba.parser.Parser{/*@bgen(jjtree)*/
protected JJTMysqlParserState jjtree = new JJTMysqlParserState();
/*@egen*/
private final static String metachars = "tnrbf\\\"";
private final static String chars = "\t\n\r\b\f\\\"";
private int parameterIndex = 0;
private Map<String,Table> tableAliasMap = new HashMap<String,Table>();
private Stack<Table> tableStack = new Stack<Table>();
private Statment statment;
private Schema defaultSchema;
private Map<String,Function> functionMap;
private static TimeConverter timeConverter = new TimeConverter();
public void setFunctionMap(Map<String,Function> map){
this.functionMap = map;
}
public void setDefaultSchema(Schema schema){
defaultSchema = schema;
}
/**
* main method to test parser
*/
public static void main( String args[] )
throws com.meidusa.amoeba.parser.ParseException
{
MysqlParser p = null ;
if ( args.length < 1 ) {
System.out.println("Reading from stdin") ;
p = new MysqlParser(System.in) ;
}
else {
try {
p = new MysqlParser(new DataInputStream(
new FileInputStream(args[0]))) ;
}
catch (FileNotFoundException e) {
System.out.println("File " + args[0] +
" not found. Reading from stdin") ;
p = new MysqlParser(System.in) ;
}
} // else ends here
if ( args.length > 0 ) {
System.out.println(args[0]) ;
}
Statment statment = p.doParse();
System.out.println(statment.getExpression());
} // main ends here
void jjtreeOpenNodeScope(Node n){
//((SimpleNode)n).setFirstToken(getToken(1));
}
void jjtreeCloseNodeScope(Node n){
// ((SimpleNode)n).setLastToken(token);
}
Function getFunction(String indent){
if(functionMap == null){
return null;
}else{
return functionMap.get(indent);
}
//return funMap.get(indent);
}
public Statment doParse() throws com.meidusa.amoeba.parser.ParseException{
try{
Statment statment = this.parse();
if(statment != null){
statment.setParameterCount(parameterIndex);
}
return statment;
}catch(Exception e){
throw new com.meidusa.amoeba.parser.ParseException(e);
}
}
public Statment getParsedStatment(){
return statment;
}
private Expression reverseExpression(boolean not,Expression expression){
if(not){
if(expression != null){
return expression.reverse();
}else{
return null;
}
}else{
return expression;
}
}
private static String replaceEscape(String inputStr) {
int len = inputStr.length();
int p = 0;
int i;
StringBuilder output = new StringBuilder();
while ((i = inputStr.indexOf('\\', p)) != -1) {
output.append(inputStr.substring(p, i));
if (i+1 == len) break;
// find metacharacter
char metac = inputStr.charAt(i+1);
// find the index of the metac
int k = metachars.indexOf(metac);
if (k == -1) {
// didn't find the metachar, leave sequence as found.
// This code should be unreachable if the parser
// is functioning properly because strings containing
// unknown escape characters should not be accepted.
output.append('\\');
output.append(metac);
} else {
// its corresponding true char
output.append(chars.charAt(k));
}
// skip over both escape character & metacharacter
p = i + 2;
}
// add the end of the input string to the output
if (p < len)
output.append(inputStr.substring(p));
return output.toString();
}
} // class MysqlParser ends here
PARSER_END(MysqlParser)
SKIP:
{
" "
| "\t"
| "\r"
| "\n"
}
/* Prefix Meaning
-------------------
K_ Keyword
O_ Operator
S_ Substitutes
*/
TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
{
<K_DONET: "@">
| <K_ALL: "ALL">
| <K_AND: "AND">
| <K_ANY: "ANY">
| <K_AS: "AS">
| <K_BETWEEN:"BETWEEN">
| <K_BOOLEAN:"BOOLEAN">
| <K_BY:"BY">
| <K_CASE:"CASE">
| <K_CAST:"CAST">
| <K_CHAR:"CHAR">
| <K_CHARACTER:"CHARACTER">
| <K_DECIMAL:"DECIMAL">
| <K_DEC:"DEC">
| <K_DELETE:"DELETE">
| <K_DISTINCT:"DISTINCT">
| <K_DO:"DO">
| <K_DOUBLE:"DOUBLE">
| <K_DROP:"DROP">
| <K_ELSE:"ELSE">
| <K_ELSEIF:"ELSEIF">
| <K_END:"END">
| <K_ESCAPE:"ESCAPE">
| <K_EXISTS:"EXISTS">
| <K_FETCH:"FETCH">
| <K_FLOAT:"FLOAT">
| <K_FOR:"FOR">
| <K_FROM:"FROM">
| <K_FULL:"FULL">
| <K_GROUP:"GROUP">
| <K_HAVING:"HAVING">
| <K_IF:"IF">
| <K_IN:"IN">
| <K_IS:"IS">
| <K_INTO:"INTO">
| <K_INDEX:"INDEX">
| <K_INNER:"INNER">
| <K_INSERT:"INSERT">
| <K_REPLACE:"REPLACE">
| <K_INTEGER:"INTEGER">
| <K_INT:"INT">
| <K_JOIN:"JOIN">
| <K_LEFT:"LEFT">
| <K_LIKE:"LIKE">
| <K_LOCK:"LOCK">
| <K_LOOP:"LOOP">
| <K_CREATE:"CREATE">
| <K_NOT:"NOT">
| <K_NULL:"NULL">
| <K_NULLS:"NULLS">
| <K_NUMBER:"NUMBER">
| <K_NUMERIC:"NUMERIC">
| <K_OF:"OF">
| <K_ON:"ON">
| <K_NOWAIT:"NOWAIT">
| <K_ONLY:"ONLY">
| <K_OR:"OR">
| <K_ORDER:"ORDER">
| <K_OUTER:"OUTER">
| <K_QUERYNO:"QUERYNO">
| <K_OPTIMIZE:"OPTIMIZE">
| <K_READ:"READ">
| <K_REAL:"REAL">
| <K_OPTION:"OPTION">
| <K_SELECT:"SELECT">
| <K_SET:"SET">
| <K_SOME:"SOME">
| <K_TABLE:"TABLE">
| <K_SHOW:"SHOW">
| <K_MOD:"MOD">
| <K_DIV:"DIV">
| <K_THEN:"THEN">
| <K_TO:"TO">
| <K_UNION:"UNION">
| <K_UNIQUE:"UNIQUE">
| <K_UPDATE:"UPDATE">
| <K_USE:"USE">
| <K_USING:"USING">
| <K_VALUES:"VALUES">
| <K_VARCHAR2:"VARCHAR2">
| <K_VARCHAR:"VARCHAR">
| <K_WHEN:"WHEN">
| <K_WHERE:"WHERE">
| <K_WHILE:"WHILE">
| <K_WITH:"WITH">
| <K_TRUE: "TRUE">
| <K_FALSE: "FALSE">
| <K_LIMIT: "LIMIT">
| <K_RIGHT:"RIGHT">
| <K_INTERVAL:"INTERVAL">
| <K_YEAR:"YEAR">
| <K_MICROSECOND:"MICROSECOND">
| <K_SECOND:"SECOND">
| <K_DAY:"DAY">
| <K_MINUTE:"MINUTE">
| <K_MONTH:"MONTH">
| <K_HOUR:"HOUR">
| <K_COMMIT:"COMMIT">
| <K_ROLLBACK:"ROLLBACK">
| <K_TRANSACTION_ISOLATION_LEVEL:"TRANSACTION ISOLATION LEVEL">
//| <K_TRANSACTION:"TRANSACTION">
//| <K_BEGIN:"BEGIN">
| <K_START_TRANSACTION:"START TRANSACTION">
| <K_SESSION:"SESSION">
| <K_TRANSACTION_READ_COMMITTED:"READ COMMITTED">
| <K_TRANSACTION_READ_UNCOMMITTED:"READ UNCOMMITTED">
| <K_TRANSACTION_REPEATABLE_READ:"REPEATABLE READ">
| <K_TRANSACTION_SERIALIZABLE:"SERIALIZABLE">
| <K_CLIENT_CHARSET:"CLIENT CHARSET">
/*
| <K_MICROSECOND:"MICROSECOND">
| <K_MILLISECOND:"MILLISECOND">
| <K_SECOND:"SECOND">
| <K_DAY:"DAY">
| <K_MINUTE:"MINUTE">
| <K_MONTH:"MONTH">
| <K_HOUR:"HOUR">
| <K_TIME:"TIME">
| <K_TIMESTAMP:"TIMESTAMP">
| <K_DATE:"DATE">
| <K_CONCAT:"CONCAT">
| <K_NOW:"NOW">
| <K_CURRENTDATE:"CURRENT_DATE">
| <K_CURRENTTIME:"CURRENT_TIME">
| <K_CURRENTTIMESTAMP:"CURRENT_TIMESTAMP">
| <K_ISOLATION:"ISOLATION">
| <K_LEVEL:"LEVEL">
| <K_CHAIN:"CHAIN">
| <K_RELEASE:"RELEASE">
| <K_SNAPSHOT:"SNAPSHOT">
| <K_WORK:"WORK">
| <K_NO:"NO">
*/
}
TOKEN : /* Numeric Constants */
{
< INTEGER_LITERAL: ( <DIGIT> )+ >
|
< FLOATING_POINT_LITERAL:
(["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)?
| "." (["0"-"9"])+ (<EXPONENT>)?
| (["0"-"9"])+ <EXPONENT>
>
|
< #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
|
<#DIGIT: [
"0" - "9",
"\u0660" - "\u0669",
"\u06f0" - "\u06f9",
"\u0966" - "\u096f",
"\u09e6" - "\u09ef",
"\u0a66" - "\u0a6f",
"\u0ae6" - "\u0aef",
"\u0b66" - "\u0b6f",
"\u0be7" - "\u0bef",
"\u0c66" - "\u0c6f",
"\u0ce6" - "\u0cef",
"\u0d66" - "\u0d6f",
"\u0e50" - "\u0e59",
"\u0ed0" - "\u0ed9",
"\u0f20" - "\u0f29",
"\uff10" - "\uff19"
]>
}
SPECIAL_TOKEN:
{
<LINE_COMMENT: "--"(~["\r","\n"])*>
| <MULTI_LINE_COMMENT: "/*" (~["*"])* "*" ("*" | (~["*","/"] (~["*"])* "*"))* "/">
}
TOKEN:
{
< IDENTIFIER: ((["@"])*( <LETTER> )+ ( <DIGIT> | <LETTER> |<SPECIAL_CHARS>)*) >
| <#LETTER: [
"a"-"z",
"A"-"Z",
"\u00aa",
"\u00b5",
"\u00ba",
"\u00c0" - "\u00d6",
"\u00d8" - "\u00f6",
"\u00f8" - "\u01f5",
"\u01fa" - "\u0217",
"\u0250" - "\u02a8",
"\u02b0" - "\u02b8",
"\u02bb" - "\u02c1",
"\u02d0" - "\u02d1",
"\u02e0" - "\u02e4",
"\u037a",
"\u0386",
"\u0388" - "\u038a",
"\u038c",
"\u038e" - "\u03a1",
"\u03a3" - "\u03ce",
"\u03d0" - "\u03d6",
"\u03da",
"\u03dc",
"\u03de",
"\u03e0",
"\u03e2" - "\u03f3",
"\u0401" - "\u040c",
"\u040e" - "\u044f",
"\u0451" - "\u045c",
"\u045e" - "\u0481",
"\u0490" - "\u04c4",
"\u04c7" - "\u04c8",
"\u04cb" - "\u04cc",
"\u04d0" - "\u04eb",
"\u04ee" - "\u04f5",
"\u04f8" - "\u04f9",
"\u0531" - "\u0556",
"\u0559",
"\u0561" - "\u0587",
"\u05d0" - "\u05ea",
"\u05f0" - "\u05f2",
"\u0621" - "\u063a",
"\u0640" - "\u064a",
"\u0671" - "\u06b7",
"\u06ba" - "\u06be",
"\u06c0" - "\u06ce",
"\u06d0" - "\u06d3",
"\u06d5",
"\u06e5" - "\u06e6",
"\u0905" - "\u0939",
"\u093d",
"\u0958" - "\u0961",
"\u0985" - "\u098c",
"\u098f" - "\u0990",
"\u0993" - "\u09a8",
"\u09aa" - "\u09b0",
"\u09b2",
"\u09b6" - "\u09b9",
"\u09dc" - "\u09dd",
"\u09df" - "\u09e1",
"\u09f0" - "\u09f1",
"\u0a05" - "\u0a0a",
"\u0a0f" - "\u0a10",
"\u0a13" - "\u0a28",
"\u0a2a" - "\u0a30",
"\u0a32" - "\u0a33",
"\u0a35" - "\u0a36",
"\u0a38" - "\u0a39",
"\u0a59" - "\u0a5c",
"\u0a5e",
"\u0a72" - "\u0a74",
"\u0a85" - "\u0a8b",
"\u0a8d",
"\u0a8f" - "\u0a91",
"\u0a93" - "\u0aa8",
"\u0aaa" - "\u0ab0",
"\u0ab2" - "\u0ab3",
"\u0ab5" - "\u0ab9",
"\u0abd",
"\u0ae0",
"\u0b05" - "\u0b0c",
"\u0b0f" - "\u0b10",
"\u0b13" - "\u0b28",
"\u0b2a" - "\u0b30",
"\u0b32" - "\u0b33",
"\u0b36" - "\u0b39",
"\u0b3d",
"\u0b5c" - "\u0b5d",
"\u0b5f" - "\u0b61",
"\u0b85" - "\u0b8a",
"\u0b8e" - "\u0b90",
"\u0b92" - "\u0b95",
"\u0b99" - "\u0b9a",
"\u0b9c",
"\u0b9e" - "\u0b9f",
"\u0ba3" - "\u0ba4",
"\u0ba8" - "\u0baa",
"\u0bae" - "\u0bb5",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -