package com.alibaba.druid.sql.dialect.postgresql.parser;

import com.alibaba.druid.sql.lexer.Token;
import com.alibaba.druid.sql.parser.AbstractDeleteParser;
import com.alibaba.druid.sql.parser.SQLExprParser;
import com.dangdang.ddframe.rdb.sharding.api.rule.ShardingRule;

import java.util.List;

/**
 * PostgreSQL Delete语句解析器.
 *
 * @author zhangliang
 */
public final class PostgreSQLDeleteParser extends AbstractDeleteParser {
    
    public PostgreSQLDeleteParser(final ShardingRule shardingRule, final List<Object> parameters, final SQLExprParser exprParser) {
        super(shardingRule, parameters, exprParser);
    }
    
    @Override
    protected void skipBetweenDeleteAndTable() {
        getLexer().skipIfEqual(Token.FROM);
        getLexer().skipIfEqual(Token.ONLY);
    }
    
    @Override
    protected void skipBetweenTableAndWhere() {
        if (getLexer().skipIfEqual(Token.USING)) {
            while (true) {
                getExprParser().name();
                if (getLexer().equalToken(Token.COMMA)) {
                    getLexer().nextToken();
                    continue;
                }
                break;
            }
        }
    }
}

@@ -916,20 +916,10 @@
     
-while (true)
+do
  %7B%0A 
@@ -940,25 +940,25 @@
  get
-ExprParser().name
+Lexer().nextToken
 ();%0A
@@ -992,30 +992,29 @@
 r().
-equalToken
+skipIfEqual
 (Token.
-COMMA
+DOT
 )) %7B
@@ -1078,76 +1078,67 @@
     
-    continue;%0A                %7D%0A                break;%0A            %7D
+%7D%0A            %7D while (getLexer().equalToken(Token.COMMA));
 %0A   

refactor skipBetweenTableAndWhere for pg