Running a Strategy

The first example of running a Stratego strategy in the manual is that of evaluating an AST, via the prop-eval-rules module in Section 4.1 . In this repository, we’ve placed those rules in trans/prop-eval-rules.str, and the glue strategies that call them in trans/prop-eval.str. This latter module is imported by trans/spoofax_propositional_language.str.

(I am unclear on what triggers Editor Services to use this particular Stratego file, but in any automatically-generated Spoofax project there will be a main language Stratego file in the trans directory, and that’s the file from which the rule specified in an ESV action has to be visible.)

There’s an Editor Services module editor/Manual.esv to invoke the eval strategy, and it’s included in in editor/Main.esv.

With all of these elements in place, you should now be able to invoke the eval rule from the “Spoofax” menu. For example, to execute the “test1” example from the Spoofax Tutorial/Reference Section 4.1 , navigate to the file syntax/examples/sec4.1_test1.spl:

(1 -> 0 & 1) & 1
and select “Spoofax > Manual > prop-eval” from the menu bar to produce:
False()
You can do the same with test2:
(1 -> p & q) & p
to produce
And(And(Atom("p"), Atom("q")), Atom("p"))

Both of these results match the expected output of the eval transformation as shown in Section 4.1 .

One other note about the files provided in this repository. The “do-XXX” rule used as boilerplate glue between ESV and a Stratego strategy in trans/prop-eval.str is:

  // Interface eval strategy with editor services and file system
  do-eval: (selected, _, _, path, project-path) -> (filename, result)
    with filename := <guarantee-extension(|"eval.aterm")> path
       ; result   := <eval> selected

The version of this glue being used here corresponds to what’s used in the example Calc language project, but is slightly different from what is described in the Menus section of the ESV Manual. I am unclear on the significance of this difference or which form is “better” – I simply modeled this Stratego code after the code in the working Calc repository, and all seems to be well.