You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by pk...@apache.org on 2013/06/09 17:04:15 UTC

svn commit: r1491230 - in /uima/sandbox/ruta/trunk: ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/ ruta-core/src/main/java/org/apache/uima/ruta/rule/ ruta-ep-addons/src/main/java/org/apache/uima/ruta/explain/element/ ruta-ep-ide/src/main/antlr3...

Author: pkluegl
Date: Sun Jun  9 15:04:15 2013
New Revision: 1491230

URL: http://svn.apache.org/r1491230
Log:
UIMA-2975
- added option to specify anchoring rule element

Modified:
    uima/sandbox/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaLexer.g
    uima/sandbox/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaParser.g
    uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/AbstractRuleElement.java
    uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElement.java
    uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementCaretaker.java
    uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java
    uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java
    uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/explain/element/ElementTreeLabelProvider.java
    uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaLexer.g
    uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaParser.g

Modified: uima/sandbox/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaLexer.g
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaLexer.g?rev=1491230&r1=1491229&r2=1491230&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaLexer.g (original)
+++ uima/sandbox/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaLexer.g Sun Jun  9 15:04:15 2013
@@ -355,6 +355,10 @@ XOR	: 	'XOR';
 TRUE 	:	'true';
 FALSE 	:	'false';
 
+
+STARTANCHOR 
+	:	 '@';
+
 HexLiteral : '0' ('x'|'X') HexDigit+ IntegerTypeSuffix? ;
 
 DecimalLiteral : ('0' | '1'..'9' '0'..'9'*) IntegerTypeSuffix? ;
