diff --git a/.gitignore b/.gitignore index 0962a4d..8b845af 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ /site /.classpath +/.project /.settings /.factorypath diff --git a/.project b/.project deleted file mode 100644 index 4904686..0000000 --- a/.project +++ /dev/null @@ -1,48 +0,0 @@ - - - spoofax_prop - - - - - - org.eclipse.m2e.core.maven2Builder - - - - - org.metaborg.spoofax.eclipse.meta.builder.generatesources - clean,full, - - - - - org.metaborg.spoofax.eclipse.builder - - - - - org.metaborg.spoofax.eclipse.meta.builder.prejava - clean,full, - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.metaborg.spoofax.eclipse.meta.builder.postjava - clean,full, - - - - - - org.eclipse.m2e.core.maven2Nature - org.eclipse.jdt.core.javanature - org.metaborg.spoofax.eclipse.nature - org.metaborg.spoofax.eclipse.meta.nature - - diff --git a/README.md b/README.md index 35e6f73..1c13c00 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,63 @@ Title: The Spoofax Propositional Language -Next: syntax/Spoofax-Propositional-Language.sdf3 # Stratego Transformations in the Spoofax Eclipse IDE -The Stratego Tutorial/Reference {! docrefs/manual.md !} in the official Spoofax documentation presents a comprehensive overview of the Stratego approach to abstract syntax tree (AST) transformations. It employs a running example of an abstract syntax intended to represent classical Propositional Logic, which we will dub here the "Spoofax Propositional Language." The manual introduces the concepts of rules and strategies for applying them, and then shows how both of those facilities can be created from more primitive operations of term matching and replacement. Every step of the way is illustrated with actual, working Stratego programs. +The Stratego Tutorial/Reference {! docrefs/manual.md !} in the official Spoofax +documentation presents a comprehensive overview of the Stratego approach to +abstract syntax tree (AST) transformations. It employs a running example of an +abstract syntax intended to represent classical Propositional Logic, which we +will dub here the "Spoofax Propositional Language." The manual introduces the +concepts of rules and strategies for applying them, and then shows how both +of those facilities can be created from more primitive operations of +term matching and replacement. Every step of the way is illustrated with actual, +working Stratego programs. -There are, however, two catches for a newcomer trying to learn Spoofax and Stratego for the first time: +There are, however, two catches for a newcomer trying to learn Spoofax and +Stratego for the first time: -1. All of the examples are worked in an older framework ("Stratego/XT") which has a rather different collection of tools than the current implementation of Spoofax in the Eclipse IDE. -1. Unlike with the Calc example language used for the explication of the Syntax Definition Language SDF3, there does not seem to be any publicly available repository containing the worked examples to follow along with. +1. All of the examples are worked in an older framework ("Stratego/XT") which + has a rather different collection of tools than the current implementation + of Spoofax in the Eclipse IDE. +1. Unlike with the Calc example language used for the explication of the + Syntax Definition Language SDF3, there does not seem to be any publicly + available repository containing the worked examples to follow along with. This [Gitea repository](https://code.studioinfinity.org/glen/spoofax_prop) aims to fill both gaps. It can be cloned as an Eclipse project (note the git root is at the project level rather than in the directory above the project, as may be more common; in other words, this repository should be cloned within an existing Eclipse workspace, rather than as the workspace itself). Within that project, (ultimately) every example from the Stratego Tutorial manual starting from Section 4 on can be executed directly. And this (Mkdocs-generated) documentation seeks to clarify the ways that Stratego transformations may be run in the Spoofax/Eclipse IDE environment, serving as a supplement/replacement for the portions of the manual that were specific to Stratego/XT. +## Preliminaries + +I recommend working with a complete pre-built Eclipse installation of Spoofax +as provided by the Spoofax project, +for example one that you can download from their +[development release page](https://www.metaborg.org/en/latest/source/release/development.html). +I have been unable to get the examples in this repository working starting from +plain Eclipse and installing Spoofax in it using the Spoofax update site. + +If at any point in using the examples things appear to stop working, and +especially if the Spoofax menu item disappears or the Spoofax menu turns into +a thin white rectangle with no items to select, try the following: + +* Build the project and try again. +* Clean the workspace, and when it is done, build the project again and try + again. +* Right click on the project, select Maven > Update Project, make sure + everything is checked except "Offline" and + "Force update of Snapshots/Releases", and then click "OK". When it is done, + clean the workspace, then build the project and try again. +* If that still hasn't done it, restart (the Spoofax version of!) Eclipse and + clean the workspace, then build the project and try again. + +Running with a version of Spoofax _later_ than 2.5.13 (I was using a 2.6.0 +development snapshot), the Spoofax menu would always come back into proper +operation at some point in the above process. + ## Abstract syntax -Let's begin by recalling the abstract syntax of the Spoofax Propositional Language (SPL), as defined at the top of {! docrefs/sec4.1.md !} of the manual. It consists of the following signature of constructors: +With the preliminaries out of the way, let's begin delving into Stratego +transformations by recalling the abstract syntax of the +Spoofax Propositional Language (SPL), as defined +at the top of {! docrefs/sec4.1.md !} of the manual. +It consists of the following signature of constructors: ```stratego {! src-gen/signatures/Spoofax-Propositional-Language-sig.str --- @@ -23,4 +66,6 @@ Let's begin by recalling the abstract syntax of the Spoofax Propositional Langua !} ``` -Continue reading in the latest released [SPL documentation](http://studioinfinity.org/SPL) to see how to define and run Stratego transformations on ASTs of this language. +Continue reading in the latest released +[SPL documentation](http://studioinfinity.org/SPL) +to see how to define and run Stratego transformations on ASTs of this language. diff --git a/editor/Manual.esv b/editor/Manual.esv index a4613d7..0c773a8 100644 --- a/editor/Manual.esv +++ b/editor/Manual.esv @@ -1,7 +1,4 @@ module Manual - menus - menu: "Manual" (openeditor) - - action: "prop-eval" = do-eval + action: "prop-eval" = do-eval (source) diff --git a/trans/prop-eval-rules.str b/trans/prop-eval-rules.str index 8bfe6f4..1af7eaf 100644 --- a/trans/prop-eval-rules.str +++ b/trans/prop-eval-rules.str @@ -4,7 +4,7 @@ Title: Running a Strategy ## Running a Strategy The first example of running a Stratego strategy -in the {! ../docrefs/manual.md !} } is that of _evaluating_ an AST, +in the {! ../docrefs/manual.md !} is that of _evaluating_ an AST, via the `prop-eval-rules` module in {! ../docrefs/sec4.1.md !}. This page describes the most straightforward way to run this same strategy in the Spoofax Eclipse IDE. @@ -87,7 +87,7 @@ It's just the one line `Manual` in the `imports` section that we have added. The {! ../editor/Manual.esv !} ``` Note that the quoted string on the `action` line is the text label of the menu -item in the "Manual" submenu, and the identifier on its right-hand side is the +item in the "Manual" submenu, and the first identifier on its right-hand side is the Stratego action to call. But note that `do-eval` is not the same identifier as `eval` in our last Stratego file above. That's because the Stratego invocation caused by an ESV action item has a specific, multi-item argument list, whereas @@ -129,7 +129,15 @@ file `syntax/examples/sec4.1_test1.spl`: {! ../syntax/examples/sec4.1_test1.spl !} ``` and select "Spoofax > Manual > prop-eval" from the menu bar to produce: - -[CONTINUE HERE ONCE THIS WORKS] - +``` +{! ../syntax/examples/sec4.1_test1.eval.aterm !} +``` +You can do the same with test2: +```SPL +{! ../syntax/examples/sec4.1_test2.spl !} +``` +to produce +``` +{! ../syntax/examples/sec4.1_test2.eval.aterm !} +``` **/