Beispiel #1
0
 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());
 }
Beispiel #2
0
  /**
   * @param sql
   * @param alterTableDef
   * @return
   * @throws SqlJetException
   */
  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();
  }
Beispiel #3
0
 /**
  * @param alterTableDef
  * @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());
 }
Beispiel #4
0
 /**
  * @param sql
  * @param alterTableName
  * @return
  * @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();
 }
 public static LinkedListTree parseRegexpLiteral(
     LinkedListToken startMarker, AS3Lexer lexer, CharStream cs, LinkedListTokenStream stream)
     throws RecognitionException {
   String tail = cs.substring(cs.index(), cs.size() - 1);
   int initialTailLength = tail.length();
   RegexSimpleParser parser;
   try {
     parser = regexpParserOn(new StringReader(tail), stream);
   } catch (IOException e) {
     // TODO: better exception type?
     throw new RuntimeException(e);
   }
   LinkedListTree ast = AS3FragmentParser.tree(parser.regexpLiteral());
   tail = parser.getInputTail();
   // skip over the regexp in the original, underlying CharStream
   cs.seek(cs.index() + (initialTailLength - tail.length()));
   LinkedListTokenSource source = (LinkedListTokenSource) stream.getTokenSource();
   stream.setTokenSource(source); // cause any remembered RegexpSimple state to be dropped
   stream.scrub(1); // erase the subsequent token that the RegexpSimple parser got from this stream
   source.setDelegate(lexer);
   return ast;
 }