[plsql] Use ReadPastNextOccurrence rather than SkipPastNextToken

The token SQLPLUS_TERMINATOR is useless, since the token ";" is
matched before. So, we always skipped till the end of the file.

Improved the image of the skipped nodes, so that it can be of some
use.

Note: This will fix the problem #2009, but it doesn't parse
DDL Commands fully. It just skips past the next ";".
This commit is contained in:
Andreas Dangel
2019-12-24 11:37:41 +01:00
parent e230027f9a
commit e345e811be
3 changed files with 11 additions and 9 deletions

View File

@@ -268,7 +268,7 @@ ASTInput Input(String sourcecode) : {}
| DeleteStatement()
| InsertStatement()
| SelectStatement() [";"]
|(<COMMIT>|<ROLLBACK>|<SAVEPOINT>|<LOCK><TABLE>|<MERGE>|<WITH>) SkipPastNextTokenOccurrence(SQLPLUS_TERMINATOR) //Ignore SQL statements in scripts
|(<COMMIT>|<ROLLBACK>|<SAVEPOINT>|<LOCK><TABLE>|<MERGE>|<WITH>) ReadPastNextOccurrence(";") //Ignore SQL statements in scripts
)
("/")*
)*
@@ -289,7 +289,7 @@ ASTDDLCommand DDLCommand() :
|
(
simpleNode = DDLEvent()
SkipPastNextTokenOccurrence(SQLPLUS_TERMINATOR)
ReadPastNextOccurrence(";")
)
)
{ jjtThis.setImage(simpleNode.getImage()) ; return jjtThis ; }
@@ -1131,6 +1131,7 @@ ASTRead2NextOccurrence Read2NextOccurrence(String target) :
{
nextToken = getNextToken();
sb.append(nextToken.image);
sb.append(' ');
nextToken = getToken(1);
}
}
@@ -1143,10 +1144,11 @@ ASTRead2NextOccurrence Read2NextOccurrence(String target) :
*/
ASTReadPastNextOccurrence ReadPastNextOccurrence(String target) :
{
ASTRead2NextOccurrence skipped = Read2NextOccurrence(target);
StringBuilder sb = new StringBuilder();
Token t = null;
sb.append(Read2NextOccurrence(target)) ;
t = getNextToken(); // Chomp this one
sb.append(skipped.getImage()) ;
Token t = getNextToken(); // Chomp this one
sb.append(t.image);
}
{
@@ -3921,7 +3923,7 @@ ASTComment Comment() :
{
}
{
LOOKAHEAD({isKeyword("COMMENT")}) KEYWORD("COMMENT")
LOOKAHEAD({isKeyword("COMMENT")}) KEYWORD("COMMENT") { jjtThis.setImage(token.image); }
<ON> (
((<TABLE> | <OPERATOR> | <INDEXTYPE>) [LOOKAHEAD(2) ID()"."] ID()) |
(<COLUMN> [LOOKAHEAD(ID()"."ID()"."ID()) ID()"."] ID() "." ID())
@@ -5157,8 +5159,6 @@ TOKEN :
< JAVA_INTERFACE_CLASS: ( "SQLData" | "CustomDatum" | "OraData" ) >
//|
//< #BOOLEAN_LITERAL: "TRUE" | "FALSE" >
|
<SQLPLUS_TERMINATOR: ( ";" | "/" ) >
}
/**

View File

@@ -21,7 +21,7 @@ public class MultipleDDLStatementsTest extends AbstractPLSQLParserTst {
StandardCharsets.UTF_8);
ASTInput input = parsePLSQL(code);
List<ASTDDLCommand> ddlcommands = input.findDescendantsOfType(ASTDDLCommand.class);
Assert.assertEquals(3, ddlcommands.size());
Assert.assertEquals(4, ddlcommands.size());
List<ASTComment> comments = input.findDescendantsOfType(ASTComment.class);
Assert.assertEquals(3, comments.size());
Assert.assertEquals("'abbreviated job title'", comments.get(0).getFirstChildOfType(ASTStringLiteral.class).getImage());

View File

@@ -2,4 +2,6 @@ COMMENT ON COLUMN employees.job_id IS 'abbreviated job title';
COMMENT ON COLUMN employees.job_id IS 'abbreviated job title';
DROP TABLE employees;
COMMENT ON COLUMN employees.job_id IS 'abbreviated job title';