Added: 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/parser/TextMarker.g
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/parser/TextMarker.g?rev=1157040&view=auto
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/parser/TextMarker.g
 (added)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/parser/TextMarker.g
 Fri Aug 12 10:44:04 2011
@@ -0,0 +1,1791 @@
+grammar TextMarker;
+
+options {
+       language = Java;
+}
+
+tokens {
+       DocComment;
+       Annotation;
+       ListIdentifier;
+}
+
+@lexer::header {
+       package org.apache.uima.textmarker.parser;
+}
+
+@parser::header {
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+*/
+
+package org.apache.uima.textmarker.parser;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Stack;
+
+import org.antlr.runtime.BaseRecognizer;
+import org.antlr.runtime.BitSet;
+import org.antlr.runtime.DFA;
+import org.antlr.runtime.EarlyExitException;
+import org.antlr.runtime.FailedPredicateException;
+import org.antlr.runtime.IntStream;
+import org.antlr.runtime.MismatchedSetException;
+import org.antlr.runtime.NoViableAltException;
+import org.antlr.runtime.Parser;
+import org.antlr.runtime.RecognitionException;
+import org.antlr.runtime.RecognizerSharedState;
+import org.antlr.runtime.Token;
+import org.antlr.runtime.TokenStream;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.CASException;
+import org.apache.uima.cas.Type;
+import org.apache.uima.jcas.tcas.DocumentAnnotation;
+
+import org.apache.uima.textmarker.action.AbstractTextMarkerAction;
+import org.apache.uima.textmarker.action.ActionFactory;
+import org.apache.uima.textmarker.condition.AbstractTextMarkerCondition;
+import org.apache.uima.textmarker.condition.ConditionFactory;
+import org.apache.uima.textmarker.TextMarkerBlock;
+import org.apache.uima.textmarker.TextMarkerModule;
+import org.apache.uima.textmarker.TextMarkerScriptBlock;
+import org.apache.uima.textmarker.TextMarkerScriptFactory;
+import org.apache.uima.textmarker.TextMarkerStatement;
+import org.apache.uima.textmarker.expression.bool.BooleanExpression;
+import org.apache.uima.textmarker.expression.ExpressionFactory;
+import org.apache.uima.textmarker.expression.resource.WordListExpression;
+import org.apache.uima.textmarker.expression.number.NumberExpression;
+import org.apache.uima.textmarker.expression.string.StringExpression;
+import org.apache.uima.textmarker.expression.resource.WordTableExpression;
+import org.apache.uima.textmarker.expression.TextMarkerExpression;
+import org.apache.uima.textmarker.expression.type.TypeExpression;
+import org.apache.uima.textmarker.extensions.TextMarkerExternalFactory;
+import org.apache.uima.textmarker.rule.ComposedRuleElement;
+import org.apache.uima.textmarker.rule.RuleElement;
+import org.apache.uima.textmarker.rule.TextMarkerRule;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.rule.quantifier.RuleElementQuantifier;
+}
+@lexer::members {
+       public int implicitLineJoiningLevel = 0;
+       public int startPos=-1;
+       public void emitErrorMessage(String msg) {
+       }
+}
+@parser::members {
+private List vars = new ArrayList();   
+private int level = 0;
+private TextMarkerScriptFactory factory = new TextMarkerScriptFactory();
+private TextMarkerExternalFactory external;
+
+
+public void setExternalFactory(TextMarkerExternalFactory factory) {
+       external = factory;
+}
+
+public void emitErrorMessage(String msg) {
+               System.out.println(msg);
+       }
+       public void reportError(RecognitionException e) {
+               System.out.println(e);
+       }
+
+       //public void addVariable(String var, IntStream input) throws 
NoViableAltException {
+       //      if(!vars.contains(var)) {
+       //              vars.add(var);
+       //      } else {
+       //              throw new NoViableAltException("already declared \"" + 
var + "\"", 3, 0, input);
+       //      }
+       //}
+       public void addVariable(TextMarkerBlock parent, String name, String 
type) {
+               parent.getEnvironment().addVariable(name, type);
+       }
+       
+       public boolean ownsVariable(TextMarkerBlock parent, String name) {
+               return parent.getEnvironment().ownsVariable(name);
+       }
+       public boolean isVariable(TextMarkerBlock parent, String name) {
+               return parent.getEnvironment().isVariable(name);
+       }
+       
+       public void setValue(TextMarkerBlock parent, String name, Object value) 
{
+               if(value != null) {
+                       parent.getEnvironment().setVariableValue(name, value);
+               }
+       }
+       
+       public boolean ownsVariableOfType(TextMarkerBlock parent, String name, 
String type) {
+               return parent.getEnvironment().ownsVariableOfType(name,type);
+       }
+       
+       public boolean isVariableOfType(TextMarkerBlock parent, String name, 
String type) {
+               return parent.getEnvironment().isVariableOfType(name,type);
+       }
+       
+       public void addType(TextMarkerBlock parent, String type) {
+       }
+       
+       public void addType(TextMarkerBlock parent, String name, String 
parentType, List featuresTypes, List featuresNames) {
+       }
+       
+       public boolean isType(TextMarkerBlock parent, String type) {
+               return parent.getEnvironment().getType(type) != null || 
type.equals("Document");
+       }
+       
+       public void checkVariable(String var, IntStream input) throws 
NoViableAltException {
+               if(!vars.contains(var)) {
+                       throw new NoViableAltException("not declared \"" + var 
+ "\"", 3, 0, input);
+               }
+       }
+       
+       public void addImportTypeSystem(TextMarkerBlock parent, String 
descriptor) {
+               //parent.getEnvironment().addTypeSystem(descriptor);
+       }
+       public void addImportScript(TextMarkerBlock parent, String namespace) {
+               parent.getScript().addScript(namespace, null);
+       }
+       public void addImportEngine(TextMarkerBlock parent, String namespace) {
+               parent.getScript().addEngine(namespace, null);
+       }
+       
+       
+       protected static final int[] getBounds(Token t) {
+               if (t instanceof CommonToken) {
+                       CommonToken ct = (CommonToken) t;
+                       int[] bounds = {ct.getStartIndex(), ct.getStopIndex()}; 
+                       return bounds;
+               }
+               return null;
+       }
+       
+       private CAS cas;
+       private String baseDir;
+       
+       public void setCAS(CAS cas) {
+               this.cas = cas;
+       }
+       
+       public void setBaseDir(String baseDir) {
+               this.baseDir = baseDir;
+       }
+}
+
+@rulecatch {
+       catch (RecognitionException exception1) {
+               emitErrorMessage(exception1.toString());
+       }
+       catch (Throwable exception2) {
+               emitErrorMessage(exception2.toString());
+       }
+}
+
+
+file_input [String moduleName] returns [TextMarkerModule module]
+@init{
+TextMarkerScriptBlock rootBlock = null;
+List<TextMarkerStatement> stmts = new ArrayList<TextMarkerStatement>();
+}
+       :
+       p = packageDeclaration  
+       {
+       rootBlock = factory.createRootScriptBlock(moduleName, p, cas);
+               
+        try {
+               Type documentType = 
cas.getJCas().getCasType(DocumentAnnotation.type);
+               rootBlock.getEnvironment().addType("Document", documentType);
+               Type annotationType = 
cas.getJCas().getCasType(org.apache.uima.jcas.tcas.Annotation.type);
+               rootBlock.getEnvironment().addType("Annotation", 
annotationType);
+               rootBlock.getEnvironment().setBaseDir(baseDir);
+               } catch (CASException e) {
+                       e.printStackTrace();
+               }
+       rootBlock.setElements(stmts);
+       module = new TextMarkerModule(rootBlock);
+       rootBlock.setScript(module);
+       }
+       {$blockDeclaration.push(new 
blockDeclaration_scope());$blockDeclaration::env = rootBlock;}
+       
+       gs = globalStatements   {stmts.addAll(gs);}
+       s = statements          {stmts.addAll(s);}
+       
+       EOF
+       ;
+
+packageDeclaration returns [String pack = ""]
+       :       PackageString p = dottedIdentifier SEMI {pack = p;}
+       ;
+
+statements returns [List<TextMarkerStatement> stmts = new 
ArrayList<TextMarkerStatement>()]
+       :
+       (stmt = statement {{if(stmt != null) {stmts.add(stmt);}}})*
+       ;
+
+globalStatements returns [List<TextMarkerStatement> stmts = new 
ArrayList<TextMarkerStatement>()]
+       :
+       (morestmts = globalStatement {if(morestmts != null) 
{stmts.addAll(morestmts);}})*
+       ;
+
+globalStatement returns [List<TextMarkerStatement> stmts = new 
ArrayList<TextMarkerStatement>()]
+       :
+       stmtImport = importStatement {stmts.add(stmtImport);}
+       ;
+       
+statement returns [TextMarkerStatement stmt = null]
+       :       
+       ( stmtDecl = declaration {stmt = stmtDecl;}
+       | stmtVariable = variableDeclaration {stmt = stmtVariable;}
+       | stmtRule = simpleStatement {stmt = stmtRule;}
+       | stmtBlock = blockDeclaration {stmt = stmtBlock;}
+       )
+       ;
+
+variableDeclaration returns [TextMarkerStatement stmt = null]
+       :
+       type = IntString
+       {!ownsVariable($blockDeclaration::env, input.LT(1).getText())}? id = 
Identifier {addVariable($blockDeclaration::env, id.getText(), type.getText());}
+               (COMMA {!ownsVariable($blockDeclaration::env, 
input.LT(1).getText())}? id = Identifier {addVariable($blockDeclaration::env, 
id.getText(), type.getText());}
+                )*(ASSIGN_EQUAL value1 = numberExpression)? 
{setValue($blockDeclaration::env, id.getText(), value1);}  SEMI
+       |
+       type = DoubleString
+       {!ownsVariable($blockDeclaration::env, input.LT(1).getText())}? id = 
Identifier {addVariable($blockDeclaration::env, id.getText(), type.getText());}
+               (COMMA {!ownsVariable($blockDeclaration::env, 
input.LT(1).getText())}? id = Identifier {addVariable($blockDeclaration::env, 
id.getText(), type.getText());}
+                )* (ASSIGN_EQUAL value2 = numberExpression)? 
{setValue($blockDeclaration::env, id.getText(), value2);} SEMI
+       |
+       type = StringString
+       {!ownsVariable($blockDeclaration::env, input.LT(1).getText())}? id = 
Identifier {addVariable($blockDeclaration::env, id.getText(), type.getText());}
+               (COMMA {!ownsVariable($blockDeclaration::env, 
input.LT(1).getText())}? id = Identifier {addVariable($blockDeclaration::env, 
id.getText(), type.getText());}
+                )* (ASSIGN_EQUAL value3 = stringExpression)? 
{setValue($blockDeclaration::env, id.getText(), value3);} SEMI
+       |
+       type = BooleanString
+       {!ownsVariable($blockDeclaration::env, input.LT(1).getText())}? id = 
Identifier {addVariable($blockDeclaration::env, id.getText(), type.getText());}
+               (COMMA {!ownsVariable($blockDeclaration::env, 
input.LT(1).getText())}? id = Identifier {addVariable($blockDeclaration::env, 
id.getText(), type.getText());}
+                )* (ASSIGN_EQUAL value4 = booleanExpression)? 
{setValue($blockDeclaration::env, id.getText(), value4);} SEMI
+       |
+       type = TypeString
+       {!ownsVariable($blockDeclaration::env, input.LT(1).getText())}? id = 
Identifier {addVariable($blockDeclaration::env, id.getText(), type.getText());}
+               (COMMA {!ownsVariable($blockDeclaration::env, 
input.LT(1).getText())}? id = Identifier {addVariable($blockDeclaration::env, 
id.getText(), type.getText());}
+                )* (ASSIGN_EQUAL value5 = annotationType)? 
{setValue($blockDeclaration::env, id.getText(), value5);} SEMI
+       | LIST 
+       {!isVariableOfType($blockDeclaration::env, input.LT(1).getText(), 
"LIST")}? 
+       name = Identifier (ASSIGN_EQUAL list = listExpression)? SEMI 
{addVariable($blockDeclaration::env, name.getText(), "LIST");if(list != 
null){setValue($blockDeclaration::env, name.getText(), list);}} 
+       | TABLE 
+       {!isVariableOfType($blockDeclaration::env, input.LT(1).getText(), 
"TABLE")}? 
+       name = Identifier (ASSIGN_EQUAL table = tableExpression)? SEMI 
{addVariable($blockDeclaration::env, name.getText(), "TABLE");if(table != 
null){setValue($blockDeclaration::env, name.getText(), table);}}
+       |
+       stmt1 = conditionDeclaration {stmt = stmt1;}
+       |
+       stmt2 = actionDeclaration {stmt = stmt2;}
+       ;
+
+//TODO added rule
+conditionDeclaration returns [TextMarkerStatement stmt = null]
+    :
+    type = CONDITION id = Identifier ASSIGN_EQUAL LPAREN cons = conditions 
RPAREN SEMI
+    {addVariable($blockDeclaration::env, id.getText(), type.getText());
+    AbstractTextMarkerCondition condition = 
ConditionFactory.createConditionAnd(cons,$blockDeclaration::env);
+    setValue($blockDeclaration::env, id.getText(), condition);}
+    ;
+
+//TODO added rule
+actionDeclaration returns [TextMarkerStatement stmt = null]
+    :
+    type = ACTION id = Identifier ASSIGN_EQUAL LPAREN a = actions RPAREN SEMI
+    {addVariable($blockDeclaration::env, id.getText(), type.getText());
+    AbstractTextMarkerAction action = 
ActionFactory.createComposedAction(a,$blockDeclaration::env);
+    setValue($blockDeclaration::env, id.getText(), action);}
+    ;
+
+importStatement returns [TextMarkerStatement stmt = null]
+       :
+       TypeSystemString ts = 
dottedIdentifier2{addImportTypeSystem($blockDeclaration::env, ts);} SEMI
+       | ScriptString ns = 
dottedIdentifier2{addImportScript($blockDeclaration::env, ns);} SEMI
+       | EngineString ns = 
dottedIdentifier2{addImportEngine($blockDeclaration::env, ns);} SEMI
+       ;
+
+declaration returns [TextMarkerStatement stmt = null]
+@init {
+List featureTypes = new ArrayList();
+List featureNames = new ArrayList();
+}
+       :
+       (
+       DECLARE 
+       //{!isType($blockDeclaration::env, input.LT(1).getText())}? 
+       lazyParent = annotationType?
+       id = Identifier //{addType($blockDeclaration::env, id.getText(), 
lazyParent);}
+                       (COMMA 
+                       //{!isType($blockDeclaration::env, 
input.LT(1).getText())}? 
+                       id = Identifier //{addType($blockDeclaration::env, 
id.getText(), lazyParent);}
+                )* SEMI
+       | 
+       DECLARE type = annotationType newName = Identifier 
+               (LPAREN 
+                       (
+                       obj1 = 
annotationType{featureTypes.add(obj1.getText());} 
+                       | obj2 = 
StringString{featureTypes.add(obj2.getText());} 
+                       | obj3 = DoubleString{featureTypes.add(obj3.getText());}
+                       | obj4 = IntString{featureTypes.add(obj4.getText());}
+                       | obj5 = 
BooleanString{featureTypes.add(obj5.getText());}
+                       ) 
+                       fname = Identifier{featureNames.add(fname.getText());} 
+                       (
+                       COMMA 
+                       (
+                       obj1 = 
annotationType{featureTypes.add(obj1.getText());} 
+                       | obj2 = 
StringString{featureTypes.add(obj2.getText());} 
+                       | obj3 = DoubleString{featureTypes.add(obj3.getText());}
+                       | obj4 = IntString{featureTypes.add(obj4.getText());}
+                       | obj5 = 
BooleanString{featureTypes.add(obj5.getText());}
+                       ) 
+                       fname = 
Identifier{featureNames.add(fname.getText());})* 
+               RPAREN) SEMI 
+               {addType($blockDeclaration::env, newName.getText(), 
type.getText(), featureTypes, featureNames);}
+       )
+       ;
+       
+       
+blockDeclaration returns [TextMarkerBlock block = null]
+options {
+       backtrack = true;
+}
+
+scope {
+       TextMarkerBlock env;
+}
+@init{
+TextMarkerRuleElement re = null;
+level++;
+}
+@after {
+level--;
+}
+
+       :
+       type = BlockString 
+       LPAREN
+       id = Identifier 
+       RPAREN
+       {block = factory.createScriptBlock(id, re, body, 
$blockDeclaration[level - 1]::env, cas);}
+       {$blockDeclaration::env = block;}
+       re1 = ruleElementWithCA {re = re1;}
+       {TextMarkerRule rule = factory.createRule(re, block);
+       if(block instanceof TextMarkerScriptBlock) {
+       ((TextMarkerScriptBlock)block).setMatchRule(rule);
+       }}
+       LCURLY body = statements RCURLY
+       {block.setElements(body);
+       $blockDeclaration::env.getScript().addBlock(id.getText(),block);
+       }       
+       ;
+       
+ruleElementWithCA returns [TextMarkerRuleElement re = null] 
+    :
+    idRef=typeExpression quantifier = quantifierPart? 
+        LCURLY c = conditions? (THEN a = actions)? RCURLY
+        {re = factory.createRuleElement(idRef,quantifier,c,a, 
$blockDeclaration::env);}
+    ;
+
+       
+ruleElementWithoutCA returns [TextMarkerRuleElement re = null] 
+    :
+    idRef=typeExpression quantifier = quantifierPart? 
+             {re = factory.createRuleElement(idRef,quantifier,null,null, 
$blockDeclaration::env);}
+
+    ;  
+       
+simpleStatement returns [TextMarkerRule stmt = null]
+       : 
+       elements = ruleElements SEMI 
+               {stmt = factory.createRule(elements, $blockDeclaration::env);}
+       ;
+       
+ruleElements returns [List<RuleElement> elements = new 
ArrayList<RuleElement>()]
+       :
+       re = ruleElement {elements.add(re);} (re = ruleElement 
{elements.add(re);})*
+       ;
+       
+blockRuleElement returns [List<RuleElement> elements = new 
ArrayList<RuleElement>()]
+       :
+       re = ruleElementType {elements.add(re);}
+       ;
+       
+
+ruleElement returns [RuleElement re = null]
+       :
+       re1 = ruleElementType {re = re1;}
+       | re2 = ruleElementLiteral {re = re2;}
+       | re3 = ruleElementComposed {re = re3;} 
+       ;       
+
+ruleElementComposed returns [ComposedRuleElement re = null]
+       :
+       LPAREN res = ruleElements RPAREN q = quantifierPart
+       {re = factory.createComposedRuleElement(res, q, 
$blockDeclaration::env);}
+       ;
+
+ruleElementType returns [TextMarkerRuleElement re = null]
+    :
+    
+    (typeExpression)=>typeExpr = typeExpression quantifier = quantifierPart? 
+        (LCURLY c = conditions? (THEN a = actions)? RCURLY)?
+    {re = factory.createRuleElement(typeExpr, quantifier, c, a, 
$blockDeclaration::env);}   
+    ;
+
+ruleElementLiteral returns [TextMarkerRuleElement re = null]
+    :
+    (simpleStringExpression)=>stringExpr = simpleStringExpression quantifier = 
quantifierPart? 
+        (LCURLY c = conditions? (THEN a = actions)? RCURLY)?
+    {re = factory.createRuleElement(stringExpr, quantifier, c, a, 
$blockDeclaration::env);} 
+    ;
+       
+conditions returns [List<AbstractTextMarkerCondition> conds = new 
ArrayList<AbstractTextMarkerCondition>()]
+    :
+    c = condition {conds.add(c);} (COMMA c = condition {conds.add(c);} )*
+    ;
+    
+actions returns [List<AbstractTextMarkerAction> actions = new 
ArrayList<AbstractTextMarkerAction>()]
+    :
+    a = action {actions.add(a);} (COMMA a = action {actions.add(a);} )*
+    ;  
+       
+typeExpression returns [TypeExpression type = null]
+options {
+       backtrack = true;
+}
+       :
+       tf = typeFunction {type = tf;}
+       | st = simpleTypeExpression {type = st;}
+       ;
+       
+
+// not checked
+typeFunction returns [TypeExpression expr = null]
+       :
+       (e = externalTypeFunction)=> e = externalTypeFunction {expr = e;}
+       ;
+
+// not checked
+externalTypeFunction returns [TypeExpression expr = null]
+       :
+       //{isVariableOfType($blockDeclaration::env, input.LT(1).getText(), 
"TYPEFUNCTION")}? 
+       id = Identifier LPAREN
+       args = varArgumentList  RPAREN
+       {
+               expr = external.createExternalTypeFunction(id, args);
+       }
+       ;
+
+simpleTypeExpression returns [TypeExpression type = null]
+       :
+       {isVariableOfType($blockDeclaration::env,input.LT(1).getText(), 
"TYPE")}? var = Identifier 
+       {type = ExpressionFactory.createReferenceTypeExpression(var);}
+       |
+       at = annotationType
+       {type = ExpressionFactory.createSimpleTypeExpression(at, 
$blockDeclaration::env);}
+       
+       
+       ;
+
+//typeExpressionOr returns [TypeExpression type = null]
+//@init {List<TypeExpression> exprs = new ArrayList<TypeExpression>();}
+//     :
+//     LBRACK e = typeExpressionAnd{exprs.add(e);} ( COMMA e = 
typeExpressionAnd{exprs.add(e);} )* RBRACK
+//     {type = ExpressionFactory.createOrTypeExpression(exprs);}
+//     ;
+
+//typeExpressionAnd returns [TypeExpression type = null]
+//@init {List<TypeExpression> exprs = new ArrayList<TypeExpression>();}
+//     :
+//     LBRACK e = simpleTypeExpression{exprs.add(e);} ( SEMI e = 
simpleTypeExpression{exprs.add(e);} )* RBRACK
+//     {type = ExpressionFactory.createAndTypeExpression(exprs);}
+//     ;
+
+quantifierPart returns [RuleElementQuantifier quantifier = null]
+       :
+        STAR q = QUESTION? 
+        {if(q != null) {quantifier = 
TextMarkerScriptFactory.createStarReluctantQuantifier();} 
+               else{quantifier = 
TextMarkerScriptFactory.createStarGreedyQuantifier();}}
+       | PLUS q = QUESTION?
+        {if(q != null) {quantifier = 
TextMarkerScriptFactory.createPlusReluctantQuantifier();}
+        else {quantifier = 
TextMarkerScriptFactory.createPlusGreedyQuantifier();}}
+       | QUESTION q = QUESTION? 
+        {if(q != null) {quantifier = 
TextMarkerScriptFactory.createQuestionReluctantQuantifier();} 
+        else {quantifier = 
TextMarkerScriptFactory.createQuestionGreedyQuantifier();}}
+       | LBRACK min = numberExpression (comma = COMMA (max = 
numberExpression)?)? RBRACK q = QUESTION?
+        {if(q != null) {quantifier = 
TextMarkerScriptFactory.createMinMaxReluctantQuantifier(min,max,comma);} 
+        else {quantifier = 
TextMarkerScriptFactory.createMinMaxGreedyQuantifier(min,max,comma);}}      
+       ;
+
+
+condition returns [AbstractTextMarkerCondition result = null]
+       :
+       (
+       c = conditionAnd
+       | c = conditionContains
+       | c = conditionContextCount
+       | c = conditionCount
+       | c = conditionCurrentCount
+       | c = conditionInList
+       | c = conditionIsInTag
+       | c = conditionLast
+       | c = conditionMofN
+       | c = conditionNear
+       | c = conditionNot
+       | c = conditionOr
+       | c = conditionPartOf
+       | c = conditionPosition
+       | c = conditionRegExp
+       | c = conditionScore
+       | c = conditionTotalCount
+       | c = conditionVote
+       | c = conditionIf
+       | c = conditionFeature
+       | c = conditionParse
+       | c = conditionIs
+       | c = conditionBefore
+       | c = conditionAfter 
+       | c = conditionStartsWith
+       | c = conditionEndsWith
+       | c = conditionPartOfNeq
+       | (c = externalCondition)=> c = externalCondition
+       | c = variableCondition
+       ) {result = c;}
+       ;
+
+
+variableCondition returns [AbstractTextMarkerCondition condition = null]
+       :               
+       
+       id = Identifier
+       {
+               condition = ConditionFactory.createConditionVariable(id);
+       }
+       ;
+
+externalCondition returns [AbstractTextMarkerCondition condition = null]
+       :               
+       
+       id = Identifier LPAREN args = varArgumentList   RPAREN
+       {
+               condition = external.createExternalCondition(id, args);
+       }
+       ;
+       
+conditionAnd returns [AbstractTextMarkerCondition cond = null]
+    :   
+    AND LPAREN conds = conditions RPAREN 
+    {cond = ConditionFactory.createConditionAnd(conds, 
$blockDeclaration::env);}
+    ;
+conditionContains returns [AbstractTextMarkerCondition cond = null]
+    :   
+    CONTAINS LPAREN type = typeExpression (COMMA min = numberExpression COMMA 
max = numberExpression (COMMA percent = booleanExpression)?)? RPAREN
+    {cond = ConditionFactory.createConditionContains(type, min, max, percent, 
$blockDeclaration::env);}
+    ;
+conditionContextCount returns [AbstractTextMarkerCondition cond = null]
+    :   
+    CONTEXTCOUNT LPAREN type = typeExpression (COMMA min = numberExpression 
COMMA max = numberExpression)? 
+    (COMMA var = numberVariable)? RPAREN
+    {cond = ConditionFactory.createConditionContextCount(type, min, max, var, 
$blockDeclaration::env);}
+    ;
+conditionCount returns [AbstractTextMarkerCondition cond = null]
+    :   
+    COUNT LPAREN type = typeExpression (COMMA min = numberExpression COMMA max 
= numberExpression)? 
+    (COMMA var = numberVariable)? RPAREN
+    {cond = ConditionFactory.createConditionCount(type, min, max, var, 
$blockDeclaration::env);}
+    ;
+conditionTotalCount returns [AbstractTextMarkerCondition cond = null]
+    :   
+    TOTALCOUNT LPAREN type = typeExpression (COMMA min = numberExpression 
COMMA max = numberExpression)?
+    (COMMA var = numberVariable)? RPAREN
+    {cond = ConditionFactory.createConditionTotalCount(type, min, max, var, 
$blockDeclaration::env);}
+    ;
+conditionCurrentCount returns [AbstractTextMarkerCondition cond = null]
+    :   
+    CURRENTCOUNT LPAREN type = typeExpression (COMMA min = numberExpression 
COMMA max = numberExpression)? 
+    (COMMA var = numberVariable)? RPAREN
+    {cond = ConditionFactory.createConditionCurrentCount(type, min, max, var, 
$blockDeclaration::env);}
+    ;
+conditionInList returns [AbstractTextMarkerCondition cond = null]
+    :
+    INLIST LPAREN wordList = listExpression (COMMA dist = numberExpression 
(COMMA rel = booleanExpression)?)? RPAREN
+    {cond = ConditionFactory.createConditionInList(wordList, dist, rel, 
$blockDeclaration::env);}
+    | INLIST LPAREN list = innerList (COMMA dist = numberExpression (COMMA rel 
= booleanExpression)?)? RPAREN
+    {cond = ConditionFactory.createConditionInList(list, dist, rel, 
$blockDeclaration::env);}
+    ;
+conditionIsInTag returns [AbstractTextMarkerCondition cond = null]
+@init {
+List<StringExpression> list1 = new ArrayList<StringExpression>();
+List<StringExpression> list2 = new ArrayList<StringExpression>();
+}
+    :
+    ISINTAG LPAREN id = stringExpression (COMMA id1 = stringExpression 
ASSIGN_EQUAL id2 = stringExpression {list1.add(id1);list2.add(id2);})* RPAREN
+    {cond = ConditionFactory.createConditionIsInTag(id, list1, list2, 
$blockDeclaration::env);} 
+    ;
+    
+conditionLast returns [AbstractTextMarkerCondition cond = null]
+    :   
+    LAST LPAREN type = typeExpression RPAREN
+    {cond = ConditionFactory.createConditionLast(type, 
$blockDeclaration::env);}    
+    ;
+    
+    
+conditionMofN returns [AbstractTextMarkerCondition cond = null]
+    :   
+    MOFN LPAREN min = numberExpression COMMA max = numberExpression COMMA 
conds = conditions RPAREN
+    {cond = ConditionFactory.createConditionMOfN(conds, min, max, 
$blockDeclaration::env);} 
+    ;
+
+conditionNear returns [AbstractTextMarkerCondition cond = null]
+    :   
+    NEAR LPAREN type = typeExpression COMMA min = numberExpression COMMA max = 
numberExpression (COMMA direction = booleanExpression (COMMA filtered = 
booleanExpression)?)? RPAREN
+    {cond = ConditionFactory.createConditionNear(type, min, max, direction, 
filtered, $blockDeclaration::env);} 
+    ;
+conditionNot returns [AbstractTextMarkerCondition cond = null]
+    :   
+    ((MINUS c = condition) |  (NOT LPAREN c = condition RPAREN))
+    {cond = ConditionFactory.createConditionNot(c, $blockDeclaration::env);}   
 