@@ -469,8 +473,6 @@ RCURLY	: '}' {implicitLineJoiningLevel--
 
 CIRCUMFLEX	: '^' ;
 
-AT : '@' ;
-
 DOT : '.' ;
 
 COLON 	: ':' ;

Modified: uima/sandbox/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaParser.g
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaParser.g?rev=1491230&r1=1491229&r2=1491230&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaParser.g (original)
+++ uima/sandbox/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaParser.g Sun Jun  9 15:04:15 2013
@@ -603,11 +603,14 @@ ruleElements[RuleElementContainer contai
 
 ruleElement[RuleElementContainer container] returns [RuleElement re = null]
 	:
+	start = STARTANCHOR? (
 	re1 = ruleElementType[container] {re = re1;}
 	| re2 = ruleElementLiteral[container] {re = re2;}
 	| (ruleElementComposed[null])=>re3 = ruleElementComposed[container] {re = re3;}
 	| (ruleElementDisjunctive[null])=> re4 = ruleElementDisjunctive[container] {re = re4;}
 	| (ruleElementWildCard[null])=> re5 = ruleElementWildCard[container] {re = re5;}
+	)
+	{re.setStartAnchor(start != null);}
 	;	
 
 ruleElementWildCard [RuleElementContainer container] returns [AbstractRuleElement re = null]

Modified: uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/AbstractRuleElement.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/AbstractRuleElement.java?rev=1491230&r1=1491229&r2=1491230&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/AbstractRuleElement.java (original)
+++ uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/AbstractRuleElement.java Sun Jun  9 15:04:15 2013
@@ -40,6 +40,8 @@ public abstract class AbstractRuleElemen
 
   protected List<AbstractRutaAction> actions;
 
+  private boolean startAnchor;
+  
   private RuleElementContainer container;
 
   protected RutaBlock parent;
@@ -67,6 +69,8 @@ public abstract class AbstractRuleElemen
   @SuppressWarnings("unchecked")
   protected final InferenceCrowd emptyCrowd = new InferenceCrowd(Collections.EMPTY_LIST);
 
+  
+
   protected void doneMatching(RuleMatch ruleMatch, RuleApply ruleApply, RutaStream stream,
           InferenceCrowd crowd) {
     if (!ruleMatch.isApplied()) {
@@ -163,4 +167,12 @@ public abstract class AbstractRuleElemen
     return container;
   }
 
+  public  void setStartAnchor(boolean start) {
+    this.startAnchor = start;
+  }
+
+  public boolean isStartAnchor() {
+    return startAnchor;
+  }
+
 }

Modified: uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElement.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElement.java?rev=1491230&r1=1491229&r2=1491230&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElement.java (original)
+++ uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElement.java Sun Jun  9 15:04:15 2013
@@ -70,4 +70,9 @@ public interface RuleElement {
   List<AbstractRutaAction> getActions();
 
   boolean hasAncestor(boolean after);
+
+  void setStartAnchor(boolean start);
+  
+  boolean isStartAnchor();
+  
 }

Modified: uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementCaretaker.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementCaretaker.java?rev=1491230&r1=1491229&r2=1491230&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementCaretaker.java (original)
+++ uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementCaretaker.java Sun Jun  9 15:04:15 2013
@@ -60,7 +60,12 @@ public class RuleElementCaretaker implem
     if (ruleElements.size() == 1 || containsLiteralMatcher(ruleElements)) {
       return ruleElements.get(0);
     }
-
+    for (RuleElement ruleElement : ruleElements) {
+      if(ruleElement.isStartAnchor()) {
+        return ruleElement;
+      }
+    }
+    
     if (stream.isDynamicAnchoring()) {
       long min = Long.MAX_VALUE;
       RuleElement minElement = null;

Modified: uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java?rev=1491230&r1=1491229&r2=1491230&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java (original)
+++ uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java Sun Jun  9 15:04:15 2013
@@ -78,7 +78,7 @@ public class RutaRuleElement extends Abs
             sideStepOrigin = hasAncestor(false) ? this : null;
             after.continueMatch(true, eachAnchor, extendedMatch, ruleApply, extendedContainerMatch,
                     sideStepOrigin, null, stream, crowd);
-          } else if (stream.isDynamicAnchoring() && before != null) {
+          } else if ((stream.isDynamicAnchoring() || isStartAnchor()) && before != null) {
             sideStepOrigin = hasAncestor(true) ? this : null;
             before.continueMatch(false, eachAnchor, extendedMatch, ruleApply,
                     extendedContainerMatch, sideStepOrigin, null, stream, crowd);

Modified: uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java?rev=1491230&r1=1491229&r2=1491230&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java (original)
+++ uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java Sun Jun  9 15:04:15 2013
@@ -72,8 +72,8 @@ public class WildCardRuleElement extends
         break;
       }
     }
-    if(nextElement == null) {
-      nextDepth =0;
+    if (nextElement == null) {
+      nextDepth = 0;
     }
     tryWithNextRuleElement(nextElement, after, annotation, ruleMatch, ruleApply, containerMatch,
             nextDepth, sideStepOrigin, entryPoint, stream, crowd);
@@ -95,36 +95,38 @@ public class WildCardRuleElement extends
       RutaRuleElement re = (RutaRuleElement) nextElement;
       RutaMatcher matcher = re.getMatcher();
       if (matcher instanceof RutaTypeMatcher) {
-        tryWithNextType(after, annotation, nextElement, null, ruleMatch, ruleApply, containerMatch, nextDepth,
-                sideStepOrigin, stream, crowd);
+        tryWithNextType(after, annotation, nextElement, null, ruleMatch, ruleApply, containerMatch,
+                nextDepth, sideStepOrigin, stream, crowd);
       } else if (matcher instanceof RutaLiteralMatcher) {
         tryWithNextLiteral(after, annotation, re, ruleMatch, ruleApply, containerMatch, nextDepth,
                 sideStepOrigin, stream, crowd);
       } else if (matcher instanceof RutaDisjunctiveMatcher) {
-        tryWithNextType(after, annotation, re, null, ruleMatch, ruleApply, containerMatch, nextDepth,
-                sideStepOrigin, stream, crowd);
+        tryWithNextType(after, annotation, re, null, ruleMatch, ruleApply, containerMatch,
+                nextDepth, sideStepOrigin, stream, crowd);
       }
 
     } else if (nextElement instanceof ComposedRuleElement) {
       ComposedRuleElement cre = ((ComposedRuleElement) nextElement);
-      tryWithNextComposed(after, annotation, cre, ruleMatch, ruleApply, containerMatch,
-              nextDepth, sideStepOrigin, stream, crowd);
-//      RuleElement nextInnerRuleElement = null;
-//      if (after) {
-//        nextInnerRuleElement = cre.getFirstElement();
-//      } else {
-//        nextInnerRuleElement = cre.getLastElement();
-//      }
-//      // TODO won't work ...!!!
-//      ComposedRuleElementMatch nextContainerMatch = getContainerMatchOfNextElement(containerMatch, nextDepth);
-//      ComposedRuleElementMatch composedMatch = new ComposedRuleElementMatch(cre, nextContainerMatch);
-//      if (containerMatch == null) {
-//        ruleMatch.setRootMatch(composedMatch);
-//      } else {
-//        nextContainerMatch.addInnerMatch(this, composedMatch, false, stream);
-//      }
-//      tryWithNextRuleElement(nextInnerRuleElement, after, annotation, ruleMatch, ruleApply,
-//              composedMatch, nextDepth, sideStepOrigin, entryPoint, stream, crowd);
+      tryWithNextComposed(after, annotation, cre, ruleMatch, ruleApply, containerMatch, nextDepth,
+              sideStepOrigin, stream, crowd);
+      // RuleElement nextInnerRuleElement = null;
+      // if (after) {
+      // nextInnerRuleElement = cre.getFirstElement();
+      // } else {
+      // nextInnerRuleElement = cre.getLastElement();
+      // }
+      // // TODO won't work ...!!!
+      // ComposedRuleElementMatch nextContainerMatch =
+      // getContainerMatchOfNextElement(containerMatch, nextDepth);
+      // ComposedRuleElementMatch composedMatch = new ComposedRuleElementMatch(cre,
+      // nextContainerMatch);
+      // if (containerMatch == null) {
+      // ruleMatch.setRootMatch(composedMatch);
+      // } else {
+      // nextContainerMatch.addInnerMatch(this, composedMatch, false, stream);
+      // }
+      // tryWithNextRuleElement(nextInnerRuleElement, after, annotation, ruleMatch, ruleApply,
+      // composedMatch, nextDepth, sideStepOrigin, entryPoint, stream, crowd);
     } else if (nextElement instanceof WildCardRuleElement) {
       // another wildcard? seriously? then just assume its an "Annotation" type
       CAS cas = stream.getCas();
@@ -134,8 +136,8 @@ public class WildCardRuleElement extends
   }
 
   private void tryWithNextComposed(boolean after, AnnotationFS annotation, ComposedRuleElement cre,
-          RuleMatch ruleMatch, RuleApply ruleApply, ComposedRuleElementMatch containerMatch, int nextDepth,
-          RutaRuleElement sideStepOrigin, RutaStream stream, InferenceCrowd crowd) {
+          RuleMatch ruleMatch, RuleApply ruleApply, ComposedRuleElementMatch containerMatch,
+          int nextDepth, RutaRuleElement sideStepOrigin, RutaStream stream, InferenceCrowd crowd) {
     AnnotationFS nextOne = annotation;
     boolean doneHere = false;
     while (!doneHere && (nextOne = getNextPositionForComposed(cre, after, nextOne, stream)) != null) {
@@ -147,7 +149,8 @@ public class WildCardRuleElement extends
       doMatch(coveredByWildCard, extendedMatch, extendedContainerMatch, annotation == null, stream,
               crowd);
       if (extendedMatch.matched()) {
-        ComposedRuleElementMatch nextContainerMatch = getContainerMatchOfNextElement(extendedContainerMatch, nextDepth);
+        ComposedRuleElementMatch nextContainerMatch = getContainerMatchOfNextElement(
+                extendedContainerMatch, nextDepth);
         if (endAnchor == null) {
           cre.startMatch(extendedMatch, ruleApply, nextContainerMatch, cre, stream, crowd);
         } else {
@@ -168,9 +171,10 @@ public class WildCardRuleElement extends
       }
     }
     if (!doneHere) {
-      ComposedRuleElementMatch nextContainerMatch = getContainerMatchOfNextElement(containerMatch, nextDepth);
-      cre.continueMatch(after, annotation, ruleMatch, ruleApply, nextContainerMatch, sideStepOrigin,
-              null, stream, crowd);
+      ComposedRuleElementMatch nextContainerMatch = getContainerMatchOfNextElement(containerMatch,
+              nextDepth);
+      cre.continueMatch(after, annotation, ruleMatch, ruleApply, nextContainerMatch,
+              sideStepOrigin, null, stream, crowd);
     }
   }
 
@@ -259,14 +263,15 @@ public class WildCardRuleElement extends
       doMatch(coveredByWildCard, extendedMatch, extendedContainerMatch, annotation == null, stream,
               crowd);
       if (extendedMatch.matched()) {
-        ComposedRuleElementMatch nextContainerMatch = getContainerMatchOfNextElement(extendedContainerMatch, nextDepth);
+        ComposedRuleElementMatch nextContainerMatch = getContainerMatchOfNextElement(
+                extendedContainerMatch, nextDepth);
         if (endAnchor == null) {
-          nextElement.startMatch(extendedMatch, ruleApply, nextContainerMatch, nextElement,
-                  stream, crowd);
+          nextElement.startMatch(extendedMatch, ruleApply, nextContainerMatch, nextElement, stream,
+                  crowd);
         } else {
           // TODO match and containermatch should be on the correct level!
-          nextElement.continueMatch(after, endAnchor, extendedMatch, ruleApply,
-                  nextContainerMatch, sideStepOrigin, nextElement, stream, crowd);
+          nextElement.continueMatch(after, endAnchor, extendedMatch, ruleApply, nextContainerMatch,
+                  sideStepOrigin, nextElement, stream, crowd);
         }
         List<RuleElementMatch> nextList = nextContainerMatch.getInnerMatches().get(nextElement);
         if (nextList == null || nextList.isEmpty() || !nextList.get(nextList.size() - 1).matched()) {
@@ -329,6 +334,9 @@ public class WildCardRuleElement extends
       } else {
         AnnotationFS pointer = stream.getAnchor(after, annotation);
         result = cas.getAnnotationIndex(type).iterator(pointer);
+        if (!after) {
+          result.moveToPrevious();
+        }
       }
     } else {
       JCas jcas = null;
@@ -345,6 +353,9 @@ public class WildCardRuleElement extends
         result = cas.getAnnotationIndex(type).subiterator(window);
         AnnotationFS pointer = stream.getAnchor(after, annotation);
         result.moveTo(pointer);
+        if (!after) {
+          result.moveToPrevious();
+        }
       }
     }
 
@@ -371,7 +382,8 @@ public class WildCardRuleElement extends
     while (!doneHere && (indexOf = document.indexOf(stringValue, pointer)) < document.length()) {
       if (indexOf < 0) {
         // can't match, the next next element will see it.
-        ComposedRuleElementMatch nextContainerMatch = getContainerMatchOfNextElement(containerMatch, nextDepth);
+        ComposedRuleElementMatch nextContainerMatch = getContainerMatchOfNextElement(
+                containerMatch, nextDepth);
         nextElement.continueMatch(after, annotation, ruleMatch, ruleApply, nextContainerMatch,
                 sideStepOrigin, null, stream, crowd);
         doneHere = true;
@@ -385,13 +397,14 @@ public class WildCardRuleElement extends
       doMatch(coveredByWildCard, extendedMatch, extendedContainerMatch, annotation == null, stream,
               crowd);
       if (extendedMatch.matched()) {
-        ComposedRuleElementMatch nextContainerMatch = getContainerMatchOfNextElement(extendedContainerMatch, nextDepth);
+        ComposedRuleElementMatch nextContainerMatch = getContainerMatchOfNextElement(
+                extendedContainerMatch, nextDepth);
         if (endAnchor == null) {
-          nextElement.startMatch(extendedMatch, ruleApply, nextContainerMatch, nextElement,
-                  stream, crowd);
+          nextElement.startMatch(extendedMatch, ruleApply, nextContainerMatch, nextElement, stream,
+                  crowd);
         } else {
-          nextElement.continueMatch(after, endAnchor, extendedMatch, ruleApply,
-                  nextContainerMatch, sideStepOrigin, nextElement, stream, crowd);
+          nextElement.continueMatch(after, endAnchor, extendedMatch, ruleApply, nextContainerMatch,
+                  sideStepOrigin, nextElement, stream, crowd);
         }
         List<RuleElementMatch> nextList = nextContainerMatch.getInnerMatches().get(nextElement);
         if (nextList == null || nextList.isEmpty()) {

Modified: uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/explain/element/ElementTreeLabelProvider.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/explain/element/ElementTreeLabelProvider.java?rev=1491230&r1=1491229&r2=1491230&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/explain/element/ElementTreeLabelProvider.java (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/explain/element/ElementTreeLabelProvider.java Sun Jun  9 15:04:15 2013
@@ -73,7 +73,7 @@ public class ElementTreeLabelProvider ex
         Feature fanchor = type.getFeatureByBaseName(ExplainConstants.RULE_ANCHOR);
         if (f != null && fanchor != null) {
           String v = fs.getStringValue(f);
-          String ruleAnchor = fs.getBooleanValue(fanchor) ? "'" : "";
+          String ruleAnchor = fs.getBooleanValue(fanchor) ? "@" : "";
           return ruleAnchor + v;
         }
       } else if (element instanceof RuleElementMatchNode) {

Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaLexer.g
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaLexer.g?rev=1491230&r1=1491229&r2=1491230&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaLexer.g (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaLexer.g Sun Jun  9 15:04:15 2013
@@ -355,6 +355,9 @@ XOR	: 	'XOR';
 TRUE 	:	'true';
 FALSE 	:	'false';
 
+STARTANCHOR 
+	:	 '@';
+
 HexLiteral : '0' ('x'|'X') HexDigit+ IntegerTypeSuffix? ;
 
 DecimalLiteral : ('0' | '1'..'9' '0'..'9'*) IntegerTypeSuffix? ;
@@ -469,8 +472,6 @@ RCURLY	: '}' {implicitLineJoiningLevel--
 
 CIRCUMFLEX	: '^' ;
 
-AT : '@' ;
-
 DOT : '.' ;
 
 COLON 	: ':' ;

Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaParser.g
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaParser.g?rev=1491230&r1=1491229&r2=1491230&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaParser.g (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaParser.g Sun Jun  9 15:04:15 2013
@@ -635,10 +635,13 @@ blockRuleElement returns [RutaRuleElemen
 	
 ruleElement returns [Expression re = null]
 	:
+	STARTANCHOR?
+	(
 	re1 = ruleElementType {re = re1;}
 	| re2 = ruleElementLiteral {re = re2;}
 	| re3 = ruleElementComposed {re = re3;}
 	| re4 = ruleElementWildCard {re = re4;}
+	)
 	;
 
 ruleElementWildCard returns [RutaRuleElement re = null] 
@@ -713,6 +716,7 @@ List<RutaCondition> dummyConds = new Arr
 
 ruleElementLiteral returns [RutaRuleElement re = null] 
     :
+    
     (simpleStringExpression)=>idRef=simpleStringExpression quantifier = quantifierPart? 
         (LCURLY 
 
@@ -875,11 +879,13 @@ options {
 expr = ExpressionFactory.createEmptyTypeExpression(input.LT(1));
 }
 	:
+	(
 	(featureTypeExpression)=> ft = featureTypeExpression {expr = ft;}
 	| 
-	tf = typeFunction {expr = tf;}
+	(typeFunction)=> tf = typeFunction {expr = tf;}
 	| 
 	st = simpleTypeExpression 
+	)
 	{expr = ExpressionFactory.createTypeExpression(st);
 	 }