@Override
public Variable createVariableReference(final String name) {
-
for (final Device d : SingleDocument.this.devices) {
if (d.getName().equals(name)) {
return new Variable() {
public String getName() {
-
return name;
}
public Value getValue() {
-
return new DeviceValue(d);
}
}
public Type getType() {
-
return DeviceValue.TYPE;
}
};
}
}
-
return super.createVariableReference(name);
}
@Override
protected Value eval(Debugger dbg, Value[] args) {
-
if (!(args[0] instanceof DeviceValue)
|| !(args[1] instanceof StringValue)) {
throw new EvaluationException(
return new TypeVariable();
}
};
- } else if (name.equals("getLetters")) {
- if (arguments.length != 3) {
- throw new TypeException(
- "Wrong number of arguments in call to function getLetters()");
- }
- return new Function(name, arguments) {
-
- @Override
- protected Value eval(Debugger dbg, Value[] args) {
-
- if (!((args[0] instanceof ListValue)
- && (args[1] instanceof StringValue) && (args[2] instanceof IntValue))) {
- throw new EvaluationException(
- "Wrong type of arguments in call to function getLetters()");
- }
- String prefix = ((StringValue) args[1]).getString();
- int numLetters = (int) ((IntValue) args[2]).getInt();
- ListValue list = (ListValue) args[0];
- return SingleDocument.getPrefixLetters(list, prefix, numLetters);
- }
-
- @Override
- public Type getType() {
-
- Type.unify(arguments[0].getType(), new ListType(Type.String));
- Type.unify(arguments[1].getType(), Type.String);
- Type.unify(arguments[2].getType(), Type.Int);
-
- return new ListType(Type.String);
- }
- };
} else if (name.equals("isConnected")) {
if (arguments.length != 1) {
throw new TypeException(
@Override
protected Value eval(Debugger dbg, Value[] args) {
-
if (!(args[0] instanceof DeviceValue)) {
throw new EvaluationException(
"Wrong type of arguments in call to function isConnected()");
@Override
public Type getType() {
-
Type.unify(arguments[0].getType(), DeviceValue.TYPE);
return Type.Bool;
}
};
- } else if (name.equals("capitalize")) {
- if (arguments.length != 1) {
- throw new TypeException(
- "Wrong number of arguments in call to function capitalize()");
- }
- return new Function(name, arguments) {
-
- @Override
- protected Value eval(Debugger dbg, Value[] args) {
-
- if (!(args[0] instanceof ListValue)) {
- throw new EvaluationException(
- "Wrong type of arguments in call to function capitalize()");
- }
- ListValue list = (ListValue) args[0];
- Value result[] = new StringValue[list.size()];
- for (int i = 0; i < list.size(); i++) {
- String s = ((StringValue) list.get(i)).getString();
- // dont't use String.toUpperCase(), because it will
- // transform \u00df -> SS
- StringBuffer b = new StringBuffer(s.length());
- for (int j = 0; j < s.length(); j++) {
- b.append(Character.toUpperCase(s.charAt(j)));
- }
- result[i] = new StringValue(b.toString());
- }
-
- return new ListValue(result);
- }
-
- public Type getType() {
-
- Type.unify(arguments[0].getType(), new ListType(Type.String));
- return new ListType(Type.String);
- }
- };
} else if (name.equals("getNBestList")) {
if (arguments.length != 1) {
throw new TypeException(
return new Function(name, arguments) {
protected Value eval(Debugger dbg, Value[] args) {
-
if (!(args[0] instanceof StructValue)) {
throw new EvaluationException(
"Wrong type of arguments in call to function getNBestList()");
}
public Type getType() {
-
Type.unify(arguments[0].getType(), new StructType());
return new ListType(Type.String);
}
return new Function(name, arguments) {
protected Value eval(Debugger dbg, Value[] args) {
-
return new StringValue(SingleDocument.this.getTitle());
}
public Type getType() {
-
return Type.String;
}
};
return new Function(name, arguments) {
protected Value eval(Debugger dbg, Value[] args) {
-
File f = SingleDocument.this.getFile();
if (f == null) {
throw new EvaluationException("Error in getModelPath(): Model "
}
public Type getType() {
-
return Type.String;
}
};
return new Function(name, arguments) {
protected Value eval(Debugger dbg, Value[] args) {
-
String bundleName = ((StringValue) args[0]).getString();
String language = ((StringValue) args[1]).getString();
String templateName = ((StringValue) args[2]).getString();
}
public Type getType() {
-
return Type.String;
}
};
@Override
protected Value eval(Debugger dbg, Value[] args) {
-
String name = ((StringValue) args[0]).getString();
File f = SingleDocument.this.getFile();
}
SingleDocument.this.localizationBundles.put(name, bundle);
-
return Value.Void;
}
@Override
public Type getType() {
-
return Type.Void;
}
};
};
- static ListValue getPrefixLetters(ListValue words, String prefix,
- int numLetters) {
-
- int position = prefix.length();
- Set<String> letters = new HashSet<String>();
- for (int i = 0; i < words.size(); i++) {
- String s = ((StringValue) words.get(i)).getString();
- if (s.startsWith(prefix) && (s.length() > position)) {
- if (numLetters == -1) {
- letters.add(s.substring(position));
- } else {
- if (s.charAt(position) == ' ') {
- letters.add(" ");
- } else {
- StringBuilder b = new StringBuilder();
- for (int j = 0; (j < numLetters) && (position + j < s.length())
- && (s.charAt(position + j) != ' '); j++) {
- if (j > 0) {
- b.append(' ');
- }
- b.append(s.charAt(position + j));
- letters.add(b.toString());
- }
- }
- }
- /*
- * if (firstLetterOnly) { letters.add(s.substring(position,
- * position+1)); if (s.length() > position+1)
- * letters.add(s.substring(position, position+1) + " " +
- * s.substring(position+1, position+2)); } else
- * letters.add(s.substring(position));
- */
- }
- }
-
- StringValue s[] = new StringValue[letters.size()];
- int i = 0;
- for (String letter : new TreeSet<String>(letters)) {
- s[i++] = new StringValue(letter);
- }
-
- return new ListValue(s);
- }
-
public Environment getEnvironment(boolean local) {
-
return this.environment;
}
public Collection<Device> getDevices() {
-
return this.devices;
}
public PluginSettings getPluginSettings(Class<? extends Plugin> pluginClass) {
-
return this.pluginSettings.get(pluginClass);
}
public List<Grammar> getGrammars() {
-
return this.getOwnedGraph().getGrammars();
}
public Graph getSuperGraph() {
-
return null;
}
public Graph getOwnedGraph() {
-
return this.graph;
}
public String getGraphName() {
-
return this.getTitle();
}
public void setGraphName(String name) {
-
this.setTitle(name);
}
public Collection<SearchResult> find(NodeSearchFilter filter) {
-
return this.graph.find(filter);
}
}
* Return the length of string <code>s</code>
*/
public static IntValue length(StringValue s) {
-
return new IntValue(s.getString().length());
}
* Return the substring of <code>s</code> starting at <code>offset</code>
*/
public static StringValue substring(StringValue s, IntValue offset) {
-
return BuiltinFunctions.substring(s, offset, new IntValue(s.getString().length() - offset.getInt()));
}
* with length <code>length</code>
*/
public static StringValue substring(StringValue s, IntValue offset, IntValue length) {
-
long start = offset.getInt();
long end = start + length.getInt();
return new StringValue(s.getString().substring((int) start, (int) end));
* lowercase
*/
public static StringValue toLowerCase(StringValue s) {
-
return new StringValue(s.getString().toLowerCase());
}
* uppercase
*/
public static StringValue toUpperCase(StringValue s) {
-
return new StringValue(s.getString().toUpperCase());
}
* Return the nth character of <code>s</code> as a string
*/
public static StringValue charAt(StringValue s, IntValue index) {
-
return new StringValue(String.valueOf(s.getString().charAt(
(int) index.getInt())));
}
* Test whether <code>s</code> starts with <code>prefix</code>
*/
public static BoolValue startsWith(StringValue s, StringValue prefix) {
-
return new BoolValue(s.getString().startsWith(prefix.getString()));
}
* Test whether <code>s</code> ends with <code>suffix</code>
*/
public static BoolValue endsWith(StringValue s, StringValue suffix) {
-
return new BoolValue(s.getString().endsWith(suffix.getString()));
}
* Test whether <code>s</code> contains <code>infix</code>
*/
public static BoolValue contains(StringValue s, StringValue infix) {
-
return new BoolValue(s.getString().indexOf(infix.getString()) >= 0);
}
* <code>-1</code>.
*/
public static IntValue indexOf(StringValue s, StringValue infix) {
-
return new IntValue(s.getString().indexOf(infix.getString()));
}
* Test whether <code>s</code> can be converted to an <code>int</code>.
*/
public static BoolValue isInt(StringValue s) {
-
try {
Long.parseLong(s.getString());
return BoolValue.TRUE;
* Test whether <code>s</code> can be converted to a <code>real</code>.
*/
public static BoolValue isReal(StringValue s) {
-
try {
Double.parseDouble(s.getString());
return BoolValue.TRUE;
* <code>undefined</code> if conversion fails.
*/
public static IntValue parseInt(StringValue s) {
-
try {
return new IntValue(Long.parseLong(s.getString()));
} catch (NumberFormatException exn) {
* <code>undefined</code> if conversion fails.
*/
public static RealValue parseReal(StringValue s) {
-
try {
return new RealValue(Double.parseDouble(s.getString()));
} catch (NumberFormatException exn) {
* Convert to string
*/
public static StringValue str(Value v) {
-
if (v instanceof StringValue) {
return (StringValue) v;
} else if (v instanceof IntValue) {
* Return the absolute value of <code>i</code>
*/
public static IntValue abs(IntValue i) {
-
return new IntValue(Math.abs(i.getInt()));
}
* Returns Euler's number <i>e</i> raised to the power of <code>r</code>.
*/
public static RealValue exp(RealValue r) {
-
return new RealValue(Math.exp(r.getReal()));
}
* Returns the natural logarithm of <code>r</code>.
*/
public static RealValue log(RealValue r) {
-
return new RealValue(Math.log(r.getReal()));
}
* <code>max</code> including both.
*/
public static IntValue random(IntValue min, IntValue max) {
-
return new IntValue(min.getInt()
+ Math.round(Math.random() * (max.getInt() - min.getInt())));
}
* Round <code>r</code> to the nearest <code>int</code>
*/
public static IntValue round(RealValue r) {
-
return new IntValue(Math.round(r.getReal()));
}
* Returns the length of list <code>l</code>
*/
public static IntValue length(ListValue l) {
-
return new IntValue(l.size());
}
* Returns whether the list <code>l</code> is empty
*/
public static BoolValue empty(ListValue l) {
-
return new BoolValue(l.size() == 0);
}
* Returns the first (head) element of <code>l</code>
*/
public static Value head(ListValue l) {
-
if (l.size() == 0) {
throw new EvaluationException("head() called with empty list");
}
* Returns the nth element of <code>l</code>
*/
public static Value get(ListValue l, IntValue index) {
-
try {
return l.get((int) index.getInt());
} catch (IndexOutOfBoundsException exn) {
* Equivalent to <code>contains(list, v)</code>
*/
public static BoolValue member(ListValue list, Value v) {
-
for (int i = 0; i < list.size(); i++) {
if (list.get(i).equals(v)) {
return BoolValue.TRUE;
* Returns whether <code>l</code> contains <code>v</code>
*/
public static BoolValue contains(ListValue list, Value v) {
-
return BuiltinFunctions.member(list, v);
}
* <code>-1</code> if <code>list</code> does not contain <code>v</code>
*/
public static IntValue indexOf(ListValue list, Value v) {
-
for (int i = 0; i < list.size(); i++) {
if (list.get(i).equals(v)) {
return new IntValue(i);
* Return the sublist of <code>list</code> starting at <code>offset</code>
*/
public static ListValue sublist(ListValue list, IntValue offset) {
-
return list.subList((int) offset.getInt(), list.size());
}
*/
public static ListValue sublist(ListValue list, IntValue offset,
IntValue length) {
-
return list.subList((int) offset.getInt(), (int) (offset.getInt() + length
.getInt()));
}
* Return a reversed copy of <code>list</code>
*/
public static ListValue reverse(ListValue list) {
-
Value[] elems = new Value[list.size()];
for (int i = 0; i < elems.length; i++) {
elems[elems.length - i - 1] = list.get(i);
* must have the same type.
*/
public static ListValue sort(ListValue list) {
-
Value[] elements = new Value[list.size()];
for (int i = 0; i < list.size(); i++) {
elements[i] = list.get(i);
* Returns whether <code>str</code> contains a label named <code>key</code>
*/
public static BoolValue contains(StructValue str, StringValue key) {
-
if (str.containsLabel(key.getString())) {
return BoolValue.TRUE;
} else {
* <code>key</code>
*/
public static Value get(StructValue str, StringValue key) {
-
if (str.containsLabel(key.getString())) {
return str.getValue(key.getString());
} else {
* The counterpart to get(struct, string)
*/
public static StructValue put(StructValue str, StringValue key, Value value) {
-
return BuiltinFunctions.merge(str, new StructValue(new String[]{key
.getString()}, new Value[]{value}));
}
* <code>{ x={x=3, y=4}, y=5 }</code>
*/
public static StructValue merge(StructValue str1, StructValue str2) {
-
return StructValue.merge(str1, str2);
}
* in <code>str2</code> is not undefined.
*/
public static StructValue mergeDefined(StructValue str1, StructValue str2) {
-
return StructValue.mergeDefined(str1, str2);
}
* Return the current time as a structure <code>{ h:int, m:int }</code>
*/
public static StructValue currentTime() {
-
Calendar c = Calendar.getInstance();
return new StructValue(new String[]{"h", "m"}, new Value[]{
* and midnight, January 1, 1970 UTC.
*/
public static IntValue currentTimeMillis() {
-
return new IntValue(System.currentTimeMillis());
}
* Print a string representation of <code>v</code> to stdout.
*/
public static void print(Value v) {
-
if (v instanceof StringValue) {
System.out.println(((StringValue) v).getString());
} else {
}
public static void error(StringValue message) {
-
throw new EvaluationException(message.getString());
}
}
public static ListValue stripSpecialCharacters(ListValue list) {
-
Value[] stripped = new Value[list.size()];
int n = 0;
for (Value element : list) {
}
public static StringValue trim(StringValue v) {
-
return new StringValue(v.getString().trim());
}
}