[#8188] Add support for labels in procedural blocks

This commit is contained in:
lukaseder 2019-01-10 12:21:22 +01:00
parent 2eb09a7247
commit fd1179677d
10 changed files with 443 additions and 6 deletions

View File

@ -46,7 +46,8 @@ dmlStatement =
proceduralStatements = ( proceduralStatement ';' )+
;
proceduralStatement =
proceduralStatement = [ label ]
(
query
| declareStatement
| assignmentStatement
@ -56,6 +57,10 @@ proceduralStatement =
| continueStatement
| exitStatement
| nullStatement
)
;
label = '<<' identifier '>>'
;
blockStatement =
@ -93,11 +98,11 @@ whileStatement =
;
continueStatement =
'CONTINUE' [ 'WHEN' condition ]
'CONTINUE' [ identifier ] [ 'WHEN' condition ]
;
exitStatement =
'EXIT' [ 'WHEN' condition ]
'EXIT' [ identifier ] [ 'WHEN' condition ]
;
nullStatement = 'NULL'

View File

@ -0,0 +1,56 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Other licenses:
* -----------------------------------------------------------------------------
* Commercial licenses for this work are available. These replace the above
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
* database integrations.
*
* For more information, please visit: http://www.jooq.org/licenses
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package org.jooq;

View File

@ -0,0 +1,56 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Other licenses:
* -----------------------------------------------------------------------------
* Commercial licenses for this work are available. These replace the above
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
* database integrations.
*
* For more information, please visit: http://www.jooq.org/licenses
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package org.jooq;

View File

@ -0,0 +1,55 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Other licenses:
* -----------------------------------------------------------------------------
* Commercial licenses for this work are available. These replace the above
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
* database integrations.
*
* For more information, please visit: http://www.jooq.org/licenses
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package org.jooq;

View File

@ -58,6 +58,19 @@ package org.jooq.impl;

View File

@ -166,6 +166,7 @@ import org.jooq.ConstraintForeignKeyReferencesStep8;
import org.jooq.ConstraintForeignKeyReferencesStep9;
import org.jooq.ConstraintForeignKeyReferencesStepN;
import org.jooq.ConstraintTypeStep;
// ...
import org.jooq.CreateIndexStep;
import org.jooq.CreateSchemaFinalStep;
import org.jooq.CreateSequenceFlagsStep;
@ -185,6 +186,7 @@ import org.jooq.DropSequenceFinalStep;
import org.jooq.DropTableStep;
import org.jooq.DropTypeStep;
import org.jooq.DropViewFinalStep;
// ...
import org.jooq.False;
import org.jooq.Field;
import org.jooq.FieldOrRow;
@ -222,6 +224,7 @@ import org.jooq.InsertValuesStepN;
import org.jooq.Keyword;
// ...
// ...
// ...
import org.jooq.Merge;
import org.jooq.MergeKeyStep1;
import org.jooq.MergeKeyStep10;
@ -9858,6 +9861,44 @@ public class DSL {

View File

@ -58,6 +58,19 @@ package org.jooq.impl;

View File

@ -0,0 +1,75 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Other licenses:
* -----------------------------------------------------------------------------
* Commercial licenses for this work are available. These replace the above
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
* database integrations.
*
* For more information, please visit: http://www.jooq.org/licenses
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package org.jooq.impl;

View File

@ -0,0 +1,70 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Other licenses:
* -----------------------------------------------------------------------------
* Commercial licenses for this work are available. These replace the above
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
* database integrations.
*
* For more information, please visit: http://www.jooq.org/licenses
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package org.jooq.impl;

View File

@ -381,6 +381,7 @@ import org.jooq.InsertSetStep;
import org.jooq.InsertValuesStepN;
import org.jooq.JoinType;
import org.jooq.Keyword;
// ...
import org.jooq.Merge;
import org.jooq.MergeFinalStep;
import org.jooq.MergeMatchedStep;
@ -2213,10 +2214,22 @@ final class ParserImpl implements Parser {
List<Statement> statements = new ArrayList<Statement>();
for (;;) {
Statement statement = parseStatement(ctx);
statements.add(statement);
Statement parsed;
Statement stored;
if (!(statement instanceof Block))
stored = parsed = parseStatement(ctx);
statements.add(stored);
if (!(parsed instanceof Block))
parse(ctx, ';');
if (peekKeyword(ctx, peek))
@ -2238,6 +2251,25 @@ final class ParserImpl implements Parser {
private static final Block parseDo(ParserContext ctx) {
@ -2446,6 +2478,18 @@ final class ParserImpl implements Parser {
@ -8934,6 +8978,15 @@ final class ParserImpl implements Parser {
return ctx.substring(start, stop);
}
private static final boolean parse(ParserContext ctx, String string) {
boolean result = parseIf(ctx, string);
if (!result)
throw ctx.expected(string);
return result;
}
private static final boolean parseIf(ParserContext ctx, String string) {
return parseIf(ctx, string, true);
}