-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[plsql] Add support for SQL_MACRO #5087
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I'll do the small fixups myself and merge afterwards.
|
||
@Test | ||
void testEmpty() { | ||
ASTInput input = plsql.parseResource("SqlMacroClause.pls"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably easier to just add this pls file as a PlsqlTreeDumpTest
|
||
import java.util.Locale; | ||
|
||
public final class ASTSqlMacroClause extends AbstractPLSQLNode { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public final class ASTSqlMacroClause extends AbstractPLSQLNode { | |
/** | |
* @since 7.4.0 | |
*/ | |
public final class ASTSqlMacroClause extends AbstractPLSQLNode { |
@@ -5133,6 +5137,7 @@ TOKEN [IGNORE_CASE]: | |||
<ROWTYPE: "ROWTYPE"> | | |||
<SAVE: "SAVE"> | | |||
<SAVEPOINT: "SAVEPOINT"> | | |||
<SCALAR: "SCALAR"> | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SCALAR and SQL_MACRO are neither reserved words or keywords. I'll try to avoid defining extra tokens for something, that is not reserved/keywords. IIRC javacc has some limit of the number of token definitions, which we hit in the past. Unfortunately, everything was defined as token in the past in this grammar, which created lots of problems - especially as these tokens can be used as identifiers in other contexts.
I'll therefore remove these from here and use directly "SCALAR"
where it is used and also make sure to add these two tokens to KEYWORD_NOT_RESERVED, so that they still can be used as identifiers.
ASTSqlMacroClause SqlMacroClause(): {} | ||
{ | ||
( | ||
<SQL_MACRO> [ <LPAREN> [ <TYPE> "=>" ] ( <SCALAR> | <TABLE> ) { jjtThis.setType(token.getImage()); } <RPAREN> ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<SQL_MACRO> [ <LPAREN> [ <TYPE> "=>" ] ( <SCALAR> | <TABLE> ) { jjtThis.setType(token.getImage()); } <RPAREN> ] | |
"SQL_MACRO" [ <LPAREN> [ <TYPE> "=>" ] ( "SCALAR" | <TABLE> ) { jjtThis.setType(token.getImage()); } <RPAREN> ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remembered, it should be
<SQL_MACRO> [ <LPAREN> [ <TYPE> "=>" ] ( <SCALAR> | <TABLE> ) { jjtThis.setType(token.getImage()); } <RPAREN> ] | |
LOOKAHEAD({isKeyword("SQL_MACRO")}) KEYWORD("SQL_MACRO") [ <LPAREN> [ <TYPE> "=>" ] ( LOOKAHEAD({isKeyword("SCALAR")}) KEYWORD("SCALAR") | <TABLE> ) { jjtThis.setType(token.getImage()); } <RPAREN> ] |
That way, we don't need to define a token at all and parse "SQL_MACRO" as an identifier.
Generated by 🚫 Danger |
|
||
end test3; | ||
|
||
function test3() return clob sql_macro(TABLE) is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function test3() return clob sql_macro(TABLE) is | |
function test4() return clob sql_macro(TABLE) is |
Merge pull request #5087 from duursma:SQL_MACRO
Describe the PR
The "Support for SQL_MACRO" push request adds support for the "sql_macro(TYPE => ...) construct declaration and usage in the "FROM" construction.
Related issues
None
Syntax errors on code using the sql_macro constructs.
Ready?
./mvnw clean verify
passes (checked automatically by github actions)