You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by sk...@apache.org on 2013/11/29 15:43:43 UTC

[2/3] [OLINGO-63] Change LEXER grammer to work with modes

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/5e10653b/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/producer/core/testutil/ParserValidator.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/producer/core/testutil/ParserValidator.java b/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/producer/core/testutil/ParserValidator.java
index 2938b43..7f58912 100644
--- a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/producer/core/testutil/ParserValidator.java
+++ b/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/producer/core/testutil/ParserValidator.java
@@ -38,21 +38,25 @@ import org.antlr.v4.runtime.Recognizer;
 import org.antlr.v4.runtime.atn.ATNConfigSet;
 import org.antlr.v4.runtime.atn.PredictionMode;
 import org.antlr.v4.runtime.dfa.DFA;
+import org.antlr.v4.runtime.misc.Interval;
 import org.apache.olingo.producer.core.uri.antlr.UriLexer;
-import org.apache.olingo.producer.core.uri.antlr.UriParser;
-import org.apache.olingo.producer.core.uri.antlr.UriParser.OdataRelativeUriEOFContext;
-import org.apache.olingo.producer.core.uri.antlr.UriParser.TestContext;
+import org.apache.olingo.producer.core.uri.antlr.UriParserParser;
+import org.apache.olingo.producer.core.uri.antlr.UriParserParser.OdataRelativeUriEOFContext;
+import org.apache.olingo.producer.core.uri.antlr.UriParserParser.TestContext;
 
 public class ParserValidator {
   private List<Exception> exceptions = new ArrayList<Exception>();
   private ParserRuleContext root;
 
   private String input = null;
-  private int exceptionOnStage = -1;
+  //private int exceptionOnStage = -1;
   private Exception curException = null;
-  private Exception curWeakException = null;
+  //private Exception curWeakException = null;
   private boolean allowFullContext;
   private boolean allowContextSensitifity;
+  private boolean allowAmbiguity;
+  private int logLevel = 0;
+  private int lexerLog;
 
   public ParserValidator run(String uri) {
     return run(uri, false);
@@ -64,9 +68,24 @@ public class ParserValidator {
 
   public ParserValidator run(String uri, boolean searchMode) {
     input = uri;
+    if (lexerLog> 0) {
+      (new TokenValidator()).log(lexerLog).run(input);
+      
+    }
     root = parseInput(uri, searchMode);
+    
+    
+
+    if (logLevel > 0) {
+
+      System.out.println(ParseTreeSerializer.getTreeAsText(root, new UriParserParser(null).getRuleNames()));
+
+    }
+
+    // reset for nest test
     allowFullContext = false;
     allowContextSensitifity = false;
+    allowAmbiguity = false;
 
     exFirst();
     return this;
@@ -75,13 +94,27 @@ public class ParserValidator {
   public ParserValidator runTest(String uri, boolean searchMode) {
     input = uri;
     root = parseInputTest(uri, searchMode);
+
+    if (logLevel > 0) {
+
+      System.out.println(ParseTreeSerializer.getTreeAsText(root, new UriParserParser(null).getRuleNames()));
+
+    }
+
+    // reset for nest test
     allowFullContext = false;
     allowContextSensitifity = false;
+    allowAmbiguity = false;
 
     exFirst();
     return this;
   }
 
+  public ParserValidator log(int logLevel) {
+    this.logLevel = logLevel;
+    return this;
+  }
+
   public ParserValidator aFC() {
     allowFullContext = true;
     return this;
@@ -92,11 +125,16 @@ public class ParserValidator {
     return this;
   }
 
+  public ParserValidator aAM() {
+    allowAmbiguity = true;
+    return this;
+  }
+
   public ParserValidator isText(String expected) {
     assertEquals(null, curException);
     assertEquals(0, exceptions.size());
 
-    String text = ParseTreeSerializer.getTreeAsText(root, new UriParser(null).getRuleNames());
+    String text = ParseTreeSerializer.getTreeAsText(root, new UriParserParser(null).getRuleNames());
     assertEquals(expected, text);
     return this;
   }
@@ -107,7 +145,7 @@ public class ParserValidator {
   }
 
   private OdataRelativeUriEOFContext parseInput(final String input, boolean searchMode) {
-    UriParser parser = null;
+    UriParserParser parser = null;
     OdataRelativeUriEOFContext ret = null;
 
     // Use 2 stage approach to improve performance
@@ -124,7 +162,7 @@ public class ParserValidator {
       ret = parser.odataRelativeUriEOF();
     } catch (Exception ex) {
       curException = ex;
-      exceptionOnStage = 1;
+      //exceptionOnStage = 1;
       // stage= 2
       try {
         curException = null;
@@ -135,7 +173,7 @@ public class ParserValidator {
         ret = parser.odataRelativeUriEOF();
       } catch (Exception ex1) {
         curException = ex1;
-        exceptionOnStage = 2;
+        //exceptionOnStage = 2;
       }
     }
 
@@ -143,7 +181,7 @@ public class ParserValidator {
   }
 
   private TestContext parseInputTest(final String input, boolean searchMode) {
-    UriParser parser = null;
+    UriParserParser parser = null;
     TestContext ret = null;
 
     // Use 2 stage approach to improve performance
@@ -160,7 +198,7 @@ public class ParserValidator {
       ret = parser.test();
     } catch (Exception ex) {
       curException = ex;
-      exceptionOnStage = 1;
+      //exceptionOnStage = 1;
       // stage= 2
       try {
         curException = null;
@@ -171,25 +209,28 @@ public class ParserValidator {
         ret = parser.test();
       } catch (Exception ex1) {
         curException = ex1;
-        exceptionOnStage = 2;
+        //exceptionOnStage = 2;
       }
     }
 
     return ret;
   }
 
-  private UriParser getNewParser(final String input, boolean searchMode) {
+  private UriParserParser getNewParser(final String input, boolean searchMode) {
     ANTLRInputStream inputStream = new ANTLRInputStream(input);
 
     // UriLexer lexer = new UriLexer(inputStream);
     UriLexer lexer = new UriLexer(inputStream);
-    lexer.setInSearch(searchMode);
+    //lexer.setInSearch(searchMode);
     // lexer.removeErrorListeners();
     lexer.addErrorListener(new ErrorCollector(this));
     CommonTokenStream tokens = new CommonTokenStream(lexer);
 
-    UriParser parser = new UriParser(tokens);
-    parser.addErrorListener(new TraceErrorHandler());
+    UriParserParser parser = new UriParserParser(tokens);
+    if ((lexerLog >0 ) || (logLevel > 0)) {
+      parser.addParseListener(new TokenWriter());
+    }
+    parser.addErrorListener(new TraceErrorHandler<Object>());
     parser.addErrorListener(new ErrorCollector(this));
 
     return parser;
@@ -202,32 +243,10 @@ public class ParserValidator {
       this.tokenValidator = tokenValidator;
     }
 
-    public void trace(final Recognizer<?, ?> recognizer, final Object offendingSymbol,
-        final int line, final int charPositionInLine, final String msg, final RecognitionException e) {
-      System.err.println("-");
-      // check also http://stackoverflow.com/questions/14747952/ll-exact-ambig-detection-interpetation
-      List<String> stack = ((Parser) recognizer).getRuleInvocationStack();
-      Collections.reverse(stack);
-      System.err.println("rule stack: " + stack);
-      if (e != null && e.getOffendingToken() != null) {
-
-        // String lexerTokenName =TestSuiteLexer.tokenNames[e.getOffendingToken().getType()];
-        String lexerTokenName = "";
-        try {
-          lexerTokenName = UriLexer.tokenNames[e.getOffendingToken().getType()];
-        } catch (ArrayIndexOutOfBoundsException es) {
-          lexerTokenName = "token error";
-        }
-        System.err.println("line " + line + ":" + charPositionInLine + " at " +
-            offendingSymbol + "/" + lexerTokenName + ": " + msg);
-      } else {
-        System.err.println("line " + line + ":" + charPositionInLine + " at " + offendingSymbol + ": " + msg);
-      }
-    }
-
     @Override
     public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine,
         String msg, RecognitionException e) {
+
       tokenValidator.exceptions.add(e);
       trace(recognizer, offendingSymbol, line, charPositionInLine, msg, e);
 
@@ -237,10 +256,19 @@ public class ParserValidator {
     @Override
     public void reportAmbiguity(Parser recognizer, DFA dfa, int startIndex, int stopIndex, boolean exact,
         BitSet ambigAlts, ATNConfigSet configs) {
-      printStack(recognizer);
-
-      fail("reportAmbiguity");
-
+      
+
+      if (!tokenValidator.allowAmbiguity) {
+        System.out.println("reportAmbiguity " +
+            ambigAlts + ":" + configs +
+            ", input=" + recognizer.getTokenStream().getText(Interval.of(startIndex, stopIndex)));
+            printStack(recognizer);
+        fail("reportAmbiguity");
+      } else {
+        System.out.println("allowed Ambiguity " +
+            ambigAlts + ":" + configs +
+            ", input=" + recognizer.getTokenStream().getText(Interval.of(startIndex, stopIndex)));
+      }
     }
 
     @Override
@@ -252,22 +280,50 @@ public class ParserValidator {
       if (!tokenValidator.allowFullContext) {
         printStack(recognizer);
         fail("reportAttemptingFullContext");
+      } else {
+        System.out.println("allowed AttemptingFullContext");
       }
     }
 
-    private void printStack(Parser recognizer) {
-      List<String> stack = ((Parser) recognizer).getRuleInvocationStack();
-      Collections.reverse(stack);
-
-      System.err.println("rule stack: " + stack);
-    }
-
     @Override
     public void reportContextSensitivity(Parser recognizer, DFA dfa, int startIndex, int stopIndex, int prediction,
         ATNConfigSet configs) {
       if (!tokenValidator.allowContextSensitifity) {
         printStack(recognizer);
         fail("reportContextSensitivity");
+      }  else {
+        System.out.println("allowed ContextSensitivity");
+
+      }
+    }
+
+    private void printStack(Parser recognizer) {
+      List<String> stack = ((Parser) recognizer).getRuleInvocationStack();
+      Collections.reverse(stack);
+
+      System.out.println("rule stack: " + stack);
+    }
+
+    public void trace(final Recognizer<?, ?> recognizer, final Object offendingSymbol,
+        final int line, final int charPositionInLine, final String msg, final RecognitionException e) {
+      System.err.println("-");
+      // check also http://stackoverflow.com/questions/14747952/ll-exact-ambig-detection-interpetation
+      List<String> stack = ((Parser) recognizer).getRuleInvocationStack();
+      Collections.reverse(stack);
+      System.err.println("rule stack: " + stack);
+      if (e != null && e.getOffendingToken() != null) {
+
+        // String lexerTokenName =TestSuiteLexer.tokenNames[e.getOffendingToken().getType()];
+        String lexerTokenName = "";
+        try {
+          lexerTokenName = UriLexer.tokenNames[e.getOffendingToken().getType()];
+        } catch (ArrayIndexOutOfBoundsException es) {
+          lexerTokenName = "token error";
+        }
+        System.err.println("line " + line + ":" + charPositionInLine + " at " +
+            offendingSymbol + "/" + lexerTokenName + ": " + msg);
+      } else {
+        System.err.println("line " + line + ":" + charPositionInLine + " at " + offendingSymbol + ": " + msg);
       }
     }
 
@@ -275,26 +331,32 @@ public class ParserValidator {
 
   public ParserValidator exFirst() {
     try {
-      curWeakException = exceptions.get(0);
+      //curWeakException = exceptions.get(0);
     } catch (IndexOutOfBoundsException ex) {
-      curWeakException = null;
+      //curWeakException = null;
     }
     return this;
 
   }
 
   public ParserValidator exLast() {
-    curWeakException = exceptions.get(exceptions.size() - 1);
+    //curWeakException = exceptions.get(exceptions.size() - 1);
     return this;
   }
 
   public ParserValidator exAt(int index) {
     try {
-      curWeakException = exceptions.get(index);
+      //curWeakException = exceptions.get(index);
     } catch (IndexOutOfBoundsException ex) {
-      curWeakException = null;
+      //curWeakException = null;
     }
     return this;
   }
 
+  public ParserValidator lexerlog(int i) {
+    this.lexerLog = i;
+    return this;
+    
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/5e10653b/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/producer/core/testutil/TokenValidator.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/producer/core/testutil/TokenValidator.java b/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/producer/core/testutil/TokenValidator.java
index 30e093f..7070651 100644
--- a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/producer/core/testutil/TokenValidator.java
+++ b/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/producer/core/testutil/TokenValidator.java
@@ -27,6 +27,7 @@ import java.util.List;
 
 import org.antlr.v4.runtime.ANTLRErrorListener;
 import org.antlr.v4.runtime.ANTLRInputStream;
+import org.antlr.v4.runtime.CharStream;
 import org.antlr.v4.runtime.Parser;
 import org.antlr.v4.runtime.RecognitionException;
 import org.antlr.v4.runtime.Recognizer;
@@ -41,16 +42,14 @@ public class TokenValidator {
   private Token curToken = null;
   private Exception curException = null;
   private String input = null;
-  int logLevel = 0;
+  private int logLevel = 0;
 
-  public TokenValidator run(String uri) {
-    return run(uri, false);
-  }
+  private int mode;
 
-  public TokenValidator run(String uri, boolean searchMode) {
+  public TokenValidator run(String uri) {
     input = uri;
     exceptions.clear();
-    tokens = parseInput(uri, searchMode);
+    tokens = parseInput(uri);
     if (logLevel > 0) {
       showTokens();
     }
@@ -92,6 +91,26 @@ public class TokenValidator {
     return this;
   }
 
+  public TokenValidator isAllText(String expected) {
+    String tmp = "";
+
+    for (Token curToken : tokens) {
+      tmp += curToken.getText();
+    }
+    assertEquals(expected, tmp);
+    return this;
+  }
+
+  public TokenValidator isAllInput() {
+    String tmp = "";
+
+    for (Token curToken : tokens) {
+      tmp += curToken.getText();
+    }
+    assertEquals(input, tmp);
+    return this;
+  }
+
   public TokenValidator isInput() {
     assertEquals(input, curToken.getText());
     return this;
@@ -108,11 +127,11 @@ public class TokenValidator {
     return this;
   }
 
-  private List<? extends Token> parseInput(final String input, boolean searchMode) {
+  private List<? extends Token> parseInput(final String input) {
     ANTLRInputStream inputStream = new ANTLRInputStream(input);
 
-    UriLexer lexer = new UriLexer(inputStream);
-    lexer.setInSearch(searchMode);
+    UriLexer lexer = new TestUriLexer(this,inputStream, mode);
+    // lexer.setInSearch(searchMode);
     // lexer.removeErrorListeners();
     lexer.addErrorListener(new ErrorCollector(this));
     return lexer.getAllTokens();
@@ -165,6 +184,37 @@ public class TokenValidator {
     return this;
   }
 
+  
+  private static class TestUriLexer extends UriLexer {
+    private TokenValidator validator;
+
+    public TestUriLexer(TokenValidator validator, CharStream input, int mode) {
+      super(input);
+      super.mode(mode);
+      this.validator = validator;
+    }
+
+    @Override
+    public void pushMode(int m) {
+      if (validator.logLevel > 0) {
+        System.out.println("OnMode" + ": " + UriLexer.modeNames[m]);
+      }
+      super.pushMode(m);
+      
+    }
+
+    @Override
+    public int popMode() {
+      int m =  super.popMode();
+      if (validator.logLevel > 0) {
+        System.out.println("OnMode" + ": " + UriLexer.modeNames[m]);
+      }
+      
+      return m;
+    }
+
+  }
+
   private static class ErrorCollector implements ANTLRErrorListener {
     TokenValidator tokenValidator;
 
@@ -198,4 +248,8 @@ public class TokenValidator {
 
   }
 
+  public void globalMode(int mode) {
+    this.mode = mode;
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/5e10653b/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/producer/core/testutil/TokenWriter.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/producer/core/testutil/TokenWriter.java b/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/producer/core/testutil/TokenWriter.java
new file mode 100644
index 0000000..cbd095a
--- /dev/null
+++ b/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/producer/core/testutil/TokenWriter.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * 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.olingo.producer.core.testutil;
+
+import org.antlr.v4.runtime.ParserRuleContext;
+import org.antlr.v4.runtime.tree.ErrorNode;
+import org.antlr.v4.runtime.tree.ParseTreeListener;
+import org.antlr.v4.runtime.tree.TerminalNode;
+import org.apache.olingo.producer.core.uri.antlr.UriLexer;
+
+public class TokenWriter implements ParseTreeListener {
+
+  @Override
+  public void visitTerminal(TerminalNode node) {
+    String out = String.format("%1$-" + 20 + "s", node.getText()); ;
+    out +=  UriLexer.tokenNames[node.getSymbol().getType()];
+    System.out.println(out); 
+  }
+
+  @Override
+  public void visitErrorNode(ErrorNode node) {
+    // TODO Auto-generated method stub
+
+  }
+
+  @Override
+  public void enterEveryRule(ParserRuleContext ctx) {
+    // TODO Auto-generated method stub
+
+  }
+
+  @Override
+  public void exitEveryRule(ParserRuleContext ctx) {
+    // TODO Auto-generated method stub
+
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/5e10653b/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/producer/core/testutil/UriResourcePathValidator.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/producer/core/testutil/UriResourcePathValidator.java b/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/producer/core/testutil/UriResourcePathValidator.java
index a3765bc..5a288aa 100644
--- a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/producer/core/testutil/UriResourcePathValidator.java
+++ b/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/producer/core/testutil/UriResourcePathValidator.java
@@ -58,7 +58,7 @@ public class UriResourcePathValidator {
   }
 
   public UriResourcePathValidator last() {
-    // TODO
+    // TODO implement
     // uriPathInfo = uriInfo.getLastUriPathInfo();
     return this;
   }

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/5e10653b/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/producer/core/uri/antlr/TestLexer.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/producer/core/uri/antlr/TestLexer.java b/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/producer/core/uri/antlr/TestLexer.java
index 738640e..5022c81 100644
--- a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/producer/core/uri/antlr/TestLexer.java
+++ b/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/producer/core/uri/antlr/TestLexer.java
@@ -18,7 +18,6 @@
  ******************************************************************************/
 package org.apache.olingo.producer.core.uri.antlr;
 
-import org.antlr.v4.runtime.LexerNoViableAltException;
 import org.apache.olingo.producer.core.testutil.TokenValidator;
 import org.junit.Test;
 
@@ -56,17 +55,32 @@ public class TestLexer {
     test = new TokenValidator();
   }
 
-  
-   @Test
+  // @Test
   public void test() {
-     test.run("$batch");
-   }
+    test.globalMode(UriLexer.MODE_QUERY);
+    // test.log(1).run("$filter='ABC'").isText("ABC").isType(UriLexer.STRING);
+    // test.log(1).run("ODI?$filter=1 add 2 mul 3");
+    // test.log(1).run("1  + 2 + 3");
+    // test.log(1).run("ODI?$filter=geography'SRID=0;Collection(LineString(142.1 64.1,3.14 2.78))'");
+    // test.log(1).run("ODI?$filter=1 mul 2 add 3");
+    // test.globalMode(UriLexer.MODE_QUERY);
+    // test.log(1).run("$entity?$id='A'&sdf=ssdf&$id=ABC");
+    // test.run("$skiptoken=top");
+
+    /*
+     * test.log(1).run("ODI?$filter=geo.intersects("
+     * + "geometry'SRID=0;Point(142.1 64.1)',"
+     * + "geometry'SRID=0;Polygon((1 1,1 1),(1 1,2 2,3 3,1 1))')");
+     */
+  }
+
   // ;------------------------------------------------------------------------------
   // ; 0. URI
   // ;------------------------------------------------------------------------------
-  
+
   @Test
   public void testUriTokens() {
+    test.globalMode(UriLexer.MODE_QUERY);
     test.run("#").isText("#").isType(UriLexer.FRAGMENT);
     test.run("$count").isText("$count").isType(UriLexer.COUNT);
     test.run("$ref").isText("$ref").isType(UriLexer.REF);
@@ -78,38 +92,44 @@ public class TestLexer {
   // ;------------------------------------------------------------------------------
   @Test
   public void testQueryOptionsTokens() {
-    test.run("$skip=1").isText("$skip=1").isType(UriLexer.SKIP);
-    test.run("$skip=2").isText("$skip=2").isType(UriLexer.SKIP);
-    test.run("$skip=123").isText("$skip=123").isType(UriLexer.SKIP);
-    test.run("$skip=A").isExType(LexerNoViableAltException.class);
-
-    test.run("$top=1").isText("$top=1").isType(UriLexer.TOP);
-    test.run("$top=2").isText("$top=2").isType(UriLexer.TOP);
-    test.run("$top=123").isText("$top=123").isType(UriLexer.TOP);
-    test.run("$top=A").isExType(LexerNoViableAltException.class);
-
-    test.run("$levels=1").isText("$levels=1").isType(UriLexer.LEVELS);
-    test.run("$levels=2").isText("$levels=2").isType(UriLexer.LEVELS);
-    test.run("$levels=123").isText("$levels=123").isType(UriLexer.LEVELS);
-    test.run("$levels=max").isText("$levels=max").isType(UriLexer.LEVELS);
-    test.run("$levels=A").isExType(LexerNoViableAltException.class);
-
-    test.run("$format=atom").isText("$format=atom").isType(UriLexer.FORMAT);
-    test.run("$format=json").isText("$format=json").isType(UriLexer.FORMAT);
-    test.run("$format=xml").isText("$format=xml").isType(UriLexer.FORMAT);
-    test.run("$format=abc/def").isText("$format=abc/def").isType(UriLexer.FORMAT);
-    test.run("$format=abc").isExType(LexerNoViableAltException.class);
-
-    test.run("$id=123").isText("$id=123").isType(UriLexer.ID);
-    test.run("$id=ABC").isText("$id=ABC").isType(UriLexer.ID);
-
-    test.run("$skiptoken=ABC").isText("$skiptoken=ABC").isType(UriLexer.SKIPTOKEN);
-    test.run("$skiptoken=ABC").isText("$skiptoken=ABC").isType(UriLexer.SKIPTOKEN);
-
-    test.run("\"ABC\"", true).isText("\"ABC\"").isType(UriLexer.SEARCHPHRASE);
-
-    test.run("$id=" + cQCHAR_NO_AMP + "", true).isInput().isType(UriLexer.ID);
 
+    test.globalMode(UriLexer.MODE_QUERY);
+    test.run("$skip=1").isAllText("$skip=1").isType(UriLexer.SKIP);
+    test.run("$skip=2").isAllText("$skip=2").isType(UriLexer.SKIP);
+    test.run("$skip=123").isAllText("$skip=123").isType(UriLexer.SKIP);
+
+    // TODO check and add error handling
+    // test.run("$skip=A").isExType(LexerNoViableAltException.class);
+
+    test.run("$top=1").isAllText("$top=1").isType(UriLexer.TOP);
+    test.run("$top=2").isAllText("$top=2").isType(UriLexer.TOP);
+    test.run("$top=123").isAllText("$top=123").isType(UriLexer.TOP);
+    // TODO check and add error handling
+    // test.run("$top=A").isExType(LexerNoViableAltException.class);
+
+    test.run("$levels=1").isAllText("$levels=1").isType(UriLexer.LEVELS);
+    test.run("$levels=2").isAllText("$levels=2").isType(UriLexer.LEVELS);
+    test.run("$levels=123").isAllText("$levels=123").isType(UriLexer.LEVELS);
+    test.run("$levels=max").isAllText("$levels=max").isType(UriLexer.LEVELS);
+    // TODO check and add error handling
+    // test.run("$levels=A").isExType(LexerNoViableAltException.class);
+
+    test.run("$format=atom").isAllText("$format=atom").isType(UriLexer.FORMAT);
+    test.run("$format=json").isAllText("$format=json").isType(UriLexer.FORMAT);
+    test.run("$format=xml").isAllText("$format=xml").isType(UriLexer.FORMAT);
+    test.run("$format=abc/def").isAllText("$format=abc/def").isType(UriLexer.FORMAT);
+    // TODO check and add error handling
+    // test.run("$format=abc").isExType(LexerNoViableAltException.class);
+
+    test.run("$id=123").isAllText("$id=123").isType(UriLexer.ID);
+    test.run("$id=ABC").isAllText("$id=ABC").isType(UriLexer.ID);
+
+    test.run("$skiptoken=ABC").isAllText("$skiptoken=ABC").isType(UriLexer.SKIPTOKEN);
+    test.run("$skiptoken=ABC").isAllText("$skiptoken=ABC").isType(UriLexer.SKIPTOKEN);
+
+    test.run("$search=\"ABC\"").isAllText("$search=\"ABC\"").isType(UriLexer.SEARCH);
+    test.run("$search=ABC").isAllText("$search=ABC").isType(UriLexer.SEARCH);
+    test.run("$search=\"A%20B%20C\"").isAllText("$search=\"A%20B%20C\"").isType(UriLexer.SEARCH);
   }
 
   // ;------------------------------------------------------------------------------
@@ -117,126 +137,135 @@ public class TestLexer {
   // ;------------------------------------------------------------------------------
   @Test
   public void testQueryExpressions() {
+    test.globalMode(UriLexer.MODE_SYSTEM_QUERY);
     // assertEquals("expected","actual");
-    test.run("$it").isText("$it").isType(UriLexer.IMPLICIT_VARIABLE_EXPR);
-    test.run("$itabc").isText("$it").isType(UriLexer.IMPLICIT_VARIABLE_EXPR);
 
-    test.run("contains").isText("contains").isType(UriLexer.CONTAINS);
-
-    test.run("containsabc").isText("containsabc").isType(UriLexer.ODATAIDENTIFIER); // test that this is a ODI
-
-    test.run("startswith").isText("startswith").isType(UriLexer.STARTSWITH);
-    test.run("endswith").isText("endswith").isType(UriLexer.ENDSWITH);
-    test.run("length").isText("length").isType(UriLexer.LENGTH);
-    test.run("indexof").isText("indexof").isType(UriLexer.INDEXOF);
-    test.run("substring").isText("substring").isType(UriLexer.SUBSTRING);
-    test.run("tolower").isText("tolower").isType(UriLexer.TOLOWER);
-    test.run("toupper").isText("toupper").isType(UriLexer.TOUPPER);
-    test.run("trim").isText("trim").isType(UriLexer.TRIM);
-    test.run("concat").isText("concat").isType(UriLexer.CONCAT);
-
-  }
+    test.run("$it").isText("$it").isType(UriLexer.IMPLICIT_VARIABLE_EXPR);
+    // TODO check and add error handling
+    // test.run("$itabc").isText("$it").isType(UriLexer.IMPLICIT_VARIABLE_EXPR);
 
-  // ;------------------------------------------------------------------------------
-  // ; 5. JSON format for function parameters
-  // ;------------------------------------------------------------------------------
-  @Test
-  public void testQueryJSON_and_otheres() {
-    // QUOTATION_MARK
-    test.run("\"").isText("\"").isType(UriLexer.QUOTATION_MARK);
-    test.run("%22").isText("%22").isType(UriLexer.QUOTATION_MARK);
-
-    // Lexer rule QCHAR_UNESCAPED
-    test.run("\"abc\"").isText("\"abc\"").isType(UriLexer.STRING_IN_JSON);
-
-    // Lexer rule QCHAR_JSON_SPECIAL
-    test.run("\"" + cQCHAR_JSON_SPECIAL + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
-
-    // Lexer rule CHAR_IN_JSON
-    test.run("\"" + cQCHAR_UNESCAPED + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
-    test.run("\"" + cQCHAR_JSON_SPECIAL + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
-
-    // Lexer rule ESCAPE CHAR_IN_JSON
-    test.run("\"" + cESCAPE + cQUOTATION_MARK + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
-    test.run("\"" + cESCAPE + cESCAPE + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
-    test.run("\"" + cESCAPE + "/" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
-    test.run("\"" + cESCAPE + "%2F" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
-    test.run("\"" + cESCAPE + "b" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
-    test.run("\"" + cESCAPE + "f" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
-    test.run("\"" + cESCAPE + "n" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
-    test.run("\"" + cESCAPE + "r" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
-    test.run("\"" + cESCAPE + "t" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
-    test.run("\"" + cESCAPE + "u12AB" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
-  }
+    test.run("$filter=contains(").at(2).isText("contains(").isType(UriLexer.CONTAINS_WORD);
 
-  // ;------------------------------------------------------------------------------
-  // ; 6. Names and identifiers
-  // ;------------------------------------------------------------------------------
-  @Test
-  public void testNamesAndIdentifiers() {
-
-    test.run("Binary").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run("Boolean").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run("Byte").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run("Date").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run("DateTimeOffset").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run("Decimal").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run("Double").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run("Duration").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run("Guid").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run("Int16").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run("Int32").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run("Int64").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run("SByte").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run("Single").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run("Stream").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run("String").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run("TimeOfDay").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-
-    test.run("Geography").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run("Geometry").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-
-    String g = "Geography";
-    test.run(g ).isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run(g + "Collection").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run(g + "LineString").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run(g + "MultiLineString").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run(g + "MultiPoint").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run(g + "MultiPolygon").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run(g + "Point").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run(g + "LineString").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run(g + "Polygon").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-
-    g = "Geometry";
-    test.run(g ).isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run(g + "Collection").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run(g + "LineString").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run(g + "MultiLineString").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run(g + "MultiPoint").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run(g + "MultiPolygon").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run(g + "Point").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run(g + "LineString").isInput().isType(UriLexer.PRIMITIVETYPENAME);
-    test.run(g + "Polygon").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+    test.run("$filter=containsabc").at(2).isText("containsabc")
+        .isType(UriLexer.ODATAIDENTIFIER); // test that this is a ODI
 
-  }
+    test.run("$filter=startswith(").at(2).isText("startswith(").isType(UriLexer.STARTSWITH_WORD);
+    test.run("$filter=endswith(").at(2).isText("endswith(").isType(UriLexer.ENDSWITH_WORD);
+    test.run("$filter=length(").at(2).isText("length(").isType(UriLexer.LENGTH_WORD);
+    test.run("$filter=indexof(").at(2).isText("indexof(").isType(UriLexer.INDEXOF_WORD);
+    test.run("$filter=substring(").at(2).isText("substring(").isType(UriLexer.SUBSTRING_WORD);
+    test.run("$filter=tolower(").at(2).isText("tolower(").isType(UriLexer.TOLOWER_WORD);
+    test.run("$filter=toupper(").at(2).isText("toupper(").isType(UriLexer.TOUPPER_WORD);
+    test.run("$filter=trim(").at(2).isText("trim(").isType(UriLexer.TRIM_WORD);
+    test.run("$filter=concat(").at(2).isText("concat(").isType(UriLexer.CONCAT_WORD);
 
-  @Test
-  public void testNameClaches() {
-   /* test.run("Collection").isInput().isType(UriLexer.COLLECTION_CS_FIX);
-    test.run("LineString").isInput().isType(UriLexer.LINESTRING_CS_FIX);
-    test.run("MultiLineString").isInput().isType(UriLexer.MULTILINESTRING_CS_FIX);
-    test.run("MultiPoint").isInput().isType(UriLexer.MULTIPOINT_CS_FIX);
-    test.run("MultiPolygon").isInput().isType(UriLexer.MULTIPOLYGON_CS_FIX);
-    test.run("Point").isInput().isType(UriLexer.POINT_CS_FIX);
-    test.run("Polygon").isInput().isType(UriLexer.POLYGON_CS_FIX);
-    test.run("Srid").isInput().isType(UriLexer.SRID_CS);*/
   }
 
+  /*
+   * // ;------------------------------------------------------------------------------
+   * // ; 5. JSON format for function parameters
+   * // ;------------------------------------------------------------------------------
+   * 
+   * @Test
+   * public void testQueryJSON_and_otheres() {
+   * // QUOTATION_MARK
+   * test.run("\"").isText("\"").isType(UriLexer.QUOTATION_MARK);
+   * test.run("%22").isText("%22").isType(UriLexer.QUOTATION_MARK);
+   * 
+   * // Lexer rule QCHAR_UNESCAPED
+   * test.run("\"abc\"").isText("\"abc\"").isType(UriLexer.STRING_IN_JSON);
+   * 
+   * // Lexer rule QCHAR_JSON_SPECIAL
+   * test.run("\"" + cQCHAR_JSON_SPECIAL + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
+   * 
+   * // Lexer rule CHAR_IN_JSON
+   * test.run("\"" + cQCHAR_UNESCAPED + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
+   * test.run("\"" + cQCHAR_JSON_SPECIAL + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
+   * 
+   * // Lexer rule ESCAPE CHAR_IN_JSON
+   * test.run("\"" + cESCAPE + cQUOTATION_MARK + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
+   * test.run("\"" + cESCAPE + cESCAPE + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
+   * test.run("\"" + cESCAPE + "/" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
+   * test.run("\"" + cESCAPE + "%2F" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
+   * test.run("\"" + cESCAPE + "b" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
+   * test.run("\"" + cESCAPE + "f" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
+   * test.run("\"" + cESCAPE + "n" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
+   * test.run("\"" + cESCAPE + "r" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
+   * test.run("\"" + cESCAPE + "t" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
+   * test.run("\"" + cESCAPE + "u12AB" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
+   * }
+   * 
+   * // ;------------------------------------------------------------------------------
+   * // ; 6. Names and identifiers
+   * // ;------------------------------------------------------------------------------
+   * 
+   * @Test
+   * public void testNamesAndIdentifiers() {
+   * 
+   * test.run("Binary").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run("Boolean").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run("Byte").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run("Date").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run("DateTimeOffset").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run("Decimal").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run("Double").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run("Duration").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run("Guid").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run("Int16").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run("Int32").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run("Int64").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run("SByte").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run("Single").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run("Stream").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run("String").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run("TimeOfDay").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * 
+   * test.run("Geography").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run("Geometry").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * 
+   * String g = "Geography";
+   * test.run(g ).isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run(g + "Collection").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run(g + "LineString").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run(g + "MultiLineString").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run(g + "MultiPoint").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run(g + "MultiPolygon").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run(g + "Point").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run(g + "LineString").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run(g + "Polygon").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * 
+   * g = "Geometry";
+   * test.run(g ).isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run(g + "Collection").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run(g + "LineString").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run(g + "MultiLineString").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run(g + "MultiPoint").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run(g + "MultiPolygon").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run(g + "Point").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run(g + "LineString").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * test.run(g + "Polygon").isInput().isType(UriLexer.PRIMITIVETYPENAME);
+   * 
+   * }
+   * 
+   * @Test
+   * public void testNameClaches() {
+   * -- test.run("Collection").isInput().isType(UriLexer.COLLECTION_CS_FIX);
+   * test.run("LineString").isInput().isType(UriLexer.LINESTRING_CS_FIX);
+   * test.run("MultiLineString").isInput().isType(UriLexer.MULTILINESTRING_CS_FIX);
+   * test.run("MultiPoint").isInput().isType(UriLexer.MULTIPOINT_CS_FIX);
+   * test.run("MultiPolygon").isInput().isType(UriLexer.MULTIPOLYGON_CS_FIX);
+   * test.run("Point").isInput().isType(UriLexer.POINT_CS_FIX);
+   * test.run("Polygon").isInput().isType(UriLexer.POLYGON_CS_FIX);
+   * test.run("Srid").isInput().isType(UriLexer.SRID_CS);--
+   * }
+   */
   // ;------------------------------------------------------------------------------
   // ; 7. Literal Data Values
   // ;------------------------------------------------------------------------------
+
   @Test
   public void testLiteralDataValues() {
+    test.globalMode(UriLexer.MODE_SYSTEM_QUERY);
     // null
     test.run("null").isInput().isType(UriLexer.NULLVALUE);
 
@@ -246,7 +275,7 @@ public class TestLexer {
     test.run("binary'ABCD'").isInput().isType(UriLexer.BINARY);
     test.run("BiNaRy'ABCD'").isInput().isType(UriLexer.BINARY);
 
-    // not a binary
+    // not a binary TODO add error handling
     test.run("x'ABCDA'")
         .at(0).isText("x").isType(UriLexer.ODATAIDENTIFIER)
         .at(1).isText("'ABCDA'").isType(UriLexer.STRING);
@@ -267,6 +296,7 @@ public class TestLexer {
     test.run("+123456789").isInput().isType(UriLexer.INT);
     test.run("-123").isInput().isType(UriLexer.INT);
     test.run("-123456789").isInput().isType(UriLexer.INT);
+
     // Lexer rule DECIMAL
     test.run("0.1").isInput().isType(UriLexer.DECIMAL);
     test.run("1.1").isInput().isType(UriLexer.DECIMAL);
@@ -274,6 +304,7 @@ public class TestLexer {
     test.run("+1.1").isInput().isType(UriLexer.DECIMAL);
     test.run("-0.1").isInput().isType(UriLexer.DECIMAL);
     test.run("-1.1").isInput().isType(UriLexer.DECIMAL);
+
     // Lexer rule EXP
     test.run("1.1e+1").isInput().isType(UriLexer.DECIMAL);
     test.run("1.1e-1").isInput().isType(UriLexer.DECIMAL);
@@ -283,7 +314,6 @@ public class TestLexer {
     test.run("INF").isInput().isType(UriLexer.NANINFINITY);
 
     // Lexer rule GUID
-
     test.run("guid'1234ABCD-12AB-23CD-45EF-123456780ABC'").isInput().isType(UriLexer.GUID);
     test.run("GuId'1234ABCD-12AB-23CD-45EF-123456780ABC'").isInput().isType(UriLexer.GUID);
 
@@ -337,74 +367,72 @@ public class TestLexer {
     test.run("timeofday'20:15:01.02'").isInput().isType(UriLexer.TIMEOFDAY);
 
     test.run("timeofday'20:15:01.02'").isInput().isType(UriLexer.TIMEOFDAY);
-    
-    //String
-    test.run("'ABC'").isInput().isType(UriLexer.STRING);
+
+    // String
+    test.run("'ABC'").isText("'ABC'").isType(UriLexer.STRING);
     test.run("'A%20C'").isInput().isType(UriLexer.STRING);
     test.run("'%20%20%20ABC'").isInput().isType(UriLexer.STRING);
-    
-  }
 
-  // ;------------------------------------------------------------------------------
-  // ; 0. misc
-  // ;------------------------------------------------------------------------------
-
-  @Test
-  public void testCriticalOrder() {
-    // Test lexer rule STRING
-    test.run("'abc'").isInput().isType(UriLexer.STRING);
-
-    // Test lexer rule SEARCHWORD
-    test.run("abc", true).isInput().isType(UriLexer.SEARCHWORD);
-
-    // Test lexer rule SEARCHPHRASE
-    test.run("\"abc\"", true).isInput().isType(UriLexer.SEARCHPHRASE);
-
-    // Test lexer rule ODATAIDENTIFIER
-    test.run("abc").isInput().isType(UriLexer.ODATAIDENTIFIER);
-
-    test.run("\"abc\"").isInput().isType(UriLexer.STRING_IN_JSON);
   }
 
-  //@Test
+  /*
+   * // ;------------------------------------------------------------------------------
+   * // ; 0. misc
+   * // ;------------------------------------------------------------------------------
+   * 
+   * @Test
+   * public void testCriticalOrder() {
+   * // Test lexer rule STRING
+   * test.run("'abc'").isInput().isType(UriLexer.STRING);
+   * 
+   * // Test lexer rule SEARCHWORD
+   * test.run("abc", true).isInput().isType(UriLexer.SEARCHWORD);
+   * 
+   * // Test lexer rule SEARCHPHRASE
+   * test.run("\"abc\"", true).isInput().isType(UriLexer.SEARCHPHRASE);
+   * 
+   * // Test lexer rule ODATAIDENTIFIER
+   * test.run("abc").isInput().isType(UriLexer.ODATAIDENTIFIER);
+   * 
+   * test.run("\"abc\"").isInput().isType(UriLexer.STRING_IN_JSON);
+   * }
+   */
+  @Test
   public void testDelims() {
     String reserved = "/";
-
+    test.globalMode(UriLexer.MODE_QUERY);
     // Test lexer rule UNRESERVED
-    test.run("$format=A/" + cUNRESERVED).isInput().isType(UriLexer.FORMAT);
-    test.run("$format=A/" + cUNRESERVED + reserved).isText("$format=A/" + cUNRESERVED).isType(UriLexer.FORMAT);
+    test.run("$format=A/" + cUNRESERVED).isAllInput().isType(UriLexer.FORMAT);
+    test.run("$format=A/" + cUNRESERVED + reserved).isType(UriLexer.FORMAT).at(4).isText(cUNRESERVED);
     // Test lexer rule PCT_ENCODED
-    test.run("$format=A/" + cPCT_ENCODED).isInput().isType(UriLexer.FORMAT);
-    test.run("$format=A/" + cPCT_ENCODED + reserved).isText("$format=A/" + cPCT_ENCODED).isType(UriLexer.FORMAT);
+    test.run("$format=A/" + cPCT_ENCODED).isAllInput().isType(UriLexer.FORMAT);
+    test.run("$format=A/" + cPCT_ENCODED + reserved).isType(UriLexer.FORMAT).at(4).isText(cPCT_ENCODED);
     // Test lexer rule SUB_DELIMS
-    test.run("$format=A/" + cSUB_DELIMS).isInput().isType(UriLexer.FORMAT);
-    test.run("$format=A/" + cSUB_DELIMS + reserved).isText("$format=A/" + cSUB_DELIMS).isType(UriLexer.FORMAT);
+    test.run("$format=A/" + cSUB_DELIMS).isAllInput().isType(UriLexer.FORMAT);
+    test.run("$format=A/" + cSUB_DELIMS + reserved).isType(UriLexer.FORMAT).at(4).isText(cSUB_DELIMS);
     // Test lexer rule PCHAR rest
-    test.run("$format=A/:@").isText("$format=A/:@").isType(UriLexer.FORMAT);
-    test.run("$format=A/:@" + reserved).isText("$format=A/:@").isType(UriLexer.FORMAT);
+    test.run("$format=A/:@").isAllText("$format=A/:@").isType(UriLexer.FORMAT);
+    test.run("$format=A/:@" + reserved).isType(UriLexer.FORMAT).at(4).isText(":@");
     // Test lexer rule PCHAR all
-    test.run("$format=" + cPCHAR + "/" + cPCHAR).isInput().isType(UriLexer.FORMAT);
+    test.run("$format=" + cPCHAR + "/" + cPCHAR).isAllInput().isType(UriLexer.FORMAT);
     test.run("$format=" + cPCHAR + "/" + cPCHAR + reserved)
-        .isText("$format=" + cPCHAR + "/" + cPCHAR)
-        .isType(UriLexer.FORMAT);
+        .isType(UriLexer.FORMAT).at(4)
+        .isText(cPCHAR);
 
     // Test lexer rule QCHAR_NO_AMP
     String amp = "&";
     // Test lexer rule UNRESERVED
-    test.run("$id=" + cUNRESERVED).isInput().isType(UriLexer.ID);
-    test.run("$id=" + cUNRESERVED + amp).isText("$id=" + cUNRESERVED).isType(UriLexer.ID);
+    test.run("$id=" + cUNRESERVED).isAllInput().isType(UriLexer.ID);
+    test.run("$id=" + cUNRESERVED + amp).isType(UriLexer.ID).at(2).isText(cUNRESERVED);
     // Test lexer rule PCT_ENCODED
-    test.run("$id=" + cPCT_ENCODED).isInput().isType(UriLexer.ID);
-    test.run("$id=" + cPCT_ENCODED + amp).isText("$id=" + cPCT_ENCODED).isType(UriLexer.ID);
+    test.run("$id=" + cPCT_ENCODED).isAllInput().isType(UriLexer.ID);
+    test.run("$id=" + cPCT_ENCODED + amp).isType(UriLexer.ID).at(2).isText(cPCT_ENCODED);
     // Test lexer rule OTHER_DELIMS
-    test.run("$id=" + cOTHER_DELIMS).isInput().isType(UriLexer.ID);
-    test.run("$id=" + cOTHER_DELIMS + amp).isText("$id=" + cOTHER_DELIMS).isType(UriLexer.ID);
+    test.run("$id=" + cOTHER_DELIMS).isAllInput().isType(UriLexer.ID);
+    test.run("$id=" + cOTHER_DELIMS + amp).isType(UriLexer.ID).at(2).isText(cOTHER_DELIMS);
     // Lexer rule QCHAR_NO_AMP rest
-    test.run("$id=:@/?$'=").isText("$id=:@/?$'=").isType(UriLexer.ID);
-    test.run("$id=:@/?$'=" + amp).isText("$id=:@/?$'=").isType(UriLexer.ID);
-
-    // Test lexer rule QCHAR_NO_AMP_DQUOTE
-    test.run("\"" + cQCHAR_NO_AMP_DQUOTE + "\"", true).isInput().isType(UriLexer.SEARCHPHRASE);
+    test.run("$id=:@/?$'=").isAllText("$id=:@/?$'=").isType(UriLexer.ID);
+    test.run("$id=:@/?$'=" + amp).isType(UriLexer.ID).at(2).isText(":@/?$'=");
 
   }