Esempio n. 1
0
 /** Get num hidden tokens between i..j inclusive */
 public int getNumberOfHiddenTokens(int i, int j) {
   int n = 0;
   TokenStream input = parser.getTokenStream();
   for (int ti = i; ti < input.size() && ti <= j; ti++) {
     Token t = input.get(ti);
     if (t.getChannel() != Token.DEFAULT_CHANNEL) {
       n++;
     }
   }
   return n;
 }
Esempio n. 2
0
  public void enterDecision(int decisionNumber, boolean couldBacktrack) {
    lastRealTokenTouchedInDecision = null;
    stats.numDecisionEvents++;
    int startingLookaheadIndex = parser.getTokenStream().index();
    TokenStream input = parser.getTokenStream();
    if (dump)
      System.out.println(
          "enterDecision canBacktrack="
              + couldBacktrack
              + " "
              + decisionNumber
              + " backtrack depth "
              + backtrackDepth
              + " @ "
              + input.get(input.index())
              + " rule "
              + locationDescription());
    String g = (String) currentGrammarFileName.peek();
    DecisionDescriptor descriptor = decisions.get(g, decisionNumber);
    if (descriptor == null) {
      descriptor = new DecisionDescriptor();
      decisions.put(g, decisionNumber, descriptor);
      descriptor.decision = decisionNumber;
      descriptor.fileName = (String) currentGrammarFileName.peek();
      descriptor.ruleName = (String) currentRuleName.peek();
      descriptor.line = (Integer) currentLine.peek();
      descriptor.pos = (Integer) currentPos.peek();
      descriptor.couldBacktrack = couldBacktrack;
    }
    descriptor.n++;

    DecisionEvent d = new DecisionEvent();
    decisionStack.push(d);
    d.decision = descriptor;
    d.startTime = System.currentTimeMillis();
    d.startIndex = startingLookaheadIndex;
  }