From fd1179677d6eef1e2dbc6de485cd6be84a07ae37 Mon Sep 17 00:00:00 2001 From: lukaseder Date: Thu, 10 Jan 2019 12:21:22 +0100 Subject: [PATCH] [#8188] Add support for labels in procedural blocks --- .../resources/org/jooq/web/grammar-3.12.txt | 11 ++- jOOQ/src/main/java/org/jooq/ContinueWhen.java | 56 ++++++++++++++ jOOQ/src/main/java/org/jooq/ExitWhen.java | 56 ++++++++++++++ jOOQ/src/main/java/org/jooq/Label.java | 55 ++++++++++++++ .../src/main/java/org/jooq/impl/Continue.java | 13 ++++ jOOQ/src/main/java/org/jooq/impl/DSL.java | 41 ++++++++++ jOOQ/src/main/java/org/jooq/impl/Exit.java | 13 ++++ .../main/java/org/jooq/impl/LabelImpl.java | 75 +++++++++++++++++++ .../java/org/jooq/impl/LabelledStatement.java | 70 +++++++++++++++++ .../main/java/org/jooq/impl/ParserImpl.java | 59 ++++++++++++++- 10 files changed, 443 insertions(+), 6 deletions(-) create mode 100644 jOOQ/src/main/java/org/jooq/ContinueWhen.java create mode 100644 jOOQ/src/main/java/org/jooq/ExitWhen.java create mode 100644 jOOQ/src/main/java/org/jooq/Label.java create mode 100644 jOOQ/src/main/java/org/jooq/impl/LabelImpl.java create mode 100644 jOOQ/src/main/java/org/jooq/impl/LabelledStatement.java diff --git a/jOOQ-manual/src/main/resources/org/jooq/web/grammar-3.12.txt b/jOOQ-manual/src/main/resources/org/jooq/web/grammar-3.12.txt index 9dd01cb863..165f83d831 100644 --- a/jOOQ-manual/src/main/resources/org/jooq/web/grammar-3.12.txt +++ b/jOOQ-manual/src/main/resources/org/jooq/web/grammar-3.12.txt @@ -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' diff --git a/jOOQ/src/main/java/org/jooq/ContinueWhen.java b/jOOQ/src/main/java/org/jooq/ContinueWhen.java new file mode 100644 index 0000000000..8ddcf87421 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/ContinueWhen.java @@ -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; + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jOOQ/src/main/java/org/jooq/ExitWhen.java b/jOOQ/src/main/java/org/jooq/ExitWhen.java new file mode 100644 index 0000000000..8ddcf87421 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/ExitWhen.java @@ -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; + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jOOQ/src/main/java/org/jooq/Label.java b/jOOQ/src/main/java/org/jooq/Label.java new file mode 100644 index 0000000000..8a40ece199 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/Label.java @@ -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; + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jOOQ/src/main/java/org/jooq/impl/Continue.java b/jOOQ/src/main/java/org/jooq/impl/Continue.java index e5e905ca7a..bbcf39be63 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Continue.java +++ b/jOOQ/src/main/java/org/jooq/impl/Continue.java @@ -58,6 +58,19 @@ package org.jooq.impl; + + + + + + + + + + + + + diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index 33602141b7..061334e96d 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -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 { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jOOQ/src/main/java/org/jooq/impl/Exit.java b/jOOQ/src/main/java/org/jooq/impl/Exit.java index e5e905ca7a..bbcf39be63 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Exit.java +++ b/jOOQ/src/main/java/org/jooq/impl/Exit.java @@ -58,6 +58,19 @@ package org.jooq.impl; + + + + + + + + + + + + + diff --git a/jOOQ/src/main/java/org/jooq/impl/LabelImpl.java b/jOOQ/src/main/java/org/jooq/impl/LabelImpl.java new file mode 100644 index 0000000000..b1673470ac --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/LabelImpl.java @@ -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; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jOOQ/src/main/java/org/jooq/impl/LabelledStatement.java b/jOOQ/src/main/java/org/jooq/impl/LabelledStatement.java new file mode 100644 index 0000000000..624f5cc18b --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/LabelledStatement.java @@ -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; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java b/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java index 3c9fa67a04..54819fd761 100644 --- a/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java @@ -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 statements = new ArrayList(); 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); }