MPS 2019.1ヘルプ




The two following constructs will build identical nodes, the first one uses quotation, the second plan model API:

node<IntegerType> node = <int>; node<IntegerType> node2 = new node<IntegerType>();

Quotations as well as light quotations are defined int the jetbrains.mps.lang.quotation language. You need this language to be set as a used language in order to be able to use it in your models.

A quotation is an expression, whose value is the MPS node written inside the quotation. Think about a quotation as a "node literal", a construction similar to numeric constants and string literals. That is, you write a literal if you statically know what value do you mean. So inside a quotation you don't write an expression, which evaluates to a node, you rather write the node itself. For instance, an expression 2 + 3 evaluates to 5 , an expression < 2 + 3 > (angled braces being quotation braces) evaluates to a node プラス式 with leftOperand being an IntegerConstant 2 and rightOperand being an IntegerConstant 3 .

The following two constructs again create the same AST, now the quotation approach yields clear benefits in code brevity:

node<PlusExpression> node3 = <2 + 3>;    node<PlusExpression> node4 = new node<PlusExpression>();  node4.leftExpression = new node<IntegerConstant>();  node4.leftExpression : IntegerConstant.value = 2;  node4.rightExpression = new node<IntegerConstant>();  node4.rightExpression : IntegerConstant.value = 3;

Note that using quotation like <Car()> does not call the behavior constructor, while using the smodel constructor like new node<Car>() will do call it.



ただし、良いニュースは、ノードの大部分を静的に知っていて、いくつかの部分だけを動的に評価されたノードに置き換えたい場合には、引用符を使用できます。反引用符は、4つのタイプ( 参照財産、およびリストの 引用符)にすることができます。それらはすべて式を含み、それは動的に評価されて、引用されたノードの一部をその結果で置き換えます。子および参照の対引用符はノードに評価され、プロパティー対引用符は文字列に評価され、リスト対引用符はノードのリストに評価されます。


したがって、<ArrayList <%(computeMyTypeParameter())%>>という式を書きます。ここでの構成%(...)%は節の逆引用符です。





c) If you want to replace a child (or some more deeply located descendant), which is of a multiple-cardinality role, and if for that reason you may want to replace it not with a single node but rather with several ones, then use child list (simply list for brevity) antiquotations, *( ) . An expression inside a list antiquotation should return a list of nodes, that is of type * * nlist <..> * * or compatible type (i.e.* **{ } list <node <.. >> * * is ok, too, as well as some others). To write such an antiquotation, position your caret on a cell for a child inside a child collection and type " ". You cannot use it on an empty child collection, so before you press " " you have to enter a single child inside it.

d)クォートされたノードのプロパティー値を動的に計算された値で置き換えたい場合は、プロパティーantiquotation $()$を使用してください。引用符内の式は文字列を返す必要があります。これは、引用符付きノードの逆引用符付きプロパティーの値になります。このような引用符を書くには、プロパティーのセルにキャレットを置き、「$」と入力します。

Light quotations (quotation builders)

Using quotations has its downsides, though. For example, if you're creating quotations of a language in its own definition, you're creating a bootstrapping cycle that needs special treatment during language compilation (See Removing Bootstrapping Dependency ). Light quotations provide an alternative approach that will help you eliminate such issues.


The following two constructs, one using a quotation and the second using a light quotation are equivalent:

node<IntegerType> node1 = <int>;  node<IntegerType> node2 = <IntegerType()>;

Unlike direct model API usage, Light quotations remain conveniently usable for deeper hierarchies:

node<PlusExpression> node3 = <2 + 3>;  node<PlusExpression> node4 = <PlusExpression(    leftExpression: IntegerConstant(value: 2),    rightExpression: IntegerConstant(value: 3))>;
最終更新日: 2019年4月12日