Skip to content
This repository was archived by the owner on Feb 18, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
f41c0c9
use memoize for performance improvement - testcase for Gokul
ibre5041 Apr 8, 2012
19733f0
memoize option removed - requires global menoize option to be enabled
ibre5041 May 18, 2012
71745c7
new test condition of type: current of c_ref
ibre5041 May 18, 2012
e0afe5e
more tests, one of them fails
ibre5041 May 18, 2012
2181900
strange query example
ibre5041 Jun 25, 2012
ae1b161
datawarehousing group by
ibre5041 Jun 27, 2012
e98ac47
update bunch of records in a row
ibre5041 Aug 29, 2012
1180524
new tests, returning into bulk collect
ibre5041 Sep 27, 2012
324e97a
testcase fixed
ibre5041 Nov 19, 2012
489212a
CAST and MULTISET are now treated as reserved words, multiset operati…
ibre5041 Nov 19, 2012
3dd7275
Full support for set operators within SQL expressions
ibre5041 Nov 20, 2012
ed0ea4c
fix COLLECT function 11gR2 feature, thx to oracle-developer.net
ibre5041 Nov 20, 2012
5afebec
CLUSTER_SET function - see datawarehousing guide
ibre5041 Nov 20, 2012
436ef5b
syntax error in Oracle docs
ibre5041 Nov 20, 2012
889aa67
PREDICTION function
ibre5041 Nov 20, 2012
086d89d
more tests added
ibre5041 Nov 21, 2012
83c059e
CONNECT_BY_ROOT unary operator
ibre5041 Jan 10, 2013
259f26e
new unit test files
ibre5041 Mar 8, 2013
c7f809e
collect operator
ibre5041 Mar 8, 2013
ef80328
Fix for some number formats
ibre5041 Mar 14, 2013
226f35e
Fix typo in test case
ibre5041 Jun 21, 2013
55a4996
Ported to ANTLR 3.5
ibre5041 Jun 23, 2013
93a12a1
Lexer for notation fix
ibre5041 Jun 24, 2013
84e210d
loop end with label
ibre5041 Jul 1, 2013
6fb726e
undocumented "opverlaps" operator - not implemented yet
ibre5041 Jul 29, 2013
81358ac
Some tests added
ibre5041 Aug 20, 2013
9371601
Model test added
ibre5041 Aug 20, 2013
a9fb689
model test
ibre5041 Aug 27, 2013
36f132d
various insert statements
ibre5041 Sep 27, 2013
c48c9f4
connect by ... order by siblings ...
ibre5041 Nov 12, 2013
374900d
pivot_in_clause - segfault fix
ibre5041 Jul 29, 2014
7204ee2
Merge branch 'master' of github.com:ibre5041/plsql-parser
ibre5041 Jul 29, 2014
9e22b72
fix unpivot_in_elements - as is mandatory
ibre5041 Jul 30, 2014
ce77729
avoid warning "Semantic predicates were present but were hidden by ac…
ibre5041 Aug 1, 2014
6825cba
align AST version with non-AST version
ibre5041 Aug 2, 2014
50d96a7
Fix for analytic functions - sync with not-AST version
ibre5041 Aug 3, 2014
5e1a793
Fix for the test insert02.sql
ibre5041 Aug 6, 2014
0b1fb25
Fix for modeling clause
ibre5041 Aug 6, 2014
cfe4337
Fixes for group by clause
ibre5041 Aug 14, 2014
88476f6
11g triger body
ibre5041 Sep 27, 2014
77061e3
Merge branch 'master' of github.com:ibre5041/plsql-parser
ibre5041 Sep 27, 2014
604ed48
block must start either with DECLARE or BEGIN
ibre5041 Dec 23, 2014
6a08b05
compilation fix for AST grammar
ibre5041 Dec 24, 2014
31c1eef
12c features
ibre5041 Jun 25, 2018
bc49fd4
some more tests
ibre5041 Jun 25, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lexer-parser/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@
<configuration>
<executable>java</executable>
<arguments>
<argument>-Xmx1g</argument>
<argument>-Xmx768m</argument>
<argument>-classpath</argument>
<classpath/>
<argument>org.antlr.Tool</argument>
<argument>-o</argument>
<argument>${project.build.directory}/generated-sources/antlr3/br/com/porcelli/parser/plsql/
</argument>
<argument>-Xmultithreaded</argument>
<!-- <argument>-Xmultithreaded</argument> -->
<argument>-lib</argument>
<argument>${project.basedir}/src/main/antlr3/br/com/porcelli/parser/plsql/imports/</argument>
<argument>${project.basedir}/src/main/antlr3/br/com/porcelli/parser/plsql/PLSQLLexer.g
Expand All @@ -73,7 +73,6 @@
<plugin>
<groupId>org.antlr</groupId>
<artifactId>maven-gunit-plugin</artifactId>
<version>3.2</version>
<executions>
<execution>
<id>maven-gunit-plugin</id>
Expand Down
6 changes: 6 additions & 0 deletions parsers/PLSQLCommons.g
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,12 @@ concatenation_op
| VERTICAL_BAR VERTICAL_BAR
;

