Documented functions and controls in expression language.
Better error checking in operator calls. git-svn-id: http://google-refine.googlecode.com/svn/trunk@127 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
607fca04cb
commit
8992531d02
@ -1,6 +1,7 @@
|
||||
package com.metaweb.gridworks.commands.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
@ -22,6 +23,8 @@ public class GetExpressionLanguageInfoCommand extends Command {
|
||||
|
||||
try {
|
||||
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||
Properties options = new Properties();
|
||||
|
||||
writer.object();
|
||||
|
||||
writer.key("functions");
|
||||
@ -29,8 +32,7 @@ public class GetExpressionLanguageInfoCommand extends Command {
|
||||
{
|
||||
for (Entry<String, Function> entry : Parser.functionTable.entrySet()) {
|
||||
writer.key(entry.getKey());
|
||||
writer.object();
|
||||
writer.endObject();
|
||||
entry.getValue().write(writer, options);
|
||||
}
|
||||
}
|
||||
writer.endObject();
|
||||
@ -40,8 +42,7 @@ public class GetExpressionLanguageInfoCommand extends Command {
|
||||
{
|
||||
for (Entry<String, Control> entry : Parser.controlTable.entrySet()) {
|
||||
writer.key(entry.getKey());
|
||||
writer.object();
|
||||
writer.endObject();
|
||||
entry.getValue().write(writer, options);
|
||||
}
|
||||
}
|
||||
writer.endObject();
|
||||
|
@ -2,6 +2,8 @@ package com.metaweb.gridworks.expr;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
public interface Control {
|
||||
import com.metaweb.gridworks.Jsonizable;
|
||||
|
||||
public interface Control extends Jsonizable {
|
||||
public Object call(Properties bindings, Evaluable[] args);
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ package com.metaweb.gridworks.expr;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
public interface Function {
|
||||
import com.metaweb.gridworks.Jsonizable;
|
||||
|
||||
public interface Function extends Jsonizable {
|
||||
public Object call(Properties bindings, Object[] args);
|
||||
}
|
||||
|
@ -17,66 +17,40 @@ public class OperatorCallExpr implements Evaluable {
|
||||
args[i] = _args[i].evaluate(bindings);
|
||||
}
|
||||
|
||||
if (args.length == 2) {
|
||||
if (args[0] != null && args[1] != null) {
|
||||
if (args[0] instanceof Number && args[1] instanceof Number) {
|
||||
if ("+".equals(_op)) {
|
||||
if (args.length == 2) {
|
||||
if (args[0] instanceof Number && args[1] instanceof Number) {
|
||||
return ((Number) args[0]).doubleValue() + ((Number) args[1]).doubleValue();
|
||||
} else {
|
||||
return args[0].toString() + args[1].toString();
|
||||
}
|
||||
}
|
||||
} else if ("-".equals(_op)) {
|
||||
if (args.length == 2) {
|
||||
if (args[0] instanceof Number && args[1] instanceof Number) {
|
||||
return ((Number) args[0]).doubleValue() - ((Number) args[1]).doubleValue();
|
||||
}
|
||||
}
|
||||
} else if ("*".equals(_op)) {
|
||||
if (args.length == 2) {
|
||||
if (args[0] instanceof Number && args[1] instanceof Number) {
|
||||
return ((Number) args[0]).doubleValue() * ((Number) args[1]).doubleValue();
|
||||
}
|
||||
}
|
||||
} else if ("/".equals(_op)) {
|
||||
if (args.length == 2) {
|
||||
if (args[0] instanceof Number && args[1] instanceof Number) {
|
||||
return ((Number) args[0]).doubleValue() / ((Number) args[1]).doubleValue();
|
||||
}
|
||||
}
|
||||
} else if (">".equals(_op)) {
|
||||
if (args.length == 2) {
|
||||
if (args[0] instanceof Number && args[1] instanceof Number) {
|
||||
return ((Number) args[0]).doubleValue() > ((Number) args[1]).doubleValue();
|
||||
}
|
||||
}
|
||||
} else if (">=".equals(_op)) {
|
||||
if (args.length == 2) {
|
||||
if (args[0] instanceof Number && args[1] instanceof Number) {
|
||||
return ((Number) args[0]).doubleValue() >= ((Number) args[1]).doubleValue();
|
||||
}
|
||||
}
|
||||
} else if ("<".equals(_op)) {
|
||||
if (args.length == 2) {
|
||||
if (args[0] instanceof Number && args[1] instanceof Number) {
|
||||
return ((Number) args[0]).doubleValue() < ((Number) args[1]).doubleValue();
|
||||
}
|
||||
}
|
||||
} else if ("<=".equals(_op)) {
|
||||
if (args.length == 2) {
|
||||
if (args[0] instanceof Number && args[1] instanceof Number) {
|
||||
return ((Number) args[0]).doubleValue() <= ((Number) args[1]).doubleValue();
|
||||
}
|
||||
}
|
||||
} else if ("==".equals(_op)) {
|
||||
if (args.length == 2) {
|
||||
|
||||
if ("+".equals(_op)) {
|
||||
return args[0].toString() + args[1].toString();
|
||||
}
|
||||
}
|
||||
|
||||
if ("==".equals(_op)) {
|
||||
if (args[0] != null) {
|
||||
return args[0].equals(args[1]);
|
||||
} else {
|
||||
return args[1] == null;
|
||||
}
|
||||
}
|
||||
} else if ("!=".equals(_op)) {
|
||||
if (args.length == 2) {
|
||||
if (args[0] != null) {
|
||||
return !args[0].equals(args[1]);
|
||||
} else {
|
||||
|
@ -4,6 +4,9 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Control;
|
||||
import com.metaweb.gridworks.expr.Evaluable;
|
||||
import com.metaweb.gridworks.expr.VariableExpr;
|
||||
@ -50,4 +53,15 @@ public class ForEach implements Control {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value(
|
||||
"Evaluates expression a to an array. Then for each array element, binds its value to variable name v, evaluates expression e, and pushes the result onto the result array."
|
||||
);
|
||||
writer.key("params"); writer.value("expression a, variable v, expression e");
|
||||
writer.key("returns"); writer.value("array");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.controls;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Control;
|
||||
import com.metaweb.gridworks.expr.Evaluable;
|
||||
import com.metaweb.gridworks.expr.ExpressionUtils;
|
||||
@ -36,4 +39,16 @@ public class ForNonBlank implements Control {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value(
|
||||
"Evaluates expression o. If it is non-blank, binds its value to variable name v, evaluates expression eNonBlank and returns the result. " +
|
||||
"Otherwise (if o evaluates to blank), evaluates expression eBlank and returns that result instead."
|
||||
);
|
||||
writer.key("params"); writer.value("expression o, variable v, expression eNonBlank, expression eBlank");
|
||||
writer.key("returns"); writer.value("Depends on actual arguments");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.controls;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Control;
|
||||
import com.metaweb.gridworks.expr.Evaluable;
|
||||
import com.metaweb.gridworks.expr.ExpressionUtils;
|
||||
@ -21,4 +24,16 @@ public class If implements Control {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value(
|
||||
"Evaluates expression o. If it is true, evaluates expression eTrue and returns the result. " +
|
||||
"Otherwise, evaluates expression eFalse and returns that result instead."
|
||||
);
|
||||
writer.key("params"); writer.value("expression o, expression eTrue, expression eFalse");
|
||||
writer.key("returns"); writer.value("Depends on actual arguments");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.controls;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Control;
|
||||
import com.metaweb.gridworks.expr.Evaluable;
|
||||
import com.metaweb.gridworks.expr.VariableExpr;
|
||||
@ -33,4 +36,15 @@ public class With implements Control {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value(
|
||||
"Evaluates expression o and binds its value to variable name v. Then evaluates expression e and returns that result"
|
||||
);
|
||||
writer.key("params"); writer.value("expression o, variable v, expression eNonBlank, expression eBlank");
|
||||
writer.key("returns"); writer.value("Depends on actual arguments");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class And implements Function {
|
||||
@ -14,4 +17,14 @@ public class And implements Function {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("ANDs two boolean values");
|
||||
writer.key("params"); writer.value("boolean a, boolean b");
|
||||
writer.key("returns"); writer.value("boolean");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class Ceil implements Function {
|
||||
@ -13,4 +16,13 @@ public class Ceil implements Function {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the ceiling of a number");
|
||||
writer.key("params"); writer.value("number d");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class EndsWith implements Function {
|
||||
@ -17,4 +20,13 @@ public class EndsWith implements Function {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns whether s ends with sub");
|
||||
writer.key("params"); writer.value("string s, string sub");
|
||||
writer.key("returns"); writer.value("boolean");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class Floor implements Function {
|
||||
@ -13,4 +16,14 @@ public class Floor implements Function {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the floor of a number");
|
||||
writer.key("params"); writer.value("number d");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
import com.metaweb.gridworks.expr.HasFields;
|
||||
|
||||
@ -75,4 +78,17 @@ public class Get implements Function {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value(
|
||||
"If o has fields, returns the field named 'from' of o. " +
|
||||
"If o is an array, returns o[from, to]. " +
|
||||
"if o is a string, returns o.substring(from, to)"
|
||||
);
|
||||
writer.key("params"); writer.value("o, number or string from, optional number to");
|
||||
writer.key("returns"); writer.value("Depends on actual arguments");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class IndexOf implements Function {
|
||||
@ -17,4 +20,13 @@ public class IndexOf implements Function {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the index of sub first ocurring in s");
|
||||
writer.key("params"); writer.value("string s, string sub");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.ExpressionUtils;
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
@ -11,4 +14,13 @@ public class IsBlank implements Function {
|
||||
return args.length == 0 || ExpressionUtils.isBlank(args[0]);
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns whether o is null or an empty string");
|
||||
writer.key("params"); writer.value("o");
|
||||
writer.key("returns"); writer.value("boolean");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.ExpressionUtils;
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
@ -11,4 +14,13 @@ public class IsNotBlank implements Function {
|
||||
return args.length > 0 && !ExpressionUtils.isBlank(args[0]);
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns whether o is not null and not an empty string");
|
||||
writer.key("params"); writer.value("o");
|
||||
writer.key("returns"); writer.value("boolean");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class IsNotNull implements Function {
|
||||
@ -10,4 +13,13 @@ public class IsNotNull implements Function {
|
||||
return args.length > 0 && args[0] != null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns whether o is not null");
|
||||
writer.key("params"); writer.value("o");
|
||||
writer.key("returns"); writer.value("boolean");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class IsNull implements Function {
|
||||
@ -10,4 +13,13 @@ public class IsNull implements Function {
|
||||
return args.length == 0 || args[0] == null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns whether o is null");
|
||||
writer.key("params"); writer.value("o");
|
||||
writer.key("returns"); writer.value("boolean");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class Join implements Function {
|
||||
@ -33,4 +36,13 @@ public class Join implements Function {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the string obtained by joining the array a with the separator sep");
|
||||
writer.key("params"); writer.value("array a, string sep");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class LastIndexOf implements Function {
|
||||
@ -17,4 +20,14 @@ public class LastIndexOf implements Function {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the index of sub last ocurring in s");
|
||||
writer.key("params"); writer.value("string s, string sub");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class Length implements Function {
|
||||
@ -23,4 +26,13 @@ public class Length implements Function {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the length of o");
|
||||
writer.key("params"); writer.value("array or string o");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class Ln implements Function {
|
||||
@ -13,4 +16,13 @@ public class Ln implements Function {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the natural log of n");
|
||||
writer.key("params"); writer.value("number n");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class Log implements Function {
|
||||
@ -13,4 +16,13 @@ public class Log implements Function {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the base 10 log of n");
|
||||
writer.key("params"); writer.value("number n");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class Max implements Function {
|
||||
@ -15,4 +18,13 @@ public class Max implements Function {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the greater of two numbers");
|
||||
writer.key("params"); writer.value("number a, number b");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class Min implements Function {
|
||||
@ -15,4 +18,13 @@ public class Min implements Function {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the smaller of two numbers");
|
||||
writer.key("params"); writer.value("number a, number b");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class Mod implements Function {
|
||||
@ -16,4 +19,13 @@ public class Mod implements Function {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns a modulus b");
|
||||
writer.key("params"); writer.value("number a, number b");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class Not implements Function {
|
||||
@ -17,4 +20,14 @@ public class Not implements Function {
|
||||
return o == null ? false : (
|
||||
(o instanceof Boolean) ? ((Boolean) o).booleanValue() : Boolean.parseBoolean(o.toString()));
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the opposite of b");
|
||||
writer.key("params"); writer.value("boolean b");
|
||||
writer.key("returns"); writer.value("boolean");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class Or implements Function {
|
||||
@ -14,4 +17,14 @@ public class Or implements Function {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns a OR b");
|
||||
writer.key("params"); writer.value("boolean a, boolean b");
|
||||
writer.key("returns"); writer.value("boolean");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class Replace implements Function {
|
||||
@ -19,4 +22,14 @@ public class Replace implements Function {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the string obtained by replacing f with r in s");
|
||||
writer.key("params"); writer.value("string s, string f, string r");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class Round implements Function {
|
||||
@ -13,4 +16,13 @@ public class Round implements Function {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns n rounded");
|
||||
writer.key("params"); writer.value("number n");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class Slice implements Function {
|
||||
@ -59,4 +62,16 @@ public class Slice implements Function {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value(
|
||||
"If o is an array, returns o[from, to]. " +
|
||||
"if o is a string, returns o.substring(from, to)"
|
||||
);
|
||||
writer.key("params"); writer.value("o, number from, optional number to");
|
||||
writer.key("returns"); writer.value("Depends on actual arguments");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class Split implements Function {
|
||||
@ -17,4 +20,13 @@ public class Split implements Function {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the array of strings obtained by splitting s with separator sep");
|
||||
writer.key("params"); writer.value("string s, string sep");
|
||||
writer.key("returns"); writer.value("array");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class StartsWith implements Function {
|
||||
@ -16,5 +19,13 @@ public class StartsWith implements Function {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns whether s starts with sub");
|
||||
writer.key("params"); writer.value("string s, string sub");
|
||||
writer.key("returns"); writer.value("boolean");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class ToLowercase implements Function {
|
||||
@ -14,4 +17,13 @@ public class ToLowercase implements Function {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns s converted to lowercase");
|
||||
writer.key("params"); writer.value("string s");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class ToNumber implements Function {
|
||||
@ -13,4 +16,14 @@ public class ToNumber implements Function {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns o converted to a number");
|
||||
writer.key("params"); writer.value("o");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class ToString implements Function {
|
||||
@ -13,4 +16,14 @@ public class ToString implements Function {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns o converted to a string");
|
||||
writer.key("params"); writer.value("o");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class ToTitlecase implements Function {
|
||||
@ -28,4 +31,14 @@ public class ToTitlecase implements Function {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns s converted to titlecase");
|
||||
writer.key("params"); writer.value("string s");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class ToUppercase implements Function {
|
||||
@ -14,4 +17,13 @@ public class ToUppercase implements Function {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns s converted to uppercase");
|
||||
writer.key("params"); writer.value("string s");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -81,18 +81,32 @@ ExpressionPreviewDialog.prototype._renderHelpTab = function() {
|
||||
ExpressionPreviewDialog.prototype._renderHelp = function(data) {
|
||||
var elmt = this._elmts.helpTabBody.empty();
|
||||
|
||||
$('<h3></h3>').text("Functions").appendTo(elmt);
|
||||
var renderEntry = function(table, name, entry) {
|
||||
var tr0 = table.insertRow(table.rows.length);
|
||||
var tr1 = table.insertRow(table.rows.length);
|
||||
var tr2 = table.insertRow(table.rows.length);
|
||||
|
||||
var ul = $('<ul></ul>').appendTo(elmt);
|
||||
for (var n in data.functions) {
|
||||
$('<li></li>').text(n).appendTo(ul);
|
||||
}
|
||||
$(tr0.insertCell(0)).text(name);
|
||||
$(tr0.insertCell(1)).text("(" + entry.params + ")");
|
||||
|
||||
$(tr1.insertCell(0));
|
||||
$(tr1.insertCell(1)).text("returns: " + entry.returns);
|
||||
|
||||
$(tr2.insertCell(0));
|
||||
$(tr2.insertCell(1)).text(entry.description);
|
||||
};
|
||||
|
||||
$('<h3></h3>').text("Functions").appendTo(elmt);
|
||||
var functionTable = $('<table width="100%"></table>').appendTo(elmt)[0];
|
||||
|
||||
$('<h3></h3>').text("Controls").appendTo(elmt);
|
||||
var controlTable = $('<table width="100%"></table>').appendTo(elmt)[0];
|
||||
|
||||
ul = $('<ul></ul>').appendTo(elmt);
|
||||
for (var n in data.functions) {
|
||||
renderEntry(functionTable, n, data.functions[n]);
|
||||
}
|
||||
for (var n in data.controls) {
|
||||
$('<li></li>').text(n).appendTo(ul);
|
||||
renderEntry(controlTable, n, data.controls[n]);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user