Author: pkluegl
Date: Mon Jan 14 15:21:15 2019
New Revision: 1851267

URL: http://svn.apache.org/viewvc?rev=1851267&view=rev
Log:
UIMA-5955: support multiple inlined rules in IDE

Modified:
    
uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/formatter/RutaFormattedPrinter.java
    
uima/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaParser.g
    
uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/ComposedRuleElement.java
    
uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/RutaRuleElement.java

Modified: 
uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/formatter/RutaFormattedPrinter.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/formatter/RutaFormattedPrinter.java?rev=1851267&r1=1851266&r2=1851267&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/formatter/RutaFormattedPrinter.java
 (original)
+++ 
uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/formatter/RutaFormattedPrinter.java
 Mon Jan 14 15:21:15 2019
@@ -83,7 +83,7 @@ public class RutaFormattedPrinter extend
   private static final String CONCAT = " + ";
 
   private static final String CONCAT_RULES = "% ";
-  
+
   private static final String COMMA = ",";
 
   private static final int NL_DECLS_COUNT = 2;
@@ -132,7 +132,8 @@ public class RutaFormattedPrinter extend
   private boolean retainLB = true;
 
   public RutaFormattedPrinter(FormatterDocument document, String lineDelimiter,
-          IFormatterIndentGenerator indentGenerator, List<CommonToken> 
comments, RutaFormatter tmf) {
+          IFormatterIndentGenerator indentGenerator, List<CommonToken> 
comments,
+          RutaFormatter tmf) {
     this.document = document;
     this.lineDelimiter = lineDelimiter;
     this.indentGenerator = indentGenerator;
@@ -209,7 +210,8 @@ public class RutaFormattedPrinter extend
         if (expressions.size() > 1) {
           for (int i = 1; i < expressions.size(); i++) {
             Expression expression = expressions.get(i);
-            if (expression.getKind() == RutaTypeConstants.RUTA_TYPE_N && i < 
expressions.size() - 1) {
+            if (expression.getKind() == RutaTypeConstants.RUTA_TYPE_N
+                    && i < expressions.size() - 1) {
               append(expression);
               append(EQUALS);
               append(expressions.get(++i));
@@ -353,7 +355,7 @@ public class RutaFormattedPrinter extend
       if (inLargeRule == 2) {
         inLargeRule = 4;
       }
-      if(cre.isAfterConcat()) {
+      if (cre.isAfterConcat()) {
         append(CONCAT_RULES);
       }
       append(PAR_OPEN);
@@ -381,7 +383,7 @@ public class RutaFormattedPrinter extend
       } else if (inLargeRule == 1) {
         inLargeRule = 2;
       }
-      if(ruleEl.isAfterConcat()) {
+      if (ruleEl.isAfterConcat()) {
         append(CONCAT_RULES);
       }
       appendRuleElement(ruleEl);
@@ -611,7 +613,7 @@ public class RutaFormattedPrinter extend
    * @param ruleEl
    * @param conditions
    * @param actions
-   * @throws Exception 
+   * @throws Exception
    */
   private void appendRuleElement(RutaRuleElement ruleEl) throws Exception {
     // if (ruleEl instanceof ComposedRuleElement) {
@@ -634,7 +636,7 @@ public class RutaFormattedPrinter extend
     if (ruleEl.getHead() != null) {
       append(ruleEl.getHead());
     }
-    if(ruleEl.isWildcard()) {
+    if (ruleEl.isWildcard()) {
       append("#");
     }
     List<RutaCondition> conditions = ruleEl.getConditions();
@@ -679,9 +681,8 @@ public class RutaFormattedPrinter extend
       return;
     }
 
-    if (!inBlockDeclaration
-            && ((conditions == null && actions.isEmpty()) || actions == null
-                    && (conditions != null) && conditions.isEmpty())) {
+    if (!inBlockDeclaration && ((conditions == null && actions.isEmpty())
+            || actions == null && (conditions != null) && 
conditions.isEmpty())) {
       return;
     }
     append(CURLY_OPEN);
@@ -701,14 +702,16 @@ public class RutaFormattedPrinter extend
       traverseAstNodes(actions);
     }
     append(CURLY_CLOSE);
-    if(ruleEl.getInlinedRules()!= null && !ruleEl.getInlinedRules().isEmpty()) 
{
+    if (ruleEl.getInlinedRuleBlocks() != null && 
!ruleEl.getInlinedRuleBlocks().isEmpty()) {
       String inlineMode = ruleEl.getInlineMode();
       append(inlineMode);
       append(CURLY_OPEN);
       indentLevel++;
-      List<RutaRule> inlinedRules = ruleEl.getInlinedRules();
-      for (RutaRule rutaRule : inlinedRules) {
-        visit(rutaRule);
+      List<List<RutaRule>> inlinedRuleBlocks = ruleEl.getInlinedRuleBlocks();
+      for (List<RutaRule> inlinedRules : inlinedRuleBlocks) {
+        for (RutaRule rutaRule : inlinedRules) {
+          visit(rutaRule);
+        }
       }
       indentLevel--;
       appendIntoNewLine(CURLY_CLOSE);

Modified: 
uima/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaParser.g
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaParser.g?rev=1851267&r1=1851266&r2=1851267&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaParser.g
 (original)
+++ 
uima/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaParser.g
 Mon Jan 14 15:21:15 2019
@@ -819,10 +819,20 @@ String label = null;
        | re4 = ruleElementSpecial {re = re4;}
        )
        {re.setLabel(label);}
-       (t = THEN2 LCURLY (rule = simpleStatement {innerRules.add(rule);})+ 
-       RCURLY {re.setInlinedRules(innerRules);re.setInlineMode(t == null ? 
null : t.getText());})?
-       (t = THEN LCURLY (rule = simpleStatement {innerRules.add(rule);})+ 
-       RCURLY {re.setInlinedRules(innerRules);re.setInlineMode(t == null ? 
null : t.getText());})?
+       
+       (
+       t = THEN2 LCURLY 
+       {innerRules = new ArrayList<RutaRule>();}
+       (rule = simpleStatement {innerRules.add(rule);})+ 
+       RCURLY {re.addInlinedRules(innerRules);}
+       )*
+       
+       (
+       t = THEN LCURLY 
+       {innerRules = new ArrayList<RutaRule>();}
+       (rule = simpleStatement {innerRules.add(rule);})+ 
+       RCURLY {re.addInlinedRules(innerRules);}
+       )*
        ;
 
 ruleElementSpecial returns [RutaRuleElement re = null] 

Modified: 
uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/ComposedRuleElement.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/ComposedRuleElement.java?rev=1851267&r1=1851266&r2=1851267&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/ComposedRuleElement.java
 (original)
+++ 
uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/ComposedRuleElement.java
 Mon Jan 14 15:21:15 2019
@@ -68,9 +68,11 @@ public class ComposedRuleElement extends
           action.traverse(visitor);
         }
       }
-      if(inlinedRules != null) {
-        for (RutaRule rule : inlinedRules) {
-          rule.traverse(visitor);
+      if (getInlinedRuleBlocks() != null) {
+        for (List<RutaRule> inlinedRules : getInlinedRuleBlocks()) {
+          for (RutaRule rule : inlinedRules) {
+            rule.traverse(visitor);
+          }
         }
       }
       visitor.endvisit(this);

Modified: 
uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/RutaRuleElement.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/RutaRuleElement.java?rev=1851267&r1=1851266&r2=1851267&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/RutaRuleElement.java
 (original)
+++ 
uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/RutaRuleElement.java
 Mon Jan 14 15:21:15 2019
@@ -35,8 +35,8 @@ public class RutaRuleElement extends Exp
   protected Expression head;
 
   protected List<Expression> quantifierExpressions;
-  
-  protected List<RutaRule> inlinedRules;
+
+  private List<List<RutaRule>> inlinedRuleBlocks = new ArrayList<>();
 
   private String inlineMode;
 
@@ -45,7 +45,7 @@ public class RutaRuleElement extends Exp
   private boolean wildcard;
 
   private String label;
-  
+
   // TODO to be removed
   public RutaRuleElement(int start, int end) {
     super(start, end);
@@ -99,9 +99,11 @@ public class RutaRuleElement extends Exp
           action.traverse(visitor);
         }
       }
-      if(inlinedRules != null) {
-        for (RutaRule rule : inlinedRules) {
-          rule.traverse(visitor);
+      if (inlinedRuleBlocks != null) {
+        for (List<RutaRule> inlinedRules : inlinedRuleBlocks) {
+          for (RutaRule rule : inlinedRules) {
+            rule.traverse(visitor);
+          }
         }
       }
       visitor.endvisit(this);
@@ -124,22 +126,19 @@ public class RutaRuleElement extends Exp
     return quantifierExpressions;
   }
 
+  @Override
   public String toString() {
     return this.getClass().getSimpleName() + " : " + super.toString();
   }
 
-  public List<RutaRule> getInlinedRules() {
-    return inlinedRules;
-  }
-
-  public void setInlinedRules(List<RutaRule> inlinedRules) {
-    if(inlinedRules != null && !inlinedRules.isEmpty()) {
-      RutaRule last = inlinedRules.get(inlinedRules.size()-1);
-      if(last != null) {
+  public void addInlinedRules(List<RutaRule> inlinedRules) {
+    if (inlinedRules != null && !inlinedRules.isEmpty()) {
+      RutaRule last = inlinedRules.get(inlinedRules.size() - 1);
+      if (last != null) {
         setEnd(last.sourceEnd());
       }
     }
-    this.inlinedRules = inlinedRules;
+    inlinedRuleBlocks.add(inlinedRules);
   }
 
   public void setInlineMode(String mode) {
@@ -171,11 +170,19 @@ public class RutaRuleElement extends Exp
   }
 
   public void setLabel(String label) {
-        this.label = label;
+    this.label = label;
   }
-  
+
   public String getLabel() {
     return this.label;
   }
-  
+
+  public List<List<RutaRule>> getInlinedRuleBlocks() {
+    return inlinedRuleBlocks;
+  }
+
+  public void setInlinedRuleBlocks(List<List<RutaRule>> inlinedRuleBlocks) {
+    this.inlinedRuleBlocks = inlinedRuleBlocks;
+  }
+
 }


Reply via email to