multiset_op
: multiset_key
( except_key | intersect_key | union_key )
( all_key | distinct_key )?
;

outer_join_sign
: LEFT_PAREN PLUS_SIGN RIGHT_PAREN
;
Expand Down
6 changes: 4 additions & 2 deletions parsers/PLSQLKeys.g
Original file line number Diff line number Diff line change
Expand Up @@ -1514,7 +1514,8 @@ over_key
;

multiset_key
: {input.LT(1).getText().equalsIgnoreCase("multiset")}?=> REGULAR_ID
// : {input.LT(1).getText().equalsIgnoreCase("multiset")}?=> REGULAR_ID
: PLSQL_NON_RESERVED_MULTISET
;

connect_by_root_key
Expand Down Expand Up @@ -2082,7 +2083,8 @@ match_key
;

cast_key
: {input.LT(1).getText().equalsIgnoreCase("cast")}? REGULAR_ID -> CAST_VK[$REGULAR_ID]
// : {input.LT(1).getText().equalsIgnoreCase("cast")}? REGULAR_ID -> CAST_VK[$REGULAR_ID]
: PLSQL_NON_RESERVED_CAST
;

full_key: {input.LT(1).getText().equalsIgnoreCase("full")}?=> REGULAR_ID -> FULL_VK[$REGULAR_ID]
Expand Down
38 changes: 28 additions & 10 deletions parsers/PLSQLLexer.g
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ import java.util.LinkedList;
state.tokenStartLine = input.getLine();
state.text = null;
if (input.LA(1) == CharStream.EOF) {
return Token.EOF_TOKEN;
return getEOFToken();
}
try {
int m = input.mark();
Expand Down Expand Up @@ -116,8 +116,12 @@ FOR_NOTATION
{state.type = UNSIGNED_INTEGER; emit(); advanceInput();}
'..'
{state.type = DOUBLE_PERIOD; emit(); advanceInput();}
UNSIGNED_INTEGER
{state.type = UNSIGNED_INTEGER; emit(); advanceInput(); $channel=HIDDEN;}
( UNSIGNED_INTEGER
{state.type = UNSIGNED_INTEGER; emit(); advanceInput(); }
| REGULAR_ID
{state.type = REGULAR_ID; emit(); advanceInput(); }
)?
{ $channel=HIDDEN; }
;

//{ Rule #358 <NATIONAL_CHAR_STRING_LIT> - subtoken typecast in <REGULAR_ID>, it also incorporates <character_representation>
Expand Down Expand Up @@ -159,7 +163,7 @@ PERIOD
EXACT_NUM_LIT
: (
UNSIGNED_INTEGER
( '.' UNSIGNED_INTEGER
( '.' UNSIGNED_INTEGER?
| {$type = UNSIGNED_INTEGER;}
) ( ('E' | 'e') ('+' | '-')? UNSIGNED_INTEGER {$type = APPROXIMATE_NUM_LIT;} )?
| '.' UNSIGNED_INTEGER ( ('E' | 'e') ('+' | '-')? UNSIGNED_INTEGER {$type = APPROXIMATE_NUM_LIT;} )?
Expand Down Expand Up @@ -228,6 +232,7 @@ RIGHT_PAREN
: ')'
;

// Not allowed in SQL, but in PL/SQL(ADA) yes
DOUBLE_ASTERISK
: '**'
;
Expand Down Expand Up @@ -541,15 +546,15 @@ SQL92_RESERVED_EXCEPTION
advanceInput();

$type = Token.INVALID_TOKEN_TYPE;
int markModel = input.mark();
int markException = input.mark();

// Now loop over next Tokens in the input and eventually set Token's type to REGULAR_ID

// Subclassed version will return NULL unless EOF is reached.
// nextToken either returns NULL => then the next token is put into the queue tokenBuffer
// or it returns Token.EOF, then nothing is put into the queue
Token t1 = super.nextToken();
{ // This "if" handles the situation when the "model" is the last text in the input.
{ // This "if" handles the situation when the "exception" is the last text in the input.
if( t1 != null && t1.getType() == Token.EOF)
{
$e.setType(REGULAR_ID);
Expand Down Expand Up @@ -579,7 +584,7 @@ SQL92_RESERVED_EXCEPTION
} // while true
} // else if( t1 != null && t1.getType() == Token.EOF)
}
input.rewind(markModel);
input.rewind(markException);
}
;

Expand Down Expand Up @@ -815,14 +820,22 @@ SQL92_RESERVED_WITH
: 'with'
;

PLSQL_NON_RESERVED_CAST
: 'cast'
;

PLSQL_NON_RESERVED_MULTISET
: 'multiset'
;

PLSQL_NON_RESERVED_USING
: 'using'
;

PLSQL_NON_RESERVED_MODEL
: m='model'
{
// "model" is a keyword if and only if it is followed by ("main"|"partition"|"dimension")
// "model" is a keyword if and only if it is followed by ("main"|"partition"|"dimension"|"unique"|"return")
// otherwise it is a identifier(REGULAR_ID).
// This wodoo implements something like context sensitive lexer.
// Here we've matched the word "model". Then the Token is created and en-queued in tokenBuffer
Expand Down Expand Up @@ -859,10 +872,15 @@ PLSQL_NON_RESERVED_MODEL
t1 = super.nextToken(); if( t1 == null) { t1 = tokenBuffer.pollLast(); };
continue;
}

if( t1.getType() != REGULAR_ID || // is something other than ("main"|"partition"|"dimension")

if( t1.getType() == SQL92_RESERVED_UNIQUE)
{
break;
}
if( t1.getType() != REGULAR_ID || // is something other than ("main"|"partition"|"dimension"|"return")
( !t1.getText().equalsIgnoreCase("main") &&
!t1.getText().equalsIgnoreCase("partition") &&
!t1.getText().equalsIgnoreCase("return") &&
!t1.getText().equalsIgnoreCase("dimension")
))
{
Expand Down
2 changes: 1 addition & 1 deletion parsers/PLSQLParser.g
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ exception_handler
// $>

block
: (declare_key? declare_spec+)?
: (declare_key declare_spec+)?
body
-> ^(BLOCK declare_spec* body)
;
Expand Down
86 changes: 49 additions & 37 deletions parsers/PLSQL_DMLParser.g
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ tokens {
PIVOT_IN_ELEMENT;
UNPIVOT_IN_ELEMENT;
HIERARCHICAL;
GROUP_BY_CLAUSE;
GROUP_BY_ELEMENT;
GROUPIN_SET;
MAIN_MODEL;
Expand Down Expand Up @@ -186,14 +187,16 @@ compilation_unit

//SHOULD BE OVERRIDEN!
seq_of_statements
: select_statement
:
( select_statement
| update_statement
| delete_statement
| insert_statement
| lock_table_statement
| merge_statement
| explain_statement
// | case_statement[true]
)
( SEMICOLON | EOF )
;

explain_statement
Expand Down Expand Up @@ -265,10 +268,10 @@ query_block
hierarchical_query_clause?
group_by_clause?
model_clause?
-> {mode == 1}? ^(select_key from_clause distinct_key? unique_key? all_key? ASTERISK
into_clause? where_clause? hierarchical_query_clause? group_by_clause? model_clause?)
-> ^(select_key from_clause distinct_key? unique_key? all_key? ^(SELECT_LIST selected_element+)
into_clause? where_clause? hierarchical_query_clause? group_by_clause? model_clause?)
-> {mode == 1}? ^(select_key distinct_key? unique_key? all_key? ASTERISK
into_clause? from_clause where_clause? hierarchical_query_clause? group_by_clause? model_clause?)
-> ^(select_key distinct_key? unique_key? all_key? ^(SELECT_LIST selected_element+)
into_clause? from_clause where_clause? hierarchical_query_clause? group_by_clause? model_clause?)
;

selected_element
Expand Down Expand Up @@ -381,7 +384,7 @@ pivot_in_clause
: in_key
LEFT_PAREN
( (select_key)=> subquery {mode = 1;}
| (any_key)=> any_key (COMMA any_key)* {mode = 1;}
| (any_key)=> any_key (COMMA any_key)* {mode = 2;}
| pivot_in_clause_element (COMMA pivot_in_clause_element)*
)
RIGHT_PAREN
Expand Down Expand Up @@ -425,7 +428,7 @@ unpivot_in_elements
: ( column_name
| LEFT_PAREN column_name (COMMA column_name)* RIGHT_PAREN
)
( as_key?
( as_key
( constant
| (LEFT_PAREN)=> LEFT_PAREN constant (COMMA constant)* RIGHT_PAREN
)
Expand All @@ -446,10 +449,19 @@ start_part
;

group_by_clause
: (group_key) => group_key by_key group_by_elements ((COMMA group_by_elements)=> COMMA group_by_elements)* having_clause?
-> ^(group_key ^(GROUP_BY_ELEMENT group_by_elements)+ having_clause?)
| (having_key) => having_clause (group_key by_key group_by_elements ((COMMA group_by_elements)=> COMMA group_by_elements)*)?
-> ^(group_key having_clause ^(GROUP_BY_ELEMENT group_by_elements)+)
: (group_key) => group_key by_key
(LEFT_PAREN RIGHT_PAREN
| group_by_elements ((COMMA group_by_elements)=> COMMA group_by_elements)*
)
having_clause?
-> ^(GROUP_BY_CLAUSE[$group_key.start] ^(group_key ^(GROUP_BY_ELEMENT group_by_elements)*) having_clause?)
| (having_key) => having_clause
(group_key by_key
(LEFT_PAREN RIGHT_PAREN
| group_by_elements ((COMMA group_by_elements)=> COMMA group_by_elements)*
)
)?
-> ^(GROUP_BY_CLAUSE[$having_clause.start] having_clause ^(group_key ^(GROUP_BY_ELEMENT group_by_elements)*)?)
;

group_by_elements
Expand Down Expand Up @@ -520,13 +532,13 @@ model_column_list
;

model_column
: expression table_alias?
-> ^(MODEL_COLUMN table_alias? ^(EXPR expression))
: expression column_alias?
-> ^(MODEL_COLUMN column_alias? ^(EXPR expression))
;

model_rules_clause
: model_rules_part? LEFT_PAREN model_rules_element (COMMA model_rules_element)* RIGHT_PAREN
-> ^(MODEL_RULES model_rules_element+ model_rules_part?)
: model_rules_part? LEFT_PAREN (model_rules_element (COMMA model_rules_element)*)? RIGHT_PAREN
-> ^(MODEL_RULES model_rules_element* model_rules_part?)
;

model_rules_part
Expand Down Expand Up @@ -591,10 +603,10 @@ update_statement

// $<Update - Specific Clauses
update_set_clause
@init { int mode = 0; }
@init { int mode = 1; }
: set_key
( column_based_update_set_clause (COMMA column_based_update_set_clause)* {mode = 1;}
| value_key LEFT_PAREN id RIGHT_PAREN EQUALS_OP expression
( column_based_update_set_clause (COMMA column_based_update_set_clause)*
| value_key LEFT_PAREN id RIGHT_PAREN EQUALS_OP expression {mode = 0;}
)
->{mode == 1}? ^(set_key column_based_update_set_clause+)
-> ^(set_key ^(value_key id ^(EXPR expression)))
Expand Down Expand Up @@ -667,7 +679,7 @@ insert_into_clause
;

values_clause
: values_key^ expression_list
: values_key^ (expression_list | record_name)
;

// $>
Expand Down Expand Up @@ -851,7 +863,7 @@ negated_expression

equality_expression
@init { boolean isNegated = false; }
: (multiset_expression -> multiset_expression)
: (multiset_comparsion -> multiset_comparsion)
( is_key (not_key {isNegated = true;})?
( null_key
-> {isNegated}? ^(IS_NOT_NULL $equality_expression)
Expand All @@ -875,14 +887,14 @@ equality_expression
-> {isNegated}? ^(IS_NOT_OF_TYPE $equality_expression type_spec+)
-> ^(IS_OF_TYPE $equality_expression type_spec+)
)
)*
)?
;


multiset_expression
multiset_comparsion
: (relational_expression -> relational_expression)
( multiset_type of_key? concatenation
-> ^(multiset_type $multiset_expression ^(EXPR concatenation)))?
-> ^(multiset_type $multiset_comparsion ^(EXPR concatenation)))?
;

multiset_type
Expand Down Expand Up @@ -977,7 +989,7 @@ interval_expression
;

model_expression
: (unary_expression -> unary_expression)
: (multiset_expression -> multiset_expression)
(LEFT_BRACKET model_expression_element RIGHT_BRACKET
-> ^(MODEL_EXPRESSION[$LEFT_BRACKET] $model_expression model_expression_element))?
;
Expand Down Expand Up @@ -1019,6 +1031,11 @@ multi_column_for_loop
-> ^(FOR_MULTI_COLUMN[$for_key.start] column_name+ ^(in_key subquery? expression_list*))
;

multiset_expression
: unary_expression
( multiset_op^ unary_expression )*
;

unary_expression
options
{
Expand Down Expand Up @@ -1113,18 +1130,18 @@ quantified_expression
;

standard_function
: stantard_function_enabling_over^ function_argument over_clause?
| stantard_function_enabling_using^ function_argument using_clause?
: stantard_function_enabling_over^ function_argument_analytic over_clause?
| stantard_function_enabling_using^ function_argument_modeling using_clause?
| count_key^
LEFT_PAREN!
( ASTERISK | (distinct_key|unique_key|all_key)? concatenation_wrapper )
RIGHT_PAREN! over_clause?
| (cast_key^|xmlcast_key^)
LEFT_PAREN!
( (multiset_key LEFT_PAREN (select_key|with_key)) => (multiset_key! LEFT_PAREN! subquery RIGHT_PAREN!)
| concatenation_wrapper
)
as_key! type_spec
( (multiset_key LEFT_PAREN+ (select_key|with_key)) => (multiset_key! LEFT_PAREN! subquery order_by_clause? RIGHT_PAREN!)
(as_key! type_spec)?
| concatenation_wrapper as_key! type_spec
)
RIGHT_PAREN!
| chr_key^
LEFT_PAREN!
Expand All @@ -1144,12 +1161,7 @@ standard_function
LEFT_PAREN!
REGULAR_ID from_key! concatenation_wrapper
RIGHT_PAREN!
| (first_value_key^|last_value_key^)
LEFT_PAREN!
concatenation_wrapper (ignore_key! nulls_key)?
RIGHT_PAREN! over_clause
| (first_value_key^|last_value_key^)
function_argument_analytic
| (first_value_key^|last_value_key^) function_argument_analytic
respect_or_ignore_nulls? over_clause
| stantard_function_pedictions^
LEFT_PAREN!
Expand Down
Loading