Package org.antlr.runtime

Examples of org.antlr.runtime.CommonToken


        public String getInfoString() {
            StringBuilder info = new StringBuilder();
            Object payload = getPayload();
            if(payload instanceof CommonToken) {
                CommonToken t = (CommonToken)payload;
                info.append("Type: ").append(grammar.getTokenDisplayName(t.getType())).append("\n");
                info.append("Text: ").append(t.getText()).append("\n");
                info.append("Line: ").append(t.getLine()).append("\n");
                info.append("Char: ").append(t.getCharPositionInLine()).append("\n");
                info.append("Channel: ").append(t.getChannel()).append("\n");
            } else if(payload instanceof NoViableAltException) {
                NoViableAltException e = (NoViableAltException)payload;
                info.append("Description: ").append(e.grammarDecisionDescription).append("\n");
                info.append("Descision: ").append(e.decisionNumber).append("\n");
                info.append("State: ").append(e.stateNumber).append("\n");
View Full Code Here


        }

        public String toString() {
            Object payload = getPayload();
            if(payload instanceof CommonToken) {
                CommonToken t = (CommonToken)payload;
                return t.getText();
            } else if(payload instanceof NoViableAltException)
                return "NoViableAltException";
            else if(payload == null)
                return "<null>";
            else
View Full Code Here

    }
    PTFInputSpec iSpec = spec.getInput();
    if (iSpec instanceof PTFInputSpec) {
      PartitionSpec partSpec = new PartitionSpec();
      PartitionExpression partExpr = new PartitionExpression();
      partExpr.setExpression(new ASTNode(new CommonToken(HiveParser.Number, "0")));
      partSpec.addExpression(partExpr);
      spec.setPartition(partSpec);
    }
  }
View Full Code Here

   * Need to serialize org.antlr.runtime.CommonToken
   */
  public static class CommonTokenDelegate extends PersistenceDelegate {
    @Override
    protected Expression instantiate(Object oldInstance, Encoder out) {
      CommonToken ct = (CommonToken)oldInstance;
      Object[] args = {ct.getType(), ct.getText()};
      return new Expression(ct, ct.getClass(), "new", args);
    }
View Full Code Here

          Transition t = p.transition(j);
          if (!t.isEpsilon() && !t.label.getSet().and(label).isNil()
              && next.contains(t.target)) {
            if (p.associatedASTNode != null) {
              Token oldtoken = p.associatedASTNode.token;
              CommonToken token = new CommonToken(oldtoken
                  .getType(), oldtoken.getText());
              token.setLine(oldtoken.getLine());
              token.setCharPositionInLine(oldtoken.getCharPositionInLine());
              tokens.add(token);
              break nfaConfigLoop; // found path, move to next
                          // NFAState set
            }
          }
View Full Code Here

    buf.append("\n");
    for (int i=ruleAST.getTokenStartIndex();
       i<=ruleAST.getTokenStopIndex() && i<tokenBuffer.size();
       i++)
    {
      CommonToken t = (CommonToken)tokenBuffer.get(i);
      // undo the text deletions done by the lexer (ugh)
      if ( t.getType()==ANTLRParser.BLOCK ) {
        buf.append("(");
      }
      else if ( t.getType()==ANTLRParser.ACTION ) {
        buf.append("{");
        buf.append(t.getText());
        buf.append("}");
      }
      else if ( t.getType()==ANTLRParser.SEMPRED ||
            t.getType()==ANTLRParser.SYN_SEMPRED ||
            t.getType()==ANTLRParser.GATED_SEMPRED ||
            t.getType()==ANTLRParser.BACKTRACK_SEMPRED )
      {
        buf.append("{");
        buf.append(t.getText());
        buf.append("}?");
      }
      else if ( t.getType()==ANTLRParser.ARG_ACTION ) {
        buf.append("[");
        buf.append(t.getText());
        buf.append("]");
      }
      else {
        buf.append(t.getText());
      }
    }
    String ruleText = buf.toString();
    //System.out.println("[["+ruleText+"]]");
    // now put the rule into the lexer grammar template
View Full Code Here

    @Test public void testSeek() throws Exception {
        // ^(101 ^(102 103 ^(106 107) ) 104 105)
        // stream has 7 real + 6 nav nodes
        // Sequence of types: 101 DN 102 DN 103 106 DN 107 UP UP 104 105 UP EOF
        Tree r0 = new CommonTree(new CommonToken(101));
        Tree r1 = new CommonTree(new CommonToken(102));
        r0.addChild(r1);
        r1.addChild(new CommonTree(new CommonToken(103)));
        Tree r2 = new CommonTree(new CommonToken(106));
        r2.addChild(new CommonTree(new CommonToken(107)));
        r1.addChild(r2);
        r0.addChild(new CommonTree(new CommonToken(104)));
        r0.addChild(new CommonTree(new CommonToken(105)));

        TreeNodeStream stream = newStream(r0);
        stream.consume(); // consume 101
        stream.consume(); // consume DN
        stream.consume(); // consume 102
View Full Code Here

    CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
    g.setCodeGenerator(generator);
    generator.genRecognizer(); // forces load of templates
    ActionTranslator translator = new ActionTranslator(generator,
                                  "rule",
                                  new CommonToken(ANTLRParser.ACTION,action),1);
    String rawTranslation =
      translator.translate();

    int expectedMsgID = ErrorManager.MSG_WRITE_TO_READONLY_ATTR;
    Object expectedArg = "other";
View Full Code Here

    public String toTokenTypeString(TreeNodeStream stream) {
        return ((CommonTreeNodeStream)stream).toTokenTypeString();
    }

  @Test public void testSingleNode() throws Exception {
    Tree t = new CommonTree(new CommonToken(101));

    TreeNodeStream stream = newStream(t);
    String expecting = " 101";
    String found = toNodesOnlyString(stream);
    assertEquals(expecting, found);
View Full Code Here

    assertEquals(expecting, found);
  }

  @Test public void test4Nodes() throws Exception {
    // ^(101 ^(102 103) 104)
    Tree t = new CommonTree(new CommonToken(101));
    t.addChild(new CommonTree(new CommonToken(102)));
    t.getChild(0).addChild(new CommonTree(new CommonToken(103)));
    t.addChild(new CommonTree(new CommonToken(104)));

    TreeNodeStream stream = newStream(t);
    String expecting = " 101 102 103 104";
    String found = toNodesOnlyString(stream);
    assertEquals(expecting, found);
View Full Code Here

TOP

Related Classes of org.antlr.runtime.CommonToken

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.