Package org.antlr.runtime

Examples of org.antlr.runtime.CommonToken


        return String.format("CREATE VIRTUAL TABLE %s", getCoreSQL(parseTable));
    }

    private String getCoreSQL(RuleReturnScope parsedSQL) {
        final CommonTree ast = (CommonTree) parsedSQL.getTree();
        final CommonToken nameToken = (CommonToken) ((CommonTree) ast.getChild(1)).getToken();
        final CharStream inputStream = nameToken.getInputStream();
        final CommonToken stopToken = (CommonToken) parsedSQL.getStop();
        return inputStream.substring(nameToken.getStartIndex(), stopToken.getStopIndex());
    }
View Full Code Here


     * @return
     */
    private String getAlterTableName(SqlJetAlterTableDef alterTableDef) {
        final ParserRuleReturnScope parsedSql = alterTableDef.getParsedSql();
        final CommonTree ast = (CommonTree) parsedSql.getTree();
        final CommonToken stopToken = (CommonToken) parsedSql.getStop();
        final CommonToken nameToken = (CommonToken) ((CommonTree) ast.getChild(ast.getChildCount() - 1)).getToken();
        final CharStream inputStream = nameToken.getInputStream();
        return inputStream.substring(nameToken.getStartIndex(), stopToken.getStopIndex());
    }
View Full Code Here

     */
    private String getTableAlteredSql(String sql, SqlJetAlterTableDef alterTableDef) throws SqlJetException {

        final RuleReturnScope parsedSQL = parseTable(sql);
        final CommonTree ast = (CommonTree) parsedSQL.getTree();
        final CommonToken nameToken = (CommonToken) ((CommonTree) ast.getChild(1)).getToken();
        final CharStream inputStream = nameToken.getInputStream();
        final CommonToken stopToken = (CommonToken) parsedSQL.getStop();

        final StringBuilder b = new StringBuilder();

        if (alterTableDef.getNewTableName() != null) {
            b.append(inputStream.substring(0, nameToken.getStartIndex() - 1));
            b.append(getAlterTableName(alterTableDef));
            b.append(inputStream.substring(nameToken.getStopIndex() + 1, stopToken.getStopIndex()));
        } else if (alterTableDef.getNewColumnDef() != null) {
            b.append(inputStream.substring(0, stopToken.getStartIndex() - 1));
            b.append(",").append(getAlterTableName(alterTableDef));
            b.append(inputStream.substring(stopToken.getStartIndex(), stopToken.getStopIndex()));
        } else {
            throw new SqlJetException("Wrong ALTER TABLE statement");
        }

        return b.toString();
View Full Code Here

     * @throws SqlJetException
     */
    private String getAlteredIndexSql(String sql, String alterTableName) throws SqlJetException {
        final RuleReturnScope parsedSQL = parseIndex(sql);
        final CommonTree ast = (CommonTree) parsedSQL.getTree();
        final CommonToken nameToken = (CommonToken) ((CommonTree) ast.getChild(2)).getToken();
        final CharStream inputStream = nameToken.getInputStream();
        final CommonToken stopToken = (CommonToken) parsedSQL.getStop();
        final StringBuilder b = new StringBuilder();
        b.append(inputStream.substring(0, nameToken.getStartIndex() - 1));
        b.append(alterTableName);
        b.append(inputStream.substring(nameToken.getStopIndex() + 1, stopToken.getStopIndex()));
        return b.toString();
    }
View Full Code Here

        public void valueChanged(TreeSelectionEvent treeSelectionEvent) {
          TreePath path = treeSelectionEvent.getNewLeadSelectionPath();
          if ( path==null ) return;
          CommonTree node = (CommonTree)treeSelectionEvent.getNewLeadSelectionPath().getLastPathComponent();
          //System.out.println("select AST: "+node);
          CommonToken a = (CommonToken)currentScope.st.impl.tokens.get(node.getTokenStartIndex());
          CommonToken b = (CommonToken)currentScope.st.impl.tokens.get(node.getTokenStopIndex());
          highlight(viewFrame.template, a.getStartIndex(), b.getStopIndex());
        }
      }
    );

    // Track selection of attr but do nothing for now
View Full Code Here

    if (tokenSource instanceof Lexer) {
      if (tokens.isEmpty())
        return "";
      Token lastToken = (Token) tokens.get(tokens.size() - 1);
      if (lastToken instanceof CommonToken) {
        CommonToken commonStop = (CommonToken) lastToken;
        CharStream charStream = ((Lexer) tokenSource).getCharStream();
        String result = charStream.substring(0, commonStop.getStopIndex());
        return result;
      }
    }
    return super.toString();
  }
View Full Code Here

    catch (Exception e) {
      // Xtext wants token to be CommonToken, INVALID_TOKEN_TYPE, and HIDDEN_CHANNEL
      String text = e.getLocalizedMessage();
      if (text == null)
        text = "simply " + e.getClass().getSimpleName();
      CommonToken ct = new CommonToken(Token.INVALID_TOKEN_TYPE,
          text);
      ct.setChannel(Token.HIDDEN_CHANNEL);
      if (prevToken != null) {
        int start = prevToken.getStopIndex() + 1;
        int stop = start + 1; // TODO: get more informative errors with length of token
        ct.setStartIndex(start);
        ct.setStopIndex(stop);
      }
      token = ct;
    }
    token.setTokenIndex(tokenIndex);
    if (symbol != null && symbol.hidden)
View Full Code Here

   * @throws Exception
   */
  public List<CommonToken> tokenize() throws Exception {
    List<CommonToken> symbols = new ArrayList<CommonToken>();
    while (true) {
      CommonToken token = (CommonToken)nextToken();
      if (Token.EOF == token.getType()) {
        break;
      } else {
        symbols.add(token);
      }
    }
View Full Code Here

    pushRoot(createNilTreeNode(id));
  }

  public void errorNode(int id, String text) {
    pushRoot(createTreeNode(id,
                new CommonToken(Token.INVALID_TOKEN_TYPE, text)));
  }
View Full Code Here

    public String getNodeLabel(TreeNode node) {
        if(node instanceof ParseTree) {
            Object payload = ((ParseTree)node).payload;
            if(payload instanceof CommonToken) {
                CommonToken t = (CommonToken)payload;
                return t.getText();
            } else {
                return payload.toString();
            }
        }
        return node.toString();
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.