@Override
 public void checkValue(Context context, IValue value) throws PromptoError {
   Context child = context.newChildContext();
   child.registerValue(new Variable(new Identifier("value"), AnyType.instance()));
   child.setValue(new Identifier("value"), value);
   Object test = expression.interpret(child);
   if (!Boolean.TRUE.equals(test))
     throw new InvalidDataError(
         (value == null ? "null" : value.toString()) + " does not match:" + expression.toString());
 }
Пример #2
0
 private IValue evaluateItemIteratorNoIndex(IType elemType, Context context) throws PromptoError {
   IValue src = source.interpret(context);
   Iterator<IValue> iterator = getIterator(context, src);
   while (iterator.hasNext()) {
     Context child = context.newChildContext();
     child.registerValue(new Variable(v1, elemType));
     child.setValue(v1, iterator.next());
     IValue value = instructions.interpret(child);
     if (value != null) return value;
   }
   return null;
 }
Пример #3
0
 private void toPDialect(CodeWriter writer) {
   writer.append("for ");
   writer.append(v1);
   if (v2 != null) {
     writer.append(", ");
     writer.append(v2);
   }
   writer.append(" in ");
   source.toDialect(writer);
   writer.append(":");
   writer.newLine();
   writer.indent();
   instructions.toDialect(writer);
   writer.dedent();
 }
Пример #4
0
 private void toODialect(CodeWriter writer) {
   writer.append("for each (");
   writer.append(v1);
   if (v2 != null) {
     writer.append(", ");
     writer.append(v2);
   }
   writer.append(" in ");
   source.toDialect(writer);
   writer.append(")");
   boolean oneLine = instructions.size() == 1 && (instructions.get(0) instanceof SimpleStatement);
   if (!oneLine) writer.append(" {");
   writer.newLine();
   writer.indent();
   instructions.toDialect(writer);
   writer.dedent();
   if (!oneLine) {
     writer.append("}");
     writer.newLine();
   }
 }
Пример #5
0
 @Override
 public IValue interpret(Context context) throws PromptoError {
   IType srcType = source.check(context);
   IType elemType = srcType.checkIterator(context);
   return evaluateItemIterator(elemType, context);
 }
Пример #6
0
 @Override
 public IType check(Context context) throws SyntaxError {
   IType srcType = source.check(context);
   IType elemType = srcType.checkIterator(context);
   return checkItemIterator(elemType, context);
 }
 @Override
 public void toDialect(CodeWriter writer) {
   writer.append(" matching ");
   expression.toDialect(writer);
 }