Пример #1
0
static modification
test_modification (int i) {
  switch (i) {
  case  0: return mod_assign (path (), "Hi");
  case  1: return mod_insert (path (), 0, tree (TUPLE, "a", "b"));
  case  2: return mod_remove (path (), 0, 2);
  case  3: return mod_split (path (), 0, 1);
  case  4: return mod_join (path (), 0);
  case  5: return mod_assign_node (path (), TUPLE);
  case  6: return mod_insert_node (path (), 1, tree (TUPLE, "a", "b"));
  case  7: return mod_remove_node (path (), 0);

  case  8: return mod_insert (path (), 1, tree (TUPLE, "a", "b"));
  case  9: return mod_insert (path (), 2, tree (TUPLE, "a", "b"));
  case 10: return mod_remove (path (), 1, 2);
  case 11: return mod_remove (path (), 2, 2);
  case 12: return mod_split (path (), 1, 2);
  case 13: return mod_split (path (), 2, 1);
  case 14: return mod_join (path (), 1);
  case 15: return mod_join (path (), 2);
  case 16: return mod_remove_node (path (), 1);
  case 17: return mod_remove_node (path (), 2);

  case 18: case 19: case 20: case 21: case 22: case 23: case 24: case 25:
    return path (0) * test_modification (i-18);
  case 26: case 27: case 28: case 29: case 30: case 31: case 32: case 33:
    return path (1) * test_modification (i-26);
  case 34: case 35: case 36: case 37: case 38: case 39: case 40: case 41:
    return path (2) * test_modification (i-34);
  default:
    FAILED ("not implemented");
    return mod_assign (path (), "");
  }
}
Пример #2
0
modification
invert (modification m, tree t) {
  ASSERT (is_applicable (t, m), "modification not applicable");
  path rp= root (m);
  switch (m->k) {
  case MOD_ASSIGN:
    return mod_assign (rp, copy (subtree (t, rp)));
  case MOD_INSERT:
    return mod_remove (rp, index (m), insert_length (m->t));
  case MOD_REMOVE:
    {
      int i= index (m);
      int n= argument (m);
      return mod_insert (rp, i, copy (insert_range (subtree (t, rp), i, n)));
    }
  case MOD_SPLIT:
    return mod_join (rp, index (m));
  case MOD_JOIN:
    {
      int  i= index (m);
      return mod_split (rp, i, insert_length (subtree (t, rp * i)));
    }
  case MOD_ASSIGN_NODE:
    return mod_assign_node (rp, L (subtree (t, rp)));
  case MOD_INSERT_NODE:
    return mod_remove_node (rp, argument (m));
  case MOD_REMOVE_NODE:
    {
      tree u= subtree (t, rp);
      int  i= index (m);
      return mod_insert_node (rp, i, copy (u (0, i) * u (i+1, N(u))));
    }
  case MOD_SET_CURSOR:
    return m;
  default:
    FAILED ("unexpected situation");
  }
}
Пример #3
0
 inline virtual modification get_inverse () {
   FAILED ("not a modification"); return mod_assign (path (), ""); }