private QueryBuilderKraken parseCreate()
  {
    Token token;

    // TableBuilderKraken factory = null;// = _database.createTableFactory();

    if ((token = scanToken()) != Token.TABLE)
      throw error("expected TABLE at '{0}'", token);

    if ((token = scanToken()) != Token.IDENTIFIER)
      throw error("expected identifier at '{0}'", token);
    
    String name = _lexeme;
    String pod = null;
    
    while (peekToken() == Token.DOT) {
      scanToken();
      
      if ((token = scanToken()) != Token.IDENTIFIER) {
        throw error("expected identifier at '{0}'", token);
      }
    
      if (pod == null) {
        pod = name;
      }
      else {
        pod = pod + '.' + name;
      }
      
      name = _lexeme;
    }
    
    if (pod == null) {
      pod = getPodName();
    }

    TableBuilderKraken factory = new TableBuilderKraken(pod, name, _sql);
    // factory.startTable(_lexeme);

    if ((token = scanToken()) != Token.LPAREN) {
      throw error("expected '(' at '{0}'", token);
    }

    do {
      token = scanToken();

      switch (token) {
      case IDENTIFIER:
        parseCreateColumn(factory, _lexeme);
        break;

        /*
      case UNIQUE:
        token = scanToken();
        
        if (token != KEY) {
          _token = token;
        }
        
        factory.addUnique(parseColumnNames());
        break;
        */

      case PRIMARY:
        token = scanToken();
        if (token != Token.KEY)
          throw error("expected 'key' at {0}", token);

        factory.addPrimaryKey(parseColumnNames());
        break;

      case KEY:
        //String key = parseIdentifier();

        factory.addPrimaryKey(parseColumnNames()); // factory.addPrimaryKey(parseColumnNames());
        break;

        /*
      case CHECK:
        if ((token = scanToken()) != '(')
          throw error(L.l("Expected '(' at '{0}'", tokenName(token)));

        parseExpr();

        if ((token = scanToken()) != ')')
          throw error(L.l("Expected ')' at '{0}'", tokenName(token)));
        break;
        */

      default:
        throw error("unexpected token '{0}'", token);
      }

      token = scanToken();
    } while (token == Token.COMMA);

    if (token != Token.RPAREN) {
      throw error("expected ')' at '{0}'", token);
    }
    
    token = scanToken();
    
    HashMap<String,String> propMap = new HashMap<>();
    
    if (token == Token.WITH) {
      do {
        String key = parseIdentifier();
        ExprKraken expr = parseExpr();

        if (! (expr instanceof LiteralExpr)) {
          throw error("WITH expression must be a literal at '{0}'", expr);
        }
        
        String value = expr.evalString(null);
        
        propMap.put(key, value);
      } while ((token = scanToken()) == Token.COMMA);
    }
    
    if (token != Token.EOF) {
      throw error("Expected end of file at '{0}'", token);
    }

    return new CreateQueryBuilder(_tableManager, factory, _sql, propMap);
  }
private QueryBuilderKraken parseCreate ( ) { Token token ; if ( ( token = scanToken ( ) ) != Token . TABLE ) throw error ( "expected TABLE at '{0}'" , token ) ; if ( ( token = scanToken ( ) ) != Token . IDENTIFIER ) throw error ( "expected identifier at '{0}'" , token ) ; String name = _lexeme ; String pod = null ; while ( peekToken ( ) == Token . DOT ) { scanToken ( ) ; if ( ( token = scanToken ( ) ) != Token . IDENTIFIER ) { throw error ( "expected identifier at '{0}'" , token ) ; } if ( pod == null ) { pod = name ; } else { pod = pod + '.' + name ; } name = _lexeme ; } if ( pod == null ) { pod = getPodName ( ) ; } TableBuilderKraken factory = new TableBuilderKraken ( pod , name , _sql ) ; if ( ( token = scanToken ( ) ) != Token . LPAREN ) { throw error ( "expected '(' at '{0}'" , token ) ; } do { token = scanToken ( ) ; switch ( token ) { case IDENTIFIER : parseCreateColumn ( factory , _lexeme ) ; break ; case PRIMARY : token = scanToken ( ) ; if ( token != Token . KEY ) throw error ( "expected 'key' at {0}" , token ) ; factory . addPrimaryKey ( parseColumnNames ( ) ) ; break ; case KEY : factory . addPrimaryKey ( parseColumnNames ( ) ) ; break ; default : throw error ( "unexpected token '{0}'" , token ) ; } token = scanToken ( ) ; } while ( token == Token . COMMA ) ; if ( token != Token . RPAREN ) { throw error ( "expected ')' at '{0}'" , token ) ; } token = scanToken ( ) ; HashMap < String , String > propMap = new HashMap < > ( ) ; if ( token == Token . WITH ) { do { String key = parseIdentifier ( ) ; ExprKraken expr = parseExpr ( ) ; if ( ! ( expr instanceof LiteralExpr ) ) { throw error ( "WITH expression must be a literal at '{0}'" , expr ) ; } String value = expr . evalString ( null ) ; propMap . put ( key , value ) ; } while ( ( token = scanToken ( ) ) == Token . COMMA ) ; } if ( token != Token . EOF ) { throw error ( "Expected end of file at '{0}'" , token ) ; } return new CreateQueryBuilder ( _tableManager , factory , _sql , propMap ) ; }
Parses the create.