节点的位置?

时间:2014-04-11 14:10:20

标签: rascal

Rascal植根于术语重写。它是否具有术语/节点位置的内置支持,这通常在术语重写中定义,以便我可以在术语内或相反的方式查询子术语的位置?

1 个答案:

答案 0 :(得分:0)

我不认为明确的位置通常在术语重写的语义中定义,但是Rascal定义了各种术语的操作,使得位置是显式的或者可以是明确的。另请参阅http://www.rascal-mpl.org

上的手册

术语的主要操作是使用正常的一阶同余,深(高阶)匹配,负匹配,析取匹配等模式匹配:

if (and(and(_, _), _) := and(and(true(),false()), false())) // pattern match operator :=
  println("yes!"); 

and(true(), b) = b; // function definition, aka rewrite rule
and(false(), _) = false();

[ a | and(a,b) <- booleanList]; // comprehension with pattern as filter on a generator

innermost visit (t) { // explicit automated traversal with strategies
   case and(a,b) => or(a,b)
}

b.leftHandSide = true(); // assign new child term to the leftHandSide field of the term assigned to the b variable (non-destructively, you get a new b)
b[0] = false(); // same but to the anonymous first child.

如果使用字段标签定义了许多已排序的术语签名,则有正常的投影运算符,子term[0]上的索引和逐个名称:term.myChildName

如果你想知道一个子孩子在哪个位置,我可能会这样写:

int getPos(node t, value child) = [*pre, child, *_] := getChildren(t) ? size(pre) : -1;

但还有其他方法可以达到同样的效果。

Rascal没有指向一个词的父母。