I have been struggling with using templates in my JAPE grammars. I was trying to use them in right hand side Java blocks but I understand now that they only work in normal JAPE constructs.
Works:
Phase: FooPhase
Input: Token
Options: control=Appelt
Template: variable_name = "testing"
Rule: foo_1
(
{Token.string == "foo"}
):annot
-->
:annot.Foo = {var_name = [variable_name]}
Doesn't work:
Phase: FooPhase
Input: Token
Options: control=Appelt
Template: variable_name = "testing"
Rule: foo_1
(
{Token.string == "foo"}
):annot
-->
: annot{
FeatureMap newFeatures = Factory.newFeatureMap();
newFeatures.put("var_name", [variable_name]);
outputAS.add(bindings.get("annot").firstNode(),bindings.get("annot").lastNode(),"Foo", newFeatures);
}