HHH-14152 sql-script.g fix for antlr non deterministic warning
This commit is contained in:
parent
28787bc013
commit
fe4a94d90c
|
@ -42,6 +42,11 @@ options {
|
|||
protected void statementEnded() {
|
||||
// by default, nothing to do
|
||||
}
|
||||
|
||||
protected void skip() {
|
||||
// by default, nothing to do
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -52,11 +57,11 @@ options {
|
|||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
script
|
||||
: (statement)+ EOF
|
||||
: (newLineToSkip)* (statement)+ EOF
|
||||
;
|
||||
|
||||
statement
|
||||
: { statementStarted(); } (statementPart)* DELIMITER (WS_CHAR)* { statementEnded(); }
|
||||
: { statementStarted(); } (statementPart (afterStatementPartNewline)*)* DELIMITER (newLineToSkip)* { statementEnded(); }
|
||||
;
|
||||
|
||||
statementPart
|
||||
|
@ -70,12 +75,22 @@ quotedString
|
|||
}
|
||||
;
|
||||
|
||||
afterStatementPartNewline
|
||||
: NEWLINE {
|
||||
out(" ");
|
||||
}
|
||||
;
|
||||
|
||||
newLineToSkip
|
||||
: NEWLINE {
|
||||
skip();
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
nonSkippedChar
|
||||
: w:WS_CHAR {
|
||||
out( w );
|
||||
}
|
||||
| o:OTHER_CHAR {
|
||||
out( o );
|
||||
: c:CHAR {
|
||||
out( c );
|
||||
}
|
||||
;
|
||||
|
||||
|
@ -108,13 +123,14 @@ QUOTED_TEXT
|
|||
protected
|
||||
ESCqs : '\'' '\'' ;
|
||||
|
||||
WS_CHAR
|
||||
: ' '
|
||||
| '\t'
|
||||
| ( "\r\n" | '\r' | '\n' ) {newline();}
|
||||
CHAR
|
||||
: ( ' ' | '\t' ) => ( ' ' | '\t' )
|
||||
| ~( ';' | '\n' | '\r' )
|
||||
;
|
||||
|
||||
OTHER_CHAR : ~( ';' | ' ' | '\t' | '\n' | '\r' );
|
||||
NEWLINE
|
||||
: ( '\r' | '\n' | '\r''\n' )
|
||||
;
|
||||
|
||||
LINE_COMMENT
|
||||
// match `//` or `--` followed by anything other than \n or \r until NEWLINE
|
||||
|
|
|
@ -33,9 +33,9 @@ public class MultiLineImportExtractorTest {
|
|||
public void testExtraction() throws IOException {
|
||||
final ClassLoader classLoader = ClassLoader.getSystemClassLoader();
|
||||
|
||||
try ( final InputStream stream = classLoader.getResourceAsStream( IMPORT_FILE ) ) {
|
||||
try (final InputStream stream = classLoader.getResourceAsStream( IMPORT_FILE )) {
|
||||
assertThat( stream, notNullValue() );
|
||||
try ( final InputStreamReader reader = new InputStreamReader( stream ) ) {
|
||||
try (final InputStreamReader reader = new InputStreamReader( stream )) {
|
||||
final String[] commands = extractor.extractCommands( reader );
|
||||
assertThat( commands, notNullValue() );
|
||||
assertThat( commands.length, is( 6 ) );
|
||||
|
@ -46,7 +46,7 @@ public class MultiLineImportExtractorTest {
|
|||
|
||||
assertThat( commands[1], is( "INSERT INTO test_data VALUES (1, 'sample')" ) );
|
||||
|
||||
assertThat( commands[2], is( "DELETE" + System.lineSeparator() + " FROM test_data" ) );
|
||||
assertThat( commands[2], is( "DELETE FROM test_data" ) );
|
||||
|
||||
assertThat( commands[3], startsWith( "INSERT INTO test_data VALUES (2," ) );
|
||||
assertThat( commands[3], containsString( "-- line 2" ) );
|
||||
|
@ -54,7 +54,7 @@ public class MultiLineImportExtractorTest {
|
|||
assertThat( commands[4], startsWith( "INSERT INTO test_data VALUES (3" ) );
|
||||
assertThat( commands[4], not( containsString( "third record" ) ) );
|
||||
|
||||
assertThat( commands[5], startsWith( "INSERT INTO test_data" + System.lineSeparator() + "VALUES" + System.lineSeparator() ) );
|
||||
assertThat( commands[5].replace( "\t", "" ), is( "INSERT INTO test_data VALUES ( 4 , NULL )" ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue