org.eclipse.datatools.sqltools.sql.parser
Class SQLParser

java.lang.Object
  extended by org.eclipse.datatools.sqltools.sql.parser.SQLParser
All Implemented Interfaces:
SQLParserConstants
Direct Known Subclasses:
DerbySQLParser, GenericSQLParser

public abstract class SQLParser
extends java.lang.Object
implements SQLParserConstants

Abstract SQL parser. Vendor developers should extend this parser to support their own dialect in content assist and syntax validation features. TODO: move scope to ParsingResult, which should keep track of scopes like Partitions

Author:
Hui Cao
See Also:
ParserParameters, ParsingResult

Field Summary
static java.lang.String SPECIAL_TOKEN
          All concrete parsers should include this special invalid token to enable the content assist feature
 
Fields inherited from interface org.eclipse.datatools.sqltools.sql.parser.SQLParserConstants
COLUMNS, DATABASES, DDL_STATEMENTS, DML_STATEMENTS, EVENT_PARAMETERS, GLOBAL_VARIABLES, PARAMETERS, SCOPE_CATALOGS, SCOPE_COLUMNS, SCOPE_DATA_TYPES, SCOPE_DEFAULT, SCOPE_DEFINE_VARIABLES, SCOPE_EVENTS, SCOPE_FUNCTIONS, SCOPE_INDEXES, SCOPE_REFERENCE_VARIABLES, SCOPE_SCHEMAS, SCOPE_SEGMENT, SCOPE_STORED_PROCEDURES, SCOPE_TABLES, SCOPE_TRIGGERS, SCOPE_VIEWS, SCOPE_WITHOUT_TABLE, TABLES, TYPE_SQL_ALTER_DATABASE, TYPE_SQL_ALTER_EVENT, TYPE_SQL_ALTER_FUNCTION, TYPE_SQL_ALTER_INDEX, TYPE_SQL_ALTER_PROCEDURE, TYPE_SQL_ALTER_TABLE, TYPE_SQL_ALTER_TRIGGER, TYPE_SQL_ALTER_VIEW, TYPE_SQL_BEGIN, TYPE_SQL_BEGIN_TRANSACTION, TYPE_SQL_CALL, TYPE_SQL_CREATE_DATABASE, TYPE_SQL_CREATE_DEFAULT, TYPE_SQL_CREATE_EVENT, TYPE_SQL_CREATE_FUNCTION, TYPE_SQL_CREATE_INDEX, TYPE_SQL_CREATE_PROCEDURE, TYPE_SQL_CREATE_TABLE, TYPE_SQL_CREATE_TRIGGER, TYPE_SQL_CREATE_VIEW, TYPE_SQL_DECLARE, TYPE_SQL_DELETE, TYPE_SQL_DROP_VIEW, TYPE_SQL_EVENT_CONDITION, TYPE_SQL_INSERT, TYPE_SQL_OTHERS, TYPE_SQL_ROOT, TYPE_SQL_ROUTINE_HEADER, TYPE_SQL_SELECT, TYPE_SQL_SELECT_INTO, TYPE_SQL_UPDATE, VARIABLE_ASSIGNMENTS, VARIABLE_DECLARATIONS, VARIABLE_REFERENCES
 
Constructor Summary
SQLParser()
           
 
Method Summary
 int getEndIndex(Token t)
          Gets the end index of a Token for a String input
 int[] getRange(Token t)
          Gets the start and end index of a Token for a String input
 int getStartIndex(Token t)
          Gets the start index of a Token for a String input
abstract  java.lang.String[] getStatementStartTokens()
          Returns the token strings that can be used to begin a SQL statement.
abstract  java.lang.String[] getStatementTerminators()
          Returns the statement terminator array.
 boolean isComplete()
          Returns whether the parser has captured the complete grammar for the database.
 ParsingResult parse(java.lang.String text)
          Parses the given sql text using the default parameter.
 ParsingResult parse(java.lang.String text, ParserParameters parameters)
          Parses a sql text and try to construct the AST by ignoring all the parsing exceptions and moving to the start token of the next possible statement;
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SPECIAL_TOKEN

public static final java.lang.String SPECIAL_TOKEN
All concrete parsers should include this special invalid token to enable the content assist feature

See Also:
Constant Field Values
Constructor Detail

SQLParser

public SQLParser()
Method Detail

parse

public ParsingResult parse(java.lang.String text)
Parses the given sql text using the default parameter. Records the abstract syntax tree nodes and accumulates ParseException in the ParsingResult.

Parameters:
text - sql text to be parsed
Returns:
ParsingResult containing root AST node and ParseExceptions.

parse

public ParsingResult parse(java.lang.String text,
                           ParserParameters parameters)
Parses a sql text and try to construct the AST by ignoring all the parsing exceptions and moving to the start token of the next possible statement;

Parameters:
text - sql text to be parsed
parameters - parameter used by parser
Returns:
ParsingResult containing root AST node and ParseExceptions.

getStatementTerminators

public abstract java.lang.String[] getStatementTerminators()
Returns the statement terminator array. Different vendors will have their own terminators defined, so we just leave this method as abstract here.

Returns:
statement terminator array

getStatementStartTokens

public abstract java.lang.String[] getStatementStartTokens()
Returns the token strings that can be used to begin a SQL statement.

Returns:
statement start token array

isComplete

public boolean isComplete()
Returns whether the parser has captured the complete grammar for the database. This will determine whether to enable syntax validation.

Returns:
default value is true

getStartIndex

public int getStartIndex(Token t)
Gets the start index of a Token for a String input


getEndIndex

public int getEndIndex(Token t)
Gets the end index of a Token for a String input


getRange

public int[] getRange(Token t)
Gets the start and end index of a Token for a String input