From efbf0236487d2028de021f7d6b554b8c423f2112 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 25 Mar 2021 19:49:03 +0100 Subject: [PATCH] [plsql] Rework SQLCommand keywords vs. identifiers --- pmd-plsql/etc/grammar/PldocAST.jjt | 100 ++++++++++++----------------- 1 file changed, 40 insertions(+), 60 deletions(-) diff --git a/pmd-plsql/etc/grammar/PldocAST.jjt b/pmd-plsql/etc/grammar/PldocAST.jjt index 1db14e25c2..280b2d6752 100644 --- a/pmd-plsql/etc/grammar/PldocAST.jjt +++ b/pmd-plsql/etc/grammar/PldocAST.jjt @@ -331,6 +331,9 @@ ASTDDLCommand DDLCommand() : { jjtThis.setImage(simpleNode.getImage()) ; return jjtThis ; } } +/* + * See https://docs.oracle.com/en/database/oracle/oracle-database/21/sqpug/SQL-Plus-reference.html#GUID-C3D4A718-56AD-4872-ADFF-A216FF70EDF2 + */ ASTSqlPlusCommand SqlPlusCommand() : { StringBuilder sb = new StringBuilder(); @@ -341,49 +344,58 @@ ASTSqlPlusCommand SqlPlusCommand() : // SQLPLUS commands ( "@@" ( <_CHARACTER> | | ) * | "@" ( <_CHARACTER> | | ) * - | | "ACC" - | LOOKAHEAD({isKeyword("ARCHIVE")}) KEYWORD("ARCHIVE") "LOG LIST" + | LOOKAHEAD({isKeyword("ACCEPT")}) KEYWORD("ACCEPT") + | LOOKAHEAD({isKeyword("ACC")}) KEYWORD("ACC") + | LOOKAHEAD({isKeyword("ARCHIVE")}) KEYWORD("ARCHIVE") {sb.append(token.getImage()).append(' ');} "LOG" {sb.append(token.getImage()).append(' ');} KEYWORD("LIST") | - | "BREAK" - | "BTITLE" + | LOOKAHEAD({isKeyword("BREAK")}) KEYWORD("BREAK") + | LOOKAHEAD({isKeyword("BTITLE")}) KEYWORD("BTITLE") | LOOKAHEAD({isKeyword("CLEAR")}) KEYWORD("CLEAR") | | LOOKAHEAD({isKeyword("COL")}) KEYWORD("COL") | LOOKAHEAD({isKeyword("COMPUTE")}) KEYWORD("COMPUTE") | LOOKAHEAD({isKeyword("COMP")}) KEYWORD("COMP") - | | "CONN" - | - | | "DEF" - | "DESCRIBE" | "DESCR" | LOOKAHEAD({isKeyword("DESC")}) KEYWORD("DESC") - | | "DISC" - | | "EXEC" + | + | LOOKAHEAD({isKeyword("CONN")}) KEYWORD("CONN") + | LOOKAHEAD({isKeyword("COPY")}) KEYWORD("COPY") + | LOOKAHEAD({isKeyword("DEFINE")}) KEYWORD("DEFINE") + | LOOKAHEAD({isKeyword("DEF")}) KEYWORD("DEF") + | LOOKAHEAD({isKeyword("DESCRIBE")}) KEYWORD("DESCRIBE") + | LOOKAHEAD({isKeyword("DESCR")}) KEYWORD("DESCR") + | LOOKAHEAD({isKeyword("DESC")}) KEYWORD("DESC") + | LOOKAHEAD({isKeyword("DISCONNECT")}) KEYWORD("DISCONNECT") + | LOOKAHEAD({isKeyword("DISC")}) KEYWORD("DISC") + | + | LOOKAHEAD({isKeyword("EXEC")}) KEYWORD("EXEC") | - | ( <_CHARACTER> | | ) * + | LOOKAHEAD({isKeyword("HOST")}) KEYWORD("HOST") ( <_CHARACTER> | | ) * | "$" ( <_CHARACTER> | | ) * // only works with a blank after the dollar - | "!" ( <_CHARACTER> | | ) * // only works with a blank afer the exlamation mark + | "!" ( <_CHARACTER> | | ) * // only works with a blank after the exclamation mark // These characters are platform-specific, anyway... - | "INPUT" + | LOOKAHEAD({isKeyword("INPUT")}) KEYWORD("INPUT") | LOOKAHEAD({isKeyword("PASSWORD")}) KEYWORD("PASSWORD") | LOOKAHEAD({isKeyword("PASSW")}) KEYWORD("PASSW") - | "PAUSE" - | - | ( <_CHARACTER> | | ) * - | + | LOOKAHEAD({isKeyword("PAUSE")}) KEYWORD("PAUSE") + | LOOKAHEAD({isKeyword("PRINT")}) KEYWORD("PRINT") + | LOOKAHEAD({isKeyword("PROMPT")}) KEYWORD("PROMPT") ( <_CHARACTER> | | ) * + | LOOKAHEAD({isKeyword("QUIT")}) KEYWORD("QUIT") | LOOKAHEAD({isKeyword("RECOVER")}) KEYWORD("RECOVER") - | ( <_CHARACTER> | | ) * - | "REM" ( <_CHARACTER> | | ) * + | LOOKAHEAD({isKeyword("REMARK")}) KEYWORD("REMARK") ( <_CHARACTER> | | ) * + | LOOKAHEAD({isKeyword("REM")}) KEYWORD("REM") ( <_CHARACTER> | | ) * | - | | "SHO" + | LOOKAHEAD({isKeyword("SHOW")}) KEYWORD("SHOW") + | LOOKAHEAD({isKeyword("SHO")}) KEYWORD("SHO") | - | + | LOOKAHEAD({isKeyword("SPOOL")}) KEYWORD("SPOOL") | ( <_CHARACTER> | | ) * | | LOOKAHEAD({isKeyword("STORE")}) KEYWORD("STORE") - | "TIMING" - | "TTITLE" - | - | | "VAR" - | + | LOOKAHEAD({isKeyword("TIMING")}) KEYWORD("TIMING") + | LOOKAHEAD({isKeyword("TTITLE")}) KEYWORD("TTITLE") + | LOOKAHEAD({isKeyword("UNDEFINE")}) KEYWORD("UNDEFINE") + | LOOKAHEAD({isKeyword("VARIABLE")}) KEYWORD("VARIABLE") + | LOOKAHEAD({isKeyword("VAR")}) KEYWORD("VAR") + | LOOKAHEAD({isKeyword("WHENEVER")}) KEYWORD("WHENEVER") // XQUERY is not yet supported, because it is not a single-line command // It should be handled as unknown, skipping to the next stand-alone "/". // DDL that might be encountered @@ -394,7 +406,8 @@ ASTSqlPlusCommand SqlPlusCommand() : // Attach Library | "." ) - { sb.append(token.getImage()) ; sb.append(" ") ; sb.append(Read2NextTokenOccurrence(EOL)) ; + { + sb.append(token.getImage()) ; sb.append(" ") ; sb.append(Read2NextTokenOccurrence(EOL)) ; } ) { jjtThis.setImage(sb.toString()) ; return jjtThis ; } @@ -3446,7 +3459,6 @@ ASTPrimaryPrefix PrimaryPrefix() : | LOOKAHEAD(Literal()) ( simpleNode = Literal() ) { sb.append(simpleNode.getImage()) ; } | LOOKAHEAD(SimpleExpression()) ( simpleNode = SimpleExpression() ) { sb.append(simpleNode.getImage()); } | ( simpleNode =Name() ) { sb.append(simpleNode.getImage()) ; } -// | SelectStatement() | LOOKAHEAD("("