+    ;
+conditionOr returns [AbstractTextMarkerCondition cond = null]
+    :   
+    OR LPAREN conds = conditions RPAREN
+    {cond = ConditionFactory.createConditionOr(conds, $blockDeclaration::env);}
+    ;
+conditionPartOf returns [AbstractTextMarkerCondition cond = null]
+    :
+    PARTOF LPAREN type = typeExpression RPAREN
+    {cond = ConditionFactory.createConditionPartOf(type, 
$blockDeclaration::env);}
+    ;
+conditionPartOfNeq returns [AbstractTextMarkerCondition cond = null]
+    :
+    PARTOFNEQ LPAREN type = typeExpression RPAREN
+    {cond = ConditionFactory.createConditionPartOfNeq(type, 
$blockDeclaration::env);}
+    ;
+
+conditionPosition returns [AbstractTextMarkerCondition cond = null]
+    :   
+    POSITION LPAREN type = typeExpression COMMA pos = numberExpression RPAREN
+    {cond = ConditionFactory.createConditionPosition(type, pos, 
$blockDeclaration::env);}
+    ;
+conditionRegExp returns [AbstractTextMarkerCondition cond = null]
+    :
+    REGEXP LPAREN pattern = stringExpression (COMMA caseSensitive = 
booleanExpression)? RPAREN
+    {cond = ConditionFactory.createConditionRegExp(pattern, caseSensitive, 
$blockDeclaration::env);}    
+    ;
+
+conditionScore returns [AbstractTextMarkerCondition cond = null]
+    :
+    SCORE LPAREN min = numberExpression (COMMA max = numberExpression
+    (COMMA var = numberVariable)?)?  RPAREN
+    {cond = ConditionFactory.createConditionScore(min, max, var, 
$blockDeclaration::env);}
+    ;
+
+
+conditionVote returns [AbstractTextMarkerCondition cond = null]
+    :   
+    VOTE LPAREN type1 = typeExpression COMMA type2 = typeExpression RPAREN
+    {cond = ConditionFactory.createConditionVote(type1, type2, 
$blockDeclaration::env);}
+    ;
+    
+conditionIf returns [AbstractTextMarkerCondition cond = null]
+    :   
+    IF LPAREN e = booleanExpression RPAREN
+    {cond = ConditionFactory.createConditionIf(e, $blockDeclaration::env);}
+    ;
+
+conditionFeature returns [AbstractTextMarkerCondition cond = null]
+    :   
+    FEATURE LPAREN se = stringExpression COMMA  v = argument RPAREN
+    {cond = ConditionFactory.createConditionFeature(se, v, 
$blockDeclaration::env);}
+    ;   
+
+conditionParse returns [AbstractTextMarkerCondition cond = null]
+    :
+    PARSE LPAREN {isVariable($blockDeclaration::env,input.LT(1).getText())}? 
id = Identifier RPAREN
+    {cond = ConditionFactory.createConditionParse(id, $blockDeclaration::env);}
+    ;
+
+conditionIs returns [AbstractTextMarkerCondition cond = null]
+    :
+    IS LPAREN type = typeExpression RPAREN
+    {cond = ConditionFactory.createConditionIs(type, $blockDeclaration::env);}
+    ;
+
+conditionBefore returns [AbstractTextMarkerCondition cond = null]
+    :
+    BEFORE LPAREN type = typeExpression RPAREN
+    {cond = ConditionFactory.createConditionBefore(type, 
$blockDeclaration::env);}
+    ;
+
+conditionAfter returns [AbstractTextMarkerCondition cond = null]
+    :
+    AFTER LPAREN type = typeExpression RPAREN
+    {cond = ConditionFactory.createConditionAfter(type, 
$blockDeclaration::env);}
+    ;
+
+conditionStartsWith returns [AbstractTextMarkerCondition cond = null]
+    :
+    STARTSWITH LPAREN type = typeExpression RPAREN
+    {cond = ConditionFactory.createConditionStartsWith(type, 
$blockDeclaration::env);}
+    ;
+
+conditionEndsWith returns [AbstractTextMarkerCondition cond = null]
+    :
+    ENDSWITH LPAREN type = typeExpression RPAREN
+    {cond = ConditionFactory.createConditionEndsWith(type, 
$blockDeclaration::env);}
+    ;
+
+action returns [AbstractTextMarkerAction result = null]
+       :
+       (
+       a = actionColor
+       | a = actionDel
+       | a = actionLog
+       | a = actionMark
+       | a = actionMarkScore
+       | a = actionMarkFast
+       | a = actionMarkLast
+       | a = actionReplace
+       | a = actionFilterMarkup
+       | a = actionFilterType
+       | a = actionRetainMarkup
+       | a = actionRetainType
+       | a = actionCreate
+       | a = actionFill
+       | a = actionCall
+       | a = actionAssign
+       | a = actionFeature
+       | a = actionUnmark
+       | a = actionTransfer
+       | a = actionMarkOnce
+       | a = actionTrie
+       | a = actionGather      
+       | a = actionExec
+       | a = actionMarkTable   
+       | (a = externalAction)=> a = externalAction
+       | a = variableAction
+       ) {result = a;}
+       ;
+
+variableAction returns [AbstractTextMarkerAction action = null]
+       :               
+       
+       id = Identifier
+       {
+               action = ActionFactory.createActionVariable(id);
+       }
+       ;
+
+
+externalAction returns [AbstractTextMarkerAction action = null]
+       :               
+       
+       id = Identifier LPAREN args = varArgumentList   RPAREN
+       {
+               action = external.createExternalAction(id, args);
+       }
+       ;
+
+
+
+actionCreate returns [AbstractTextMarkerAction action = null]
+@init {
+       Map<StringExpression, TextMarkerExpression> map = new 
HashMap<StringExpression, TextMarkerExpression>();
+       List<NumberExpression> indexes = new ArrayList<NumberExpression>();
+}
+    :
+    name = CREATE LPAREN structure = typeExpression 
+   (COMMA 
+    (
+    (index = numberExpression)=>index = numberExpression {indexes.add(index);} 
((COMMA index = numberExpression)=> (COMMA index = numberExpression) 
{indexes.add(index);})* COMMA)?
+    (fname = stringExpression ASSIGN_EQUAL obj1 = argument 
{map.put(fname,obj1);} 
+    (COMMA fname = stringExpression ASSIGN_EQUAL obj1 = argument 
{map.put(fname,obj1);})*)?
+    )? RPAREN
+    {action = ActionFactory.createCreateAction(structure, map, indexes, 
$blockDeclaration::env);}
+    ;
+
+
+actionMarkTable returns [AbstractTextMarkerAction action = null]
+@init {
+       Map<StringExpression, NumberExpression> map = new 
HashMap<StringExpression, NumberExpression>();
+}
+    :
+    name = MARKTABLE LPAREN 
+    structure = typeExpression COMMA 
+    index = numberExpression COMMA
+    table = tableExpression 
+    (COMMA    
+    fname = stringExpression ASSIGN_EQUAL obj1 = numberExpression 
{map.put(fname,obj1);} 
+    (COMMA fname = stringExpression ASSIGN_EQUAL obj1 = numberExpression 
{map.put(fname,obj1);})*
+    )? RPAREN
+    {action = ActionFactory.createMarkTableAction(structure, index, table, 
map, $blockDeclaration::env);}
+    ;
+ 
+actionGather returns [AbstractTextMarkerAction action = null]
+@init {
+       Map<StringExpression, NumberExpression> map = new 
HashMap<StringExpression, NumberExpression>();
+       List<NumberExpression> indexes = new ArrayList<NumberExpression>();
+}
+    :
+    name = GATHER LPAREN structure = typeExpression 
+   (COMMA 
+    ((index = numberExpression)=>index = numberExpression 
{indexes.add(index);} ((COMMA index = numberExpression)=>(COMMA index = 
numberExpression) {indexes.add(index);})* COMMA)?
+    (fname = stringExpression ASSIGN_EQUAL obj1 = numberExpression 
{map.put(fname,obj1);} 
+    (COMMA fname = stringExpression ASSIGN_EQUAL obj1 = numberExpression 
{map.put(fname,obj1);})*)?
+    )? RPAREN
+    {action = ActionFactory.createGatherAction(structure, map, indexes, 
$blockDeclaration::env);}
+    ;  
+
+  
+
+actionFill returns [AbstractTextMarkerAction action = null]
+@init {
+Map<StringExpression, TextMarkerExpression> map = new 
HashMap<StringExpression, TextMarkerExpression>();
+}
+    :
+    FILL LPAREN type = typeExpression (COMMA fname = stringExpression 
ASSIGN_EQUAL 
+    (
+    obj1 = argument{map.put(fname,obj1);} 
+    )
+    )+ RPAREN
+    {action = ActionFactory.createFillAction(type, map, 
$blockDeclaration::env);}
+    ;
+    
+actionColor returns [AbstractTextMarkerAction action = null]
+    :   
+    COLOR LPAREN type = typeExpression COMMA color = stringExpression RPAREN
+    {action = ActionFactory.createColorAction(type, color, 
$blockDeclaration::env);}
+    ;
+
+actionDel returns [AbstractTextMarkerAction action = null]
+    :   
+    DEL
+    {action = ActionFactory.createDelAction($blockDeclaration::env);}
+    ;
+        
+actionLog returns [AbstractTextMarkerAction action = null]
+    :   
+    LOG LPAREN lit = stringExpression (COMMA log = LogLevel)? RPAREN
+    {action = ActionFactory.createLogAction(lit, log, $blockDeclaration::env);}
+    ;
+
+actionMark returns [AbstractTextMarkerAction action = null]
+@init {
+List<NumberExpression> list = new ArrayList<NumberExpression>();
+}
+    :   
+    MARK LPAREN 
+    type = typeExpression
+    (
+        COMMA (index = numberExpression) => index = numberExpression
+        {list.add(index);}
+    )*
+     RPAREN
+    
+    {action = ActionFactory.createMarkAction(null, type, list, 
$blockDeclaration::env);}
+    ;
+
+
+actionMarkScore returns [AbstractTextMarkerAction action = null]
+@init {
+List<NumberExpression> list = new ArrayList<NumberExpression>();
+}
+    :   
+    MARKSCORE LPAREN 
+    score = numberExpression COMMA
+    type = typeExpression
+    (
+        COMMA (index = numberExpression) => index = numberExpression
+        {list.add(index);}
+    )*
+     RPAREN
+    
+    {action = ActionFactory.createMarkAction(score, type, list, 
$blockDeclaration::env);}
+    ;
+
+actionMarkOnce returns [AbstractTextMarkerAction action = null]
+@init {
+List<NumberExpression> list = new ArrayList<NumberExpression>();
+}
+    :   
+    MARKONCE LPAREN ((score = numberExpression) => score = numberExpression 
COMMA)? (type = typeExpression) => type = typeExpression
+    (
+        COMMA (index = numberExpression) => index = numberExpression
+        {list.add(index);}
+    )* RPAREN
+    
+    {action = ActionFactory.createMarkOnceAction(score, type, list, 
$blockDeclaration::env);}
+    ;
+
+actionMarkFast returns [AbstractTextMarkerAction action = null]
+    :   
+    MARKFAST LPAREN type = typeExpression COMMA list = listExpression (COMMA 
ignore = booleanExpression (COMMA ignoreLength = numberExpression)?)? RPAREN
+    {action = ActionFactory.createMarkFastAction(type, list, ignore, 
ignoreLength, $blockDeclaration::env);}
+    ;
+
+actionMarkLast returns [AbstractTextMarkerAction action = null]
+    :   
+    MARKLAST LPAREN type = typeExpression RPAREN
+    {action = ActionFactory.createMarkLastAction(type, 
$blockDeclaration::env);}
+    ;
+
+actionReplace returns [AbstractTextMarkerAction action = null]
+    :   
+    REPLACE LPAREN lit = stringExpression RPAREN
+    {action = ActionFactory.createReplaceAction(lit, $blockDeclaration::env);}
+    ;
+    
+actionRetainMarkup returns [AbstractTextMarkerAction action = null]
+@init {
+List<StringExpression> list = new ArrayList<StringExpression>();
+}
+    :   
+    RETAINMARKUP (LPAREN id = stringExpression {list.add(id);} (COMMA id = 
stringExpression {list.add(id);})* RPAREN)?
+    {action = ActionFactory.createRetainMarkupAction(list, 
$blockDeclaration::env);}
+    ;
+    
+
+actionRetainType returns [AbstractTextMarkerAction action = null]
+@init {
+List<TypeExpression> list = new ArrayList<TypeExpression>();
+}
+    :   
+    RETAINTYPE (LPAREN id = typeExpression {list.add(id);} (COMMA id = 
typeExpression {list.add(id);})* RPAREN)?
+    {action = ActionFactory.createRetainTypeAction(list, 
$blockDeclaration::env);}
+    ;   
+    
+actionFilterMarkup returns [AbstractTextMarkerAction action = null]
+@init {
+List<StringExpression> list = new ArrayList<StringExpression>();
+}
+    :   
+    FILTERMARKUP (LPAREN id = stringExpression {list.add(id);} (COMMA id = 
stringExpression {list.add(id);})* RPAREN)?
+    {action = ActionFactory.createFilterMarkupAction(list, 
$blockDeclaration::env);}
+    ;
+    
+
+actionFilterType returns [AbstractTextMarkerAction action = null]
+@init {
+List<TypeExpression> list = new ArrayList<TypeExpression>();
+}
+    :   
+    FILTERTYPE (LPAREN id = typeExpression {list.add(id);} (COMMA id = 
typeExpression {list.add(id);})* RPAREN)?
+    {action = ActionFactory.createFilterTypeAction(list, 
$blockDeclaration::env);}
+    ;       
+
+actionCall returns [AbstractTextMarkerAction action = null]
+    :
+    CALL LPAREN ns = dottedIdentifier RPAREN
+    {action = ActionFactory.createCallAction(ns, $blockDeclaration::env);}
+    ;
+
+actionExec returns [AbstractTextMarkerAction action = null]
+    :
+    EXEC LPAREN ns = dottedIdentifier RPAREN
+    {action = ActionFactory.createExecAction(ns, $blockDeclaration::env);}
+    ;    
+    
+actionAssign returns [AbstractTextMarkerAction action = null]
+    :
+    name = ASSIGN LPAREN
+    (
+    {isVariableOfType($blockDeclaration::env, input.LT(1).getText(), "TYPE")}? 
+        nv = Identifier COMMA e1 = typeExpression 
+        {action = ActionFactory.createAssignAction(nv, e1, 
$blockDeclaration::env);}
+    |
+    {isVariableOfType($blockDeclaration::env, input.LT(1).getText(), 
"BOOLEAN")}? 
+        nv = Identifier COMMA e2 = booleanExpression 
+        {action = ActionFactory.createAssignAction(nv, e2, 
$blockDeclaration::env);}
+    |
+    {isVariableOfType($blockDeclaration::env, input.LT(1).getText(), 
"STRING")}? 
+        nv = Identifier COMMA e3 = stringExpression 
+        {action = ActionFactory.createAssignAction(nv, e3, 
$blockDeclaration::env);}
+    |
+    {isVariableOfType($blockDeclaration::env, input.LT(1).getText(), "INT")}? 
+        nv = Identifier COMMA e4 = numberExpression 
+        {action = ActionFactory.createAssignAction(nv, e4, 
$blockDeclaration::env);}
+    |
+    {isVariableOfType($blockDeclaration::env, input.LT(1).getText(), 
"DOUBLE")}? 
+        nv = Identifier COMMA e5 = numberExpression 
+        {action = ActionFactory.createAssignAction(nv, e5, 
$blockDeclaration::env);}
+    ) RPAREN
+    ;
+
+actionFeature returns [AbstractTextMarkerAction action = null]
+    :   
+    name = SETFEATURE LPAREN f = stringExpression COMMA v = argument RPAREN
+    {action = ActionFactory.createFeatureAction(f, v, $blockDeclaration::env);}
+    ;
+
+actionUnmark returns [AbstractTextMarkerAction action = null]
+    :
+    name = UNMARK LPAREN f = typeExpression RPAREN
+    {action = ActionFactory.createUnmarkAction(f, $blockDeclaration::env);}
+    ;
+
+actionTransfer returns [AbstractTextMarkerAction action = null]
+    :
+    name = TRANSFER LPAREN f = typeExpression RPAREN
+    {action = ActionFactory.createTransferAction(f, $blockDeclaration::env);}
+    ;
+
+actionTrie returns [AbstractTextMarkerAction action = null]
+@init {
+Map<StringExpression, TypeExpression> map = new HashMap<StringExpression, 
TypeExpression>();
+}
+    :
+    name = TRIE LPAREN
+    key = stringExpression ASSIGN_EQUAL value = 
typeExpression{map.put(key,value);}
+    (COMMA key = stringExpression ASSIGN_EQUAL value = 
typeExpression{map.put(key,value);} )*
+    COMMA list = listExpression 
+    COMMA ignoreCase = booleanExpression 
+    COMMA ignoreLength = numberExpression 
+    COMMA edit = booleanExpression 
+    COMMA distance = numberExpression 
+    COMMA ignoreChar = stringExpression
+    RPAREN
+    //TODO cost parameter
+    {action = ActionFactory.createTrieAction(list, map, ignoreCase, 
ignoreLength, edit, distance, ignoreChar, $blockDeclaration::env);}
+    ;
+
+
+varArgumentList returns [List args = new ArrayList()]
+       :
+       (LPAREN arg = argument {args.add(arg);}(COMMA arg = argument 
{args.add(arg);})* RPAREN)?
+       ;
+
+argument returns [TextMarkerExpression expr = null]
+options {
+       backtrack = true;
+}
+       :
+       a4 = stringExpression {expr = a4;}
+       | a2 = booleanExpression {expr = a2;}
+       | a3 = numberExpression {expr = a3;}
+       | a1 = typeExpression {expr = a1;}
+       
+       //(a2 = booleanExpression)=> a2 = booleanExpression {expr = a2;}
+       //| (a3 = numberExpression)=> a3 = numberExpression {expr = a3;}
+       //| (a4 = stringExpression)=> a4 = stringExpression {expr = a4;}
+       //| (a1 = typeExpression)=> a1 = typeExpression {expr = a1;}
+       ;
+       
+innerList returns [List<String> result = new ArrayList<String>();]
+       :
+       LBRACK id = Identifier {result.add(id.getText());}
+       
+       ('|' id = Identifier {result.add(id.getText());} )* RBRACK
+       |
+       LBRACK id = StringLiteral {result.add(id.getText());}
+       
+       ('|' id = StringLiteral {result.add(id.getText());} )* RBRACK
+       ;       
+
+
+dottedIdentifier returns [String idString = ""]
+       :
+       id = Identifier {idString += id.getText();}
+       (
+               dot = DOT {idString += dot.getText();}
+               idn = Identifier {idString += idn.getText();}
+       )*
+       ;
+
+dottedIdentifier2 returns [String idString = ""]
+       :
+       id = Identifier {idString += id.getText();}
+       (
+               dot = (DOT|'-') {idString += dot.getText();}
+               idn = Identifier {idString += idn.getText();}
+       )*
+       ;
+
+//snooze       
+dottedId returns [Token token = null ]
+@init {CommonToken ct = null;}
+       :
+       id = Identifier {
+               ct = new CommonToken(id);
+               }
+       (
+               dot = DOT {ct.setText(ct.getText() + dot.getText());}
+               id = Identifier {ct.setStopIndex(getBounds(id)[1]);
+                                ct.setText(ct.getText() + id.getText());}
+       )*
+       {token = ct;
+        return token;}
+       ;
+
+annotationType returns [Token ref = null]
+       : 
+       (
+       //{isType($blockDeclaration::env, input.LT(1).getText())}? 
+       token = BasicAnnotationType {ref = token;}
+       |
+       did = dottedId {ref = did;}
+       )
+       ;
+
+listExpression returns [ListExpression expr = null]
+       :
+       id = Identifier
+       {expr = ExpressionFactory.createReferenceListExpression(id);}
+       |
+       path = RessourceLiteral
+       {expr = ExpressionFactory.createLiteralListExpression(path);}
+       ;
+
+
+tableExpression returns [TableExpression expr = null]
+       :
+       id = Identifier
+       {expr = ExpressionFactory.createReferenceTableExpression(id);}
+       |
+       path = RessourceLiteral
+       {expr = ExpressionFactory.createLiteralTableExpression(path);}
+       ;
+
+// not checked
+numberFunction returns [NumberExpression expr = null]
+       :
+       (op=(EXP | LOGN | SIN | COS | TAN) numExprP=numberExpressionInPar)
+       {expr = ExpressionFactory.createComposedNumberExpression(numExprP,op);}
+       //| {root = ExpressionFactory.createNumberFunction(numExprP,op)}
+       | (e = externalNumberFunction)=> e = externalNumberFunction {expr = e;}
+       ;
+
+
+// not checked
+externalNumberFunction returns [NumberExpression expr = null]
+       :
+       //{isVariableOfType($blockDeclaration::env, input.LT(1).getText(), 
"NUMBERFUNCTION")}? 
+       id = Identifier LPAREN
+       args = varArgumentList RPAREN
+       {
+               expr = external.createExternalNumberFunction(id, args);
+       }
+       ;
+
+numberVariable returns [Token ref = null]
+       :
+       {isVariableOfType($blockDeclaration::env,input.LT(1).getText(), 
"INT")}? token1 = Identifier {ref = token1;}
+       |{isVariableOfType($blockDeclaration::env,input.LT(1).getText(), 
"DOUBLE")}? token2 = Identifier {ref = token2;}
+       ;
+
+
+additiveExpression returns [NumberExpression expr = null]
+@init{List<NumberExpression> exprs = new ArrayList<NumberExpression>();
+       List<Token> ops = new ArrayList<Token>();}
+       :   
+       e = multiplicativeExpression{exprs.add(e);} ( op = (PLUS | 
MINUS){ops.add(op);} e = multiplicativeExpression{exprs.add(e);} )*
+       {expr = ExpressionFactory.createComposedNumberExpression(exprs,ops);}
+       ;
+
+multiplicativeExpression returns [NumberExpression expr = null]
+@init{List<NumberExpression> exprs = new ArrayList<NumberExpression>();
+       List<Token> ops = new ArrayList<Token>();}
+       :       
+       (e = simpleNumberExpression{exprs.add(e);} ( op = ( STAR | SLASH | 
PERCENT ){ops.add(op);} e = simpleNumberExpression{exprs.add(e);} )*
+       {expr = ExpressionFactory.createComposedNumberExpression(exprs,ops);}
+       |   e1 = numberFunction {expr = e1;})
+       ;
+
+numberExpression returns [NumberExpression expr = null]
+       :
+       e = additiveExpression {expr = e;}
+       ;
+
+numberExpressionInPar returns [NumberExpression expr = null]
+       :
+       LPAREN  e = additiveExpression RPAREN {expr = e;}
+       ;
+
+simpleNumberExpression returns [NumberExpression expr = null]
+       :       
+       m = MINUS? lit = DecimalLiteral {expr = 
ExpressionFactory.createIntegerExpression(lit,m);} 
+       | m = MINUS? lit = FloatingPointLiteral {expr = 
ExpressionFactory.createDoubleExpression(lit,m);}
+       | m = MINUS? var = numberVariable {expr = 
ExpressionFactory.createReferenceNumberExpression(var,m);}
+       | e = numberExpressionInPar {expr = e;}
+       ;
+       
+stringExpression returns [StringExpression expr = null]
+options {
+       backtrack = true;
+}
+@init {
+List<StringExpression> exprs = new ArrayList<StringExpression>();
+}
+       :
+       e = simpleStringExpression {exprs.add(e);} 
+       (PLUS (e1 = simpleStringExpression {exprs.add(e1);} 
+               | e2 = numberExpressionInPar {exprs.add(e2);}
+               | be = simpleBooleanExpression {exprs.add(be);}
+               | te = typeExpression {exprs.add(te);}
+               ))*
+       {expr = ExpressionFactory.createComposedStringExpression(exprs);}
+       |(e = stringFunction)=> e = stringFunction{expr = e;} 
+       ;
+
+// not checked
+stringFunction returns [StringExpression expr = null]
+       :
+       (e = externalStringFunction)=> e = externalStringFunction {expr = e;}
+       ;
+
+// not checked
+externalStringFunction returns [StringExpression expr = null]
+       :
+       //{isVariableOfType($blockDeclaration::env, input.LT(1).getText(), 
"STRINGFUNCTION")}? 
+       id = Identifier LPAREN
+       args = varArgumentList  RPAREN
+       {
+               expr = external.createExternalStringFunction(id, args);
+       }
+       ;
+
+simpleStringExpression returns [StringExpression expr = null]
+       : 
+       lit = StringLiteral {expr = 
ExpressionFactory.createSimpleStringExpression(lit);} 
+       | {isVariableOfType($blockDeclaration::env,input.LT(1).getText(), 
"STRING")}? id = Identifier {expr = 
ExpressionFactory.createReferenceStringExpression(id);} 
+       ;
+
+
+booleanExpression returns [BooleanExpression expr = null]
+       :
+       (e = composedBooleanExpression)=> e = composedBooleanExpression {expr = 
e;}
+       |sbE =  simpleBooleanExpression {expr = sbE;}
+       ;
+
+simpleBooleanExpression returns [BooleanExpression expr = null]
+       :
+        e = literalBooleanExpression {expr = e;}
+       | {isVariableOfType($blockDeclaration::env,input.LT(1).getText(), 
"BOOLEAN")}? 
+       id = Identifier {expr = 
ExpressionFactory.createReferenceBooleanExpression(id);} 
+       ;
+
+// not checked
+composedBooleanExpression returns [BooleanExpression expr = null]
+
+       :
+       (e2 = booleanCompare)=> e2 = booleanCompare {expr = e2;}
+       | (bte = booleanTypeExpression)=> bte = booleanTypeExpression{expr = 
bte;}
+       | (bne = booleanNumberExpression)=> bne = booleanNumberExpression{expr 
= bne;}
+       | e1 = booleanFunction {expr = e1;}
+       ;
+
+// not checked
+booleanFunction returns [BooleanExpression expr = null]
+
+       :
+       (op = XOR LPAREN e1 = booleanExpression COMMA e2 = booleanExpression 
RPAREN)
+       {expr = ExpressionFactory.createBooleanFunction(op,e1,e2);}
+       | (e = externalBooleanFunction)=> e = externalBooleanFunction {expr = 
e;}
+       ;
+
+// not checked
+externalBooleanFunction returns [BooleanExpression expr = null]
+       :
+       //{isVariableOfType($blockDeclaration::env, input.LT(1).getText(), 
"BOOLEANFUNCTION")}? 
+       id = Identifier LPAREN
+       args = varArgumentList RPAREN
+       {
+               expr = external.createExternalBooleanFunction(id, args);
+       }
+       ;
+
+// not checked
+booleanCompare returns [BooleanExpression expr = null]
+       :
+       (e1 = simpleBooleanExpression op = (EQUAL | NOTEQUAL) e2 = 
booleanExpression)
+       {expr = ExpressionFactory.createBooleanFunction(op,e1,e2);}
+       ;
+
+
+literalBooleanExpression returns  [BooleanExpression expr = null]
+       :
+       v = TRUE {expr = ExpressionFactory.createSimpleBooleanExpression(v);} 
+       | v = FALSE {expr = ExpressionFactory.createSimpleBooleanExpression(v);}
+       ;
+
+
+
+booleanTypeExpression  returns  [BooleanExpression expr = null]
+       :
+       e1 = typeExpression
+       op = (EQUAL | NOTEQUAL)
+       e2 = typeExpression
+       {expr = ExpressionFactory.createBooleanTypeExpression(e1,op,e2);}
+       ;
+       
+booleanNumberExpression  returns  [BooleanExpression expr = null]
+       :
+       LPAREN
+       e1 = numberExpression//{exprs.add(e);} 
+       op = (LESS | GREATER | GREATEREQUAL | LESSEQUAL | EQUAL | 
NOTEQUAL)//{ops.add(op);} 
+       e2 = numberExpression//{exprs.add(e);}
+       RPAREN
+       {expr = ExpressionFactory.createBooleanNumberExpression(e1,op,e2);}
+       ;
+
+// Lexer
+
+
+TRIE
+       :       'TRIE'
+       ;
+
+CONTAINS
+       :       'CONTAINS'
+       ;
+
+DECLARE
+       :       'DECLARE'
+       ;
+
+LIST
+       :       'LIST'
+       ;
+
+TABLE
+       :       'TABLE'
+       ;
+
+AND
+       :       'AND'
+       ;
+
+CONTEXTCOUNT
+       :       'CONTEXTCOUNT'
+       ;
+
+COUNT
+       :       'COUNT'
+       ;
+
+TOTALCOUNT
+       :       'TOTALCOUNT'
+       ;
+
+CURRENTCOUNT
+       :       'CURRENTCOUNT'
+       ;
+
+INLIST
+       :       'INLIST'
+       ;
+
+ISINTAG
+       :       'ISINTAG'
+       ;
+
+LAST
+       :       'LAST'
+       ;
+
+MOFN
+       :       'MOFN'
+       ;
+
+NEAR
+       :       'NEAR'
+       ;
+
+OR
+       :       'OR'
+       ;
+
+PARTOF
+       :       'PARTOF'
+       ;
+       
+PARTOFNEQ
+       :       'PARTOFNEQ'
+       ;
+
+POSITION
+       :       'POSITION'
+       ;
+
+REGEXP
+       :       'REGEXP'
+       ;
+
+SCORE
+       :       'SCORE'
+       ;
+
+VOTE
+       :       'VOTE'
+       ;
+
+IF
+       :       'IF'
+       ;
+
+FEATURE
+       :       'FEATURE'
+       ;
+
+PARSE
+       :       'PARSE'
+       ;
+
+CREATE
+       :       'CREATE'
+       ;
+
+GATHER
+       :       'GATHER'
+       ;
+
+FILL
+       :       'FILL'
+       ;
+
+ATTRIBUTE
+       :       'ATTRIBUTE'
+       ;
+
+COLOR
+       :       'COLOR'
+       ;
+
+DEL
+       :       'DEL'
+       ;
+
+LOG
+       :       'LOG'
+       ;
+
+MARK
+       :       'MARK'
+       ;
+
+MARKSCORE
+       :       'MARKSCORE'
+       ;
+
+MARKONCE
+       :       'MARKONCE'
+       ;
+
+MARKFAST
+       :       'MARKFAST'
+       ;
+       
+MARKTABLE
+       :       'MARKTABLE'
+       ;
+       
+MARKLAST
+       :       'MARKLAST'
+       ;
+
+REPLACE
+       :       'REPLACE'
+       ;
+
+RETAINMARKUP
+       :       'RETAINMARKUP'
+       ;
+
+RETAINTYPE
+       :       'RETAINTYPE'
+       ;
+
+FILTERMARKUP
+       :       'FILTERMARKUP'
+       ;
+
+FILTERTYPE
+       :       'FILTERTYPE'
+       ;
+
+CALL
+       :       'CALL'
+       ;
+
+
+EXEC
+       :       'EXEC'
+       ;
+
+ASSIGN
+       :       'ASSIGN'
+       ;
+
+SETFEATURE
+       :       'SETFEATURE'
+       ;
+
+UNMARK
+       :       'UNMARK'
+       ;
+
+
+TRANSFER
+       :       'TRANSFER'
+       ;
+
+BEFORE
+       :       'BEFORE'
+       ;
+
+AFTER
+       :       'AFTER'
+       ;
+
+IS     
+       :       'IS'     
+       ;
+
+
+STARTSWITH     
+       :       'STARTSWITH'     
+       ;
+
+ENDSWITH       
+       :       'ENDSWITH'       
+       ;
+
+NOT
+       :       'NOT'
+       ;
+
+THEN 
+       :       '->'
+       ;
+
+BasicAnnotationType 
+       : 'COLON'| 'SW' | 'MARKUP' | 'PERIOD' | 'CW'| 'NUM' | 'QUESTION' | 
'SPECIAL' | 'CAP' | 'COMMA' | 'EXCLAMATION' | 'SEMICOLON' | 'NBSP'| 'AMP' |
+       '_' | 'SENTENCEEND' | 'W' | 'PM' | 'ANY' | 'ALL' | 'SPACE' | 'BREAK' 
+       ;
+       
+LogLevel:
+       'finest' | 'finer' | 'fine' | 'config' | 'info' | 'warning' | 'severe'
+       ;       
+
+OldColor 
+       : 'black' | 'maroon' | 'green' | 'olive' | 'navy' | 'purple' | 'teal' | 
'gray' | 'silver' | 'red' | 'lime' | 'yellow' | 'blue' | 'fuchsia' | 'aqua'
+       ;
+
+PackageString   :      'PACKAGE';
+ScriptString   :       'SCRIPT';
+EngineString   :       'ENGINE';
+BlockString    :       'BLOCK';
+TypeString     :       'TYPE';
+IntString      :       'INT';
+DoubleString   :       'DOUBLE';
+StringString   :       'STRING';
+BooleanString  :       'BOOLEAN';
+TypeSystemString:      'TYPESYSTEM';   
+SymbolString   :       'SYMBOL';
+CONDITION      :       'CONDITION';    
+ACTION         :       'ACTION';
+
+EXP    :       'EXP';
+LOGN   :       'LOGN';
+SIN    :       'SIN';
+COS    :       'COS';
+TAN    :       'TAN';
+XOR    :       'XOR';
+TRUE   :       'true';
+FALSE  :       'false';
+
+HexLiteral : '0' ('x'|'X') HexDigit+ IntegerTypeSuffix? ;
+
+DecimalLiteral : ('0' | '1'..'9' '0'..'9'*) IntegerTypeSuffix? ;
+
+OctalLiteral : '0' ('0'..'7')+ IntegerTypeSuffix? ;
+
+fragment
+HexDigit : ('0'..'9'|'a'..'f'|'A'..'F') ;
+
+fragment
+IntegerTypeSuffix : ('l'|'L') ;
+
+FloatingPointLiteral
+    :   ('0'..'9')+ '.' ('0'..'9')* Exponent? FloatTypeSuffix?
+    |   '.' ('0'..'9')+ Exponent? FloatTypeSuffix?
+    //|   ('0'..'9')+ Exponent FloatTypeSuffix?
+    //|   ('0'..'9')+ Exponent? FloatTypeSuffix
+       ;
+       
+fragment
+Exponent : ('e'|'E') ('+'|'-')? ('0'..'9')+ ;
+
+fragment
+FloatTypeSuffix : ('f'|'F'|'d'|'D') ;
+
+CharacterLiteral
+    :   '\'' ( EscapeSequence | ~('\''|'\\') ) '\''
+    ;
+
+StringLiteral
+    :  '"' ( EscapeSequence | ~('\\'|'"') )* '"'
+    ;
+
+RessourceLiteral
+    :  '\'' ( EscapeSequence | ~('\\'|'\'') )* '\''
+    ;
+
+fragment
+EscapeSequence
+    :   '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
+    |   UnicodeEscape
+    |   OctalEscape
+    ;
+
+fragment
+OctalEscape
+    :   '\\' ('0'..'3') ('0'..'7') ('0'..'7')
+    |   '\\' ('0'..'7') ('0'..'7')
+    |   '\\' ('0'..'7')
+    ;
+
+fragment
+UnicodeEscape
+    :   '\\' 'u' HexDigit HexDigit HexDigit HexDigit
+    ;
+
+       
+Identifier 
+    :   Letter (Letter|JavaIDDigit)*
+    ;
+
+
+fragment
+Letter
+    :  '\u0024' |
+       '\u0041'..'\u005a' |
+       '\u005f' |
+       '\u0061'..'\u007a' |
+       '\u00c0'..'\u00d6' |
+       '\u00d8'..'\u00f6' |
+       '\u00f8'..'\u00ff' |
+       '\u0100'..'\u1fff' |
+       '\u3040'..'\u318f' |
+       '\u3300'..'\u337f' |
+       '\u3400'..'\u3d2d' |
+       '\u4e00'..'\u9fff' |
+       '\uf900'..'\ufaff'
+    ;
+
+fragment
+JavaIDDigit
+    :  '\u0030'..'\u0039' |
+       '\u0660'..'\u0669' |
+       '\u06f0'..'\u06f9' |
+       '\u0966'..'\u096f' |
+       '\u09e6'..'\u09ef' |
+       '\u0a66'..'\u0a6f' |
+       '\u0ae6'..'\u0aef' |
+       '\u0b66'..'\u0b6f' |
+       '\u0be7'..'\u0bef' |
+       '\u0c66'..'\u0c6f' |
+       '\u0ce6'..'\u0cef' |
+       '\u0d66'..'\u0d6f' |
+       '\u0e50'..'\u0e59' |
+       '\u0ed0'..'\u0ed9' |
+       '\u1040'..'\u1049'
+   ;
+
+
+
+LPAREN : '(' {implicitLineJoiningLevel++;} ;
+
+RPAREN : ')' {implicitLineJoiningLevel--;} ;
+
+LBRACK : '[' {implicitLineJoiningLevel++;} ;
+
+RBRACK : ']' {implicitLineJoiningLevel--;} ;
+
+LCURLY : '{' {implicitLineJoiningLevel++;} ;
+
+RCURLY : '}' {implicitLineJoiningLevel--;} ;
+
+CIRCUMFLEX     : '^' ;
+
+AT : '@' ;
+
+DOT : '.' ;
+
+COLON  : ':' ;
+
+COMMA  : ',' ;
+
+SEMI   : ';' ;
+
+PLUS   : '+' ;
+
+MINUS  : '-' ;
+
+STAR   : '*' ;
+
+SLASH  : '/' ;
+
+VBAR   : '|' ;
+
+AMPER  : '&' ;
+
+LESS   : '<' ;
+
+GREATER        : '>' ;
+
+ASSIGN_EQUAL   : '=' ;
+
+PERCENT        : '%' ;
+
+QUESTION       : '?' ;
+
+EQUAL  : '==' ;
+
+NOTEQUAL       : '!=' ;
+
+ALT_NOTEQUAL: '<>' ;
+
+LESSEQUAL      : '<=' ;
+
+
+GREATEREQUAL   : '>=' ;
+
+WS  :  (' '|'\r'|'\t'|'\u000C'|'\n') {$channel=HIDDEN;}
+    ;
+
+
+
+
+
+
+
+COMMENT
+    :   '/*'{if (input.LA(1)=='*') $type=DocComment; else $channel=HIDDEN;} ( 
options {greedy=false;} : . )* '*/' 
+    ;
+
+LINE_COMMENT
+    : '//' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;}
+    ;
+
+
+
+    
+
+
+

