Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Reformat BLOCK production
Disable STATEMENTS() test, which will never fail and add comments to this regard
  • Loading branch information
manticore-projects committed Apr 24, 2022
commit 28f2dcfe9ff7d8bb51434fdbad1ffcbe9618c8d6
34 changes: 29 additions & 5 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -657,10 +657,27 @@ Block Block() #Block : {
}
{
<K_BEGIN>
(<ST_SEMICOLON>)*
(<ST_SEMICOLON>)*
try {
(stm = SingleStatement() | stm = Block()) { list.add(stm); } <ST_SEMICOLON>
( (stm = SingleStatement() | stm = Block()) <ST_SEMICOLON> { list.add(stm); } )*
(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

To be honest I find your version much harder to read.

(
stm = SingleStatement()
| stm = Block()
)
<ST_SEMICOLON>
{ list.add(stm); }
)

(
(
(
stm = SingleStatement()
| stm = Block()
)
<ST_SEMICOLON>
{ list.add(stm); }
)
)*
} catch (ParseException e) {
if (errorRecovery) {
parseErrors.add(e);
Expand All @@ -669,11 +686,13 @@ Block Block() #Block : {
throw e;
}
}

{
stmts.setStatements(list);
block.setStatements(stmts);
}
<K_END>

<K_END> [LOOKAHEAD(2) <ST_SEMICOLON>]
{
return block;
}
Expand Down Expand Up @@ -737,6 +756,11 @@ Statements Statements() #Statements : {

[ LOOKAHEAD(2) <ST_SEMICOLON> ]
) { list.add(stm); }
|
// For any reason, we can't LOOKAHEAD( { getAsBoolean(Feature.allowUnsupportedStatements) } ) here
// As it will result in a Stack Overflow
stm = UnsupportedStatement()
{ if ( !((UnsupportedStatement) stm).isEmpty() ) list.add(stm); }
]
)*
<EOF>
Expand Down Expand Up @@ -6323,7 +6347,7 @@ List<String> captureUnsupportedStatementDeclaration() {

while(true) {
tok = getToken(1);
if(tok.kind == EOF || tok.kind== ST_SEMICOLON) {
if( tok.kind == EOF || tok.kind== ST_SEMICOLON || tok.kind== K_END ) {
break;
}
tokens.add(tok.image);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

public class CCJSqlParserUtilTest {
Expand Down Expand Up @@ -160,7 +162,10 @@ public void accept(Statement statement) {
}

@Test
@Disabled
public void testParseStatementsFail() throws Exception {
// This will not fail, but always return the Unsupported Statements
// Since we can't LOOKAHEAD in the Statements() production
assertThrows(JSQLParserException.class, () -> CCJSqlParserUtil.parseStatements("select * from dual;WHATEVER!!"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.statement.select.Select;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;

Expand Down Expand Up @@ -44,7 +43,6 @@ public void execute() throws Throwable {
}

@Test
@Disabled
public void testUnsupportedStatementsMiddleInBlock() throws JSQLParserException {
String sqlStr = "Select * from dual; This is an unsupported statement; Select * from dual;";

Expand All @@ -54,5 +52,15 @@ public void testUnsupportedStatementsMiddleInBlock() throws JSQLParserException
Assertions.assertInstanceOf(Select.class, statements.getStatements().get(0));
Assertions.assertInstanceOf(UnsupportedStatement.class, statements.getStatements().get(1));
Assertions.assertInstanceOf(Select.class, statements.getStatements().get(2));

// This will not fail, but always return the Unsupported Statements
// Since we can't LOOKAHEAD in the Statements() production

// Assertions.assertThrowsExactly(JSQLParserException.class, new Executable() {
// @Override
// public void execute() throws Throwable {
// CCJSqlParserUtil.parseStatements(sqlStr, parser -> parser.withUnsupportedStatements(false) );
// }
// });
}
}