From 8bf94e16fe51ef95efeac775dbfb0925f9607832 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Wed, 22 May 2013 20:15:03 +0200 Subject: [PATCH] [#1737] Substitute also multi-sequences --- .../src/org/jooq/api/rr/BNFGenerator.java | 39 ++++++++++++++----- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/jOOQ-tools/src/org/jooq/api/rr/BNFGenerator.java b/jOOQ-tools/src/org/jooq/api/rr/BNFGenerator.java index 2c0526f6f3..c90e25382a 100644 --- a/jOOQ-tools/src/org/jooq/api/rr/BNFGenerator.java +++ b/jOOQ-tools/src/org/jooq/api/rr/BNFGenerator.java @@ -113,17 +113,17 @@ public class BNFGenerator { while (true) { // Some debugging.... - String check = "UpdateSetMoreStep"; + String check = "WindowPartitionByStep"; Set e = edgesTo.get(check); if (e != null) { - System.out.println(); - System.out.println(); - System.out.println(); - System.out.println(string(e, false)); - System.out.println(string(edgesFrom.get(check), false)); - System.out.println(); - System.out.println(); - System.out.println(); + System.err.println(); + System.err.println(); + System.err.println(); + System.err.println(string(e, false)); + System.err.println(string(edgesFrom.get(check), false)); + System.err.println(); + System.err.println(); + System.err.println(); } // Alternatives with equal paths are substituted @@ -211,6 +211,7 @@ public class BNFGenerator { // Sequences are substituted (only if B consumed exactly once) // A ::= B x; B ::= C y; => A ::= C y x; // ----------------------------------------------------------------- + for (int maxSize : new int[] { 1, Integer.MAX_VALUE }) substitutionLoop: for (String name : new ArrayList(edgesFrom.keySet())) { if (terminals.contains(name)) { @@ -221,7 +222,25 @@ public class BNFGenerator { Edge from = edgesFrom.get(name).iterator().next(); Set set = edgesTo.get(name); - if (set != null && set.size() == 1) { + if (set != null) { + if (set.size() > maxSize) { + continue substitutionLoop; + } + + if (set.size() > 1) { + if (!"".equals(from.expr.toString())) { + continue substitutionLoop; + } + else { + System.out.println(); + System.out.println(); + System.out.println("Substituting multi-sequence"); + System.out.println(string(from)); + System.out.println("..."); + System.out.println(string(set)); + } + } + List list = new ArrayList(set); List substitutes = new ArrayList();