Skip to content

[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

Merged
merged 4 commits into from
Jul 11, 2024
Merged

[plsql] Add support for SQL_MACRO #5087

merged 4 commits into from
Jul 11, 2024

Conversation

duursma
Copy link
Contributor

@duursma duursma commented Jun 27, 2024

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

  • Fixes #
    Syntax errors on code using the sql_macro constructs.

Ready?

  • [X ] Added unit tests for fixed bug/feature
  • [X ] Passing all unit tests
  • [X ] Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • [X ] Added (in-code) documentation (if needed)

@adangel adangel added this to the 7.4.0 milestone Jun 27, 2024
@adangel adangel changed the title [pmd-plsql] Add support for SQL_MACRO [plsql] Add support for SQL_MACRO Jun 27, 2024
@adangel adangel self-requested a review July 5, 2024 09:50
Copy link
Member

@adangel adangel left a 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");
Copy link
Member

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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"> |
Copy link
Member

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> ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<SQL_MACRO> [ <LPAREN> [ <TYPE> "=>" ] ( <SCALAR> | <TABLE> ) { jjtThis.setType(token.getImage()); } <RPAREN> ]
"SQL_MACRO" [ <LPAREN> [ <TYPE> "=>" ] ( "SCALAR" | <TABLE> ) { jjtThis.setType(token.getImage()); } <RPAREN> ]

Copy link
Member

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

Suggested change
<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.

@adangel adangel added the in:grammar About the grammar of a lexer or parser, eg, a parse/lex exception label Jul 11, 2024
@ghost
Copy link

ghost commented Jul 11, 2024

1 Message
📖 Compared to master:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Download full report as build artifact

Generated by 🚫 Danger


end test3;

function test3() return clob sql_macro(TABLE) is
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function test3() return clob sql_macro(TABLE) is
function test4() return clob sql_macro(TABLE) is

adangel added a commit that referenced this pull request Jul 11, 2024
adangel added a commit that referenced this pull request Jul 11, 2024
adangel added a commit that referenced this pull request Jul 11, 2024
Merge pull request #5087 from duursma:SQL_MACRO
@adangel adangel merged commit 3579f3f into pmd:master Jul 11, 2024
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in:grammar About the grammar of a lexer or parser, eg, a parse/lex exception
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants