Package org.antlr.runtime3_3_0

Examples of org.antlr.runtime3_3_0.FailedPredicateException


    /** Make stream jump to a new location, saving old location.
     *  Switch back with pop().
     */
    public void push(int index) {
        if ( calls==null ) {
            calls = new IntArray();
        }
        calls.push(p); // save current index
        seek(index);
    }
View Full Code Here


  Stack callStack = new Stack();
  List hiddenTokens = new ArrayList();
  int backtracking = 0;

  public ParseTreeBuilder(String grammarName) {
    ParseTree root = create("<grammar "+grammarName+">");
    callStack.push(root);
  }
View Full Code Here

  /**  What kind of node to create.  You might want to override
   *   so I factored out creation here.
   */
  public ParseTree create(Object payload) {
    return new ParseTree(payload);
  }
View Full Code Here

  public void enterDecision(int d, boolean couldBacktrack) { backtracking++; }
  public void exitDecision(int i) { backtracking--; }

  public void enterRule(String filename, String ruleName) {
    if ( backtracking>0 ) return;
    ParseTree parentRuleNode = (ParseTree)callStack.peek();
    ParseTree ruleNode = create(ruleName);
    parentRuleNode.addChild(ruleNode);
    callStack.push(ruleNode);
  }
View Full Code Here

    callStack.push(ruleNode);
  }

  public void exitRule(String filename, String ruleName) {
    if ( backtracking>0 ) return;
    ParseTree ruleNode = (ParseTree)callStack.peek();
    if ( ruleNode.getChildCount()==0 ) {
      ruleNode.addChild(epsilonNode());
    }
    callStack.pop();   
  }
View Full Code Here

    callStack.pop();   
  }

  public void consumeToken(Token token) {
    if ( backtracking>0 ) return;
    ParseTree ruleNode = (ParseTree)callStack.peek();
    ParseTree elementNode = create(token);
    elementNode.hiddenTokens = this.hiddenTokens;
    this.hiddenTokens = new ArrayList();
    ruleNode.addChild(elementNode);
  }
View Full Code Here

    hiddenTokens.add(token);
  }

  public void recognitionException(RecognitionException e) {
    if ( backtracking>0 ) return;
    ParseTree ruleNode = (ParseTree)callStack.peek();
    ParseTree errorNode = create(e);
    ruleNode.addChild(errorNode);
  }
View Full Code Here

    if ( input instanceof TokenStream ) {
      return token.getType();
    }
    else if ( input instanceof TreeNodeStream ) {
      TreeNodeStream nodes = (TreeNodeStream)input;
      TreeAdaptor adaptor = nodes.getTreeAdaptor();
      return adaptor.getType(node);
    }
    else {
      return c;
    }
  }
View Full Code Here

  }

  protected void extractInformationFromTreeNodeStream(IntStream input) {
    TreeNodeStream nodes = (TreeNodeStream)input;
    this.node = nodes.LT(1);
    TreeAdaptor adaptor = nodes.getTreeAdaptor();
    Token payload = adaptor.getToken(node);
    if ( payload!=null ) {
      this.token = payload;
      if ( payload.getLine()<= 0 ) {
        // imaginary node; no line/pos info; scan backwards
        int i = -1;
        Object priorNode = nodes.LT(i);
        while ( priorNode!=null ) {
          Token priorPayload = adaptor.getToken(priorNode);
          if ( priorPayload!=null && priorPayload.getLine()>0 ) {
            // we found the most recent real line / pos info
            this.line = priorPayload.getLine();
            this.charPositionInLine = priorPayload.getCharPositionInLine();
            this.approximateLineInfo = true;
            break;
          }
          --i;
          priorNode = nodes.LT(i);
        }
      }
      else { // node created from real token
        this.line = payload.getLine();
        this.charPositionInLine = payload.getCharPositionInLine();
      }
    }
    else if ( this.node instanceof Tree) {
      this.line = ((Tree)this.node).getLine();
      this.charPositionInLine = ((Tree)this.node).getCharPositionInLine();
      if ( this.node instanceof CommonTree) {
        this.token = ((CommonTree)this.node).token;
      }
    }
    else {
      int type = adaptor.getType(this.node);
      String text = adaptor.getText(this.node);
      this.token = new CommonToken(type, text);
    }
  }
View Full Code Here

      this.c = input.LA(1);
    }
  }

  protected void extractInformationFromTreeNodeStream(IntStream input) {
    TreeNodeStream nodes = (TreeNodeStream)input;
    this.node = nodes.LT(1);
    TreeAdaptor adaptor = nodes.getTreeAdaptor();
    Token payload = adaptor.getToken(node);
    if ( payload!=null ) {
      this.token = payload;
      if ( payload.getLine()<= 0 ) {
        // imaginary node; no line/pos info; scan backwards
        int i = -1;
        Object priorNode = nodes.LT(i);
        while ( priorNode!=null ) {
          Token priorPayload = adaptor.getToken(priorNode);
          if ( priorPayload!=null && priorPayload.getLine()>0 ) {
            // we found the most recent real line / pos info
            this.line = priorPayload.getLine();
            this.charPositionInLine = priorPayload.getCharPositionInLine();
            this.approximateLineInfo = true;
            break;
          }
          --i;
          priorNode = nodes.LT(i);
        }
      }
      else { // node created from real token
        this.line = payload.getLine();
        this.charPositionInLine = payload.getCharPositionInLine();
View Full Code Here

TOP

Related Classes of org.antlr.runtime3_3_0.FailedPredicateException

Copyright © 2018 www.massapicom. 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.