Examples of IntervalSet


Examples of org.antlr.misc.IntervalSet

    String result = (s.complement(vocabulary)).toString();
    assertEquals(result, expecting);
  }

    @Test public void testNotSetFragmentedVocabulary() throws Exception {
        IntervalSet vocabulary = IntervalSet.of(1,255);
        vocabulary.add(1000,2000);
        vocabulary.add(9999);
        IntervalSet s = IntervalSet.of(50,60);
        s.add(3);
        s.add(250,300);
        s.add(10000); // this is outside range of vocab and should be ignored
        String expecting = "{1..2, 4..49, 61..249, 1000..2000, 9999}";
        String result = (s.complement(vocabulary)).toString();
        assertEquals(result, expecting);
    }
View Full Code Here

Examples of org.antlr.misc.IntervalSet

        String result = (s.complement(vocabulary)).toString();
        assertEquals(result, expecting);
    }

    @Test public void testSubtractOfCompletelyContainedRange() throws Exception {
        IntervalSet s = IntervalSet.of(10,20);
        IntervalSet s2 = IntervalSet.of(12,15);
        String expecting = "{10..11, 16..20}";
        String result = (s.subtract(s2)).toString();
        assertEquals(result, expecting);
    }
View Full Code Here

Examples of org.antlr.misc.IntervalSet

        String result = (s.subtract(s2)).toString();
        assertEquals(result, expecting);
    }

    @Test public void testSubtractOfOverlappingRangeFromLeft() throws Exception {
        IntervalSet s = IntervalSet.of(10,20);
        IntervalSet s2 = IntervalSet.of(5,11);
        String expecting = "12..20";
        String result = (s.subtract(s2)).toString();
        assertEquals(result, expecting);

        IntervalSet s3 = IntervalSet.of(5,10);
        expecting = "11..20";
        result = (s.subtract(s3)).toString();
        assertEquals(result, expecting);
    }
View Full Code Here

Examples of org.antlr.misc.IntervalSet

        result = (s.subtract(s3)).toString();
        assertEquals(result, expecting);
    }

    @Test public void testSubtractOfOverlappingRangeFromRight() throws Exception {
        IntervalSet s = IntervalSet.of(10,20);
        IntervalSet s2 = IntervalSet.of(15,25);
        String expecting = "10..14";
        String result = (s.subtract(s2)).toString();
        assertEquals(result, expecting);

        IntervalSet s3 = IntervalSet.of(20,25);
        expecting = "10..19";
        result = (s.subtract(s3)).toString();
        assertEquals(result, expecting);
    }
View Full Code Here

Examples of org.antlr.misc.IntervalSet

        result = (s.subtract(s3)).toString();
        assertEquals(result, expecting);
    }

    @Test public void testSubtractOfCompletelyCoveredRange() throws Exception {
        IntervalSet s = IntervalSet.of(10,20);
        IntervalSet s2 = IntervalSet.of(1,25);
        String expecting = "{}";
        String result = (s.subtract(s2)).toString();
        assertEquals(result, expecting);
    }
View Full Code Here

Examples of org.antlr.misc.IntervalSet

        String result = (s.subtract(s2)).toString();
        assertEquals(result, expecting);
    }

    @Test public void testSubtractOfRangeSpanningMultipleRanges() throws Exception {
        IntervalSet s = IntervalSet.of(10,20);
        s.add(30,40);
        s.add(50,60); // s has 3 ranges now: 10..20, 30..40, 50..60
        IntervalSet s2 = IntervalSet.of(5,55); // covers one and touches 2nd range
        String expecting = "56..60";
        String result = (s.subtract(s2)).toString();
        assertEquals(result, expecting);

        IntervalSet s3 = IntervalSet.of(15,55); // touches both
        expecting = "{10..14, 56..60}";
        result = (s.subtract(s3)).toString();
        assertEquals(result, expecting);
    }
View Full Code Here

Examples of org.antlr.v4.runtime.misc.IntervalSet

    // ignore tokens from existing option subtrees like:
    //    (ELEMENT_OPTIONS (= assoc right))
    //
    // element options are added back according to the values in the map
    // returned by getOptions().
    IntervalSet ignore = new IntervalSet();
    List<GrammarAST> optionsSubTrees = t.getNodesWithType(ELEMENT_OPTIONS);
    for (GrammarAST sub : optionsSubTrees) {
      ignore.add(sub.getTokenStartIndex(), sub.getTokenStopIndex());
    }

    // Individual labels appear as RULE_REF or TOKEN_REF tokens in the tree,
    // but do not support the ELEMENT_OPTIONS syntax. Make sure to not try
    // and add the tokenIndex option when writing these tokens.
    IntervalSet noOptions = new IntervalSet();
    List<GrammarAST> labeledSubTrees = t.getNodesWithType(new IntervalSet(ASSIGN,PLUS_ASSIGN));
    for (GrammarAST sub : labeledSubTrees) {
      noOptions.add(sub.getChild(0).getTokenStartIndex());
    }

    StringBuilder buf = new StringBuilder();
    for (int i=tokenStartIndex; i<=tokenStopIndex; i++) {
      if ( ignore.contains(i) ) {
        continue;
      }

      Token tok = tokenStream.get(i);

      StringBuilder elementOptions = new StringBuilder();
      if (!noOptions.contains(i)) {
        GrammarAST node = t.getNodeWithTokenIndex(tok.getTokenIndex());
        if ( node!=null &&
           (tok.getType()==TOKEN_REF ||
            tok.getType()==STRING_LITERAL ||
            tok.getType()==RULE_REF) )
View Full Code Here

Examples of org.antlr.v4.runtime.misc.IntervalSet

  @NotNull
  @Override
  public Handle set(@NotNull GrammarAST associatedAST, @NotNull List<GrammarAST> terminals, boolean invert) {
    ATNState left = newState(associatedAST);
    ATNState right = newState(associatedAST);
    IntervalSet set = new IntervalSet();
    for (GrammarAST t : terminals) {
      int ttype = g.getTokenType(t.getText());
      set.add(ttype);
    }
    if ( invert ) {
      left.addTransition(new NotSetTransition(right, set));
    }
    else {
View Full Code Here

Examples of org.antlr.v4.runtime.misc.IntervalSet

//                 lastErrorIndex+", states="+lastErrorStates);
//      System.err.println("FAILSAFE consumes "+recognizer.getTokenNames()[recognizer.getInputStream().LA(1)]);
      recognizer.consume();
    }
    lastErrorIndex = recognizer.getInputStream().index();
    if ( lastErrorStates==null ) lastErrorStates = new IntervalSet();
    lastErrorStates.add(recognizer.getState());
    IntervalSet followSet = getErrorRecoverySet(recognizer);
    consumeUntil(recognizer, followSet);
  }
View Full Code Here

Examples of org.antlr.v4.runtime.misc.IntervalSet

    case ATNState.PLUS_LOOP_BACK:
    case ATNState.STAR_LOOP_BACK:
//      System.err.println("at loop back: "+s.getClass().getSimpleName());
      reportUnwantedToken(recognizer);
      IntervalSet expecting = recognizer.getExpectedTokens();
      IntervalSet whatFollowsLoopIterationOrRule =
        expecting.or(getErrorRecoverySet(recognizer));
      consumeUntil(recognizer, whatFollowsLoopIterationOrRule);
      break;

    default:
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.