提交 695b8413 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Add strict parameter to Parser.readIfMore() and use this method in more places

上级 b92a913e
......@@ -794,8 +794,7 @@ public class Parser {
do {
Column column = readTableColumn(filter);
columns.add(column);
} while (readIf(","));
read(")");
} while (readIfMore(true));
read("=");
Expression expression = readExpression();
if (columns.size() == 1) {
......@@ -906,8 +905,7 @@ public class Parser {
column.sortType |= SortOrder.NULLS_LAST;
}
}
} while (readIf(","));
read(")");
} while (readIfMore(true));
return columns.toArray(new IndexColumn[0]);
}
......@@ -916,7 +914,7 @@ public class Parser {
do {
String columnName = readColumnIdentifier();
columns.add(columnName);
} while (readIfMore());
} while (readIfMore(false));
return columns.toArray(new String[0]);
}
......@@ -931,7 +929,7 @@ public class Parser {
column.getSQL());
}
columns.add(column);
} while (readIfMore());
} while (readIfMore(false));
}
return columns.toArray(new Column[0]);
}
......@@ -944,9 +942,16 @@ public class Parser {
return table.getColumn(id);
}
private boolean readIfMore() {
/**
* Read comma or closing brace.
*
* @param strict
* if {@code false} additional comma before brace is allowed
* @return {@code true} if comma is read, {@code false} if brace is read
*/
private boolean readIfMore(boolean strict) {
if (readIf(",")) {
return !readIf(")");
return strict || !readIf(")");
}
read(")");
return false;
......@@ -1110,7 +1115,7 @@ public class Parser {
} else {
values.add(readExpression());
}
} while (readIfMore());
} while (readIfMore(false));
}
command.addRow(values.toArray(new Expression[0]));
} while (readIf(","));
......@@ -1281,7 +1286,7 @@ public class Parser {
} else {
values.add(readExpression());
}
} while (readIfMore());
} while (readIfMore(false));
}
command.addRow(values.toArray(new Expression[0]));
// the following condition will allow (..),; and (..);
......@@ -1340,7 +1345,7 @@ public class Parser {
} else {
values.add(readExpression());
}
} while (readIfMore());
} while (readIfMore(false));
}
command.addRow(values.toArray(new Expression[0]));
} while (readIf(","));
......@@ -1476,8 +1481,7 @@ public class Parser {
String indexName = readIdentifierWithSchema();
Index index = table.getIndex(indexName);
indexNames.add(index.getName());
} while (readIf(","));
read(")");
} while (readIfMore(true));
}
return IndexHints.createUseIndexHints(indexNames);
}
......@@ -1503,8 +1507,7 @@ public class Parser {
ArrayList<String> derivedColumnNames = New.arrayList();
do {
derivedColumnNames.add(readAliasIdentifier());
} while (readIf(","));
read(")");
} while (readIfMore(true));
return derivedColumnNames;
}
return null;
......@@ -2722,8 +2725,7 @@ public class Parser {
ArrayList<Expression> params = New.arrayList();
do {
params.add(readExpression());
} while (readIf(","));
read(")");
} while (readIfMore(true));
Expression filterCondition;
if (readIf("FILTER")) {
read("(");
......@@ -2894,8 +2896,7 @@ public class Parser {
read("=");
function.setParameter(i, readExpression());
i++;
} while (readIf(","));
read(")");
} while (readIfMore(true));
TableFunction tf = (TableFunction) function;
tf.setColumns(columns);
break;
......@@ -2915,8 +2916,7 @@ public class Parser {
int i = 0;
do {
function.setParameter(i++, readExpression());
} while (readIf(","));
read(")");
} while (readIfMore(true));
}
}
function.doneWithParameters();
......@@ -4513,13 +4513,12 @@ public class Parser {
String enumerator0 = readString();
enumeratorList.add(enumerator0);
original += "'" + enumerator0 + "'";
while (readIf(",")) {
while (readIfMore(true)) {
original += ',';
String enumeratorN = readString();
original += "'" + enumeratorN + "'";
enumeratorList.add(enumeratorN);
}
read(")");
original += ')';
enumerators = enumeratorList.toArray(new String[0]);
}
......@@ -4839,10 +4838,7 @@ public class Parser {
columns.set(i, column);
row.add(expr);
i++;
} while (multiColumn && readIf(","));
if (multiColumn) {
read(")");
}
} while (multiColumn && readIfMore(true));
rows.add(row);
} while (readIf(","));
int columnCount = columns.size();
......@@ -6346,8 +6342,7 @@ public class Parser {
command.setIfNotExists(false);
do {
parseTableColumnDefinition(command, schema, tableName);
} while (readIf(","));
read(")");
} while (readIfMore(true));
} else {
boolean ifNotExists = readIfNotExists();
command.setIfNotExists(ifNotExists);
......@@ -6598,7 +6593,7 @@ public class Parser {
if (!readIf(")")) {
do {
parseTableColumnDefinition(command, schema, tableName);
} while (readIfMore());
} while (readIfMore(false));
}
}
// Allows "COMMENT='comment'" in DDL statements (MySQL syntax)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论