Propchange: 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/parser/TextMarker.g
------------------------------------------------------------------------------
    svn:executable = *

Added: 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/parser/TextMarker.tokens
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/parser/TextMarker.tokens?rev=1157040&view=auto
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/parser/TextMarker.tokens
 (added)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/parser/TextMarker.tokens
 Fri Aug 12 10:44:04 2011
@@ -0,0 +1,133 @@
+STAR=31
+FloatTypeSuffix=119
+OctalLiteral=117
+FILTERMARKUP=80
+LOG=70
+CONTAINS=37
+GREATEREQUAL=109
+MARKFAST=75
+CONDITION=19
+COUNT=39
+LOGN=94
+NOT=48
+ACTION=22
+Identifier=10
+NOTEQUAL=104
+VBAR=129
+ENDSWITH=63
+RPAREN=21
+CREATE=64
+GREATER=108
+SIN=95
+EXP=93
+CURRENTCOUNT=41
+COS=96
+TAN=97
+LESS=107
+REGEXP=53
+PARTOF=50
+UNMARK=86
+LAST=44
+COMMENT=133
+RBRACK=35
+NEAR=46
+LINE_COMMENT=134
+IntegerTypeSuffix=115
+MARKSCORE=73
+TRANSFER=87
+LCURLY=28
+FILTERTYPE=81
+TRIE=88
+LIST=17
+RETAINMARKUP=78
+EngineString=25
+ScriptString=24
+MARKONCE=74
+WS=132
+FloatingPointLiteral=101
+OR=49
+JavaIDDigit=125
+CALL=82
+Annotation=5
+FALSE=106
+LESSEQUAL=110
+RessourceLiteral=92
+VOTE=55
+Letter=124
+EscapeSequence=120
+BasicAnnotationType=91
+LBRACK=34
+CharacterLiteral=121
+DEL=69
+ATTRIBUTE=111
+TypeString=16
+TABLE=18
+Exponent=118
+ASSIGN_EQUAL=12
+RETAINTYPE=79
+AND=36
+TypeSystemString=23
+BlockString=27
+IntString=9
+HexDigit=114
+COLOR=68
+LPAREN=20
+POSITION=52
+IF=56
+AT=127
+LogLevel=71
+SLASH=98
+THEN=30
+FILL=67
+COMMA=11
+IS=59
+AMPER=130
+REPLACE=77
+EQUAL=103
+GATHER=66
+INLIST=42
+PLUS=33
+BooleanString=15
+DOT=90
+ListIdentifier=6
+PARTOFNEQ=51
+MARKTABLE=65
+HexLiteral=116
+XOR=102
+PERCENT=99
+MARK=72
+PackageString=7
+PARSE=58
+OldColor=112
+MARKLAST=76
+CONTEXTCOUNT=38
+BEFORE=60
+EXEC=83
+MINUS=47
+AFTER=61
+DecimalLiteral=100
+TRUE=105
+SEMI=8
+FEATURE=57
+SymbolString=113
+COLON=128
+StringString=14
+StringLiteral=89
+SCORE=54
+QUESTION=32
+UnicodeEscape=122
+RCURLY=29
+STARTSWITH=62
+ASSIGN=84
+TOTALCOUNT=40
+DECLARE=26
+ISINTAG=43
+DocComment=4
+MOFN=45
+OctalEscape=123
+SETFEATURE=85
+DoubleString=13
+CIRCUMFLEX=126
+ALT_NOTEQUAL=131
+'|'=129
+'-'=47

Propchange: 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/parser/TextMarker.tokens
------------------------------------------------------------------------------
    svn:executable = *


Reply via email to