Fixed issue 46: Array literals in GEL

git-svn-id: http://google-refine.googlecode.com/svn/trunk@833 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-05-20 17:49:20 +00:00
parent bf6ba51700
commit 0709ec3f92
3 changed files with 33 additions and 0 deletions

View File

@ -12,6 +12,7 @@ Fixes:
- Issue 28: "mql-like preview is not properly unquoting numbers" - Issue 28: "mql-like preview is not properly unquoting numbers"
- Issue 45: "Renaming Cells with Ctrl-Enter produced ERROR" - Issue 45: "Renaming Cells with Ctrl-Enter produced ERROR"
Tentative fix for a concurrent bug. Tentative fix for a concurrent bug.
- Issue 46: "Array literals in GEL"
Changes: Changes:
- Moved unit tests from JUnit to TestNG - Moved unit tests from JUnit to TestNG

View File

@ -0,0 +1,25 @@
package com.metaweb.gridworks.expr.functions.arrays;
import java.util.Properties;
import org.json.JSONException;
import org.json.JSONWriter;
import com.metaweb.gridworks.gel.Function;
public class ArgsToArray implements Function {
public Object call(Properties bindings, Object[] args) {
return args;
}
public void write(JSONWriter writer, Properties options)
throws JSONException {
writer.object();
writer.key("description"); writer.value("Returns all arguments passed to it as an array");
writer.key("params"); writer.value("a1, a2, ...");
writer.key("returns"); writer.value("array");
writer.endObject();
}
}

View File

@ -6,6 +6,7 @@ import java.util.regex.Pattern;
import com.metaweb.gridworks.expr.Evaluable; import com.metaweb.gridworks.expr.Evaluable;
import com.metaweb.gridworks.expr.ParsingException; import com.metaweb.gridworks.expr.ParsingException;
import com.metaweb.gridworks.expr.functions.arrays.ArgsToArray;
import com.metaweb.gridworks.gel.Scanner.NumberToken; import com.metaweb.gridworks.gel.Scanner.NumberToken;
import com.metaweb.gridworks.gel.Scanner.RegexToken; import com.metaweb.gridworks.gel.Scanner.RegexToken;
import com.metaweb.gridworks.gel.Scanner.Token; import com.metaweb.gridworks.gel.Scanner.Token;
@ -197,6 +198,12 @@ public class Parser {
} else { } else {
throw makeException("Missing )"); throw makeException("Missing )");
} }
} else if (_token.type == TokenType.Delimiter && _token.text.equals("[")) { // [ ... ] array
next(true); // swallow [
List<Evaluable> args = parseExpressionList("]");
eval = new FunctionCallExpr(makeArray(args), new ArgsToArray());
} else { } else {
throw makeException("Missing number, string, identifier, regex, or parenthesized expression"); throw makeException("Missing number, string, identifier, regex, or parenthesized expression");
} }