2021-01-12 16:41:01 +00:00
|
|
|
Title: The Spoofax Propositional Language
|
2020-12-15 08:24:59 +00:00
|
|
|
|
2021-01-12 16:41:01 +00:00
|
|
|
# Stratego Transformations in the Spoofax Eclipse IDE
|
|
|
|
|
2021-01-14 18:19:35 +00:00
|
|
|
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.
|
2021-01-12 16:41:01 +00:00
|
|
|
|
2021-02-04 00:24:47 +00:00
|
|
|
This [Gitea repository](https://code.studioinfinity.org/glen/spoofax_prop)
|
|
|
|
provides a working implementation of most of the examples in the manual.
|
|
|
|
It can be cloned as an Eclipse project (note the git root
|
2021-01-22 17:29:57 +00:00
|
|
|
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, all of the examples from the Stratego Tutorial manual that employ the
|
|
|
|
propositional language (see below), starting from Section 4 on, can be executed
|
|
|
|
directly. This repository does not attempt to implement the portion of examples
|
|
|
|
dealing with an arithmetical/imperative language (except in a couple of
|
|
|
|
isolated instances in which the relevant phenomenon is recast in the
|
|
|
|
propositional language).
|
|
|
|
|
2021-01-14 18:19:35 +00:00
|
|
|
## 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).
|
2021-02-04 00:24:47 +00:00
|
|
|
Sometimes I have had difficulty getting the examples in this repository working
|
|
|
|
starting from plain Eclipse and installing Spoofax in it using the Spoofax
|
|
|
|
update site.
|
2021-01-14 18:19:35 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2021-01-12 16:41:01 +00:00
|
|
|
## Abstract syntax
|
|
|
|
|
2021-02-04 00:24:47 +00:00
|
|
|
With the preliminaries out of the way, note that the examples in the Stratego
|
|
|
|
manual deal exclusively with Abstract Syntax Trees (ASTs). The trees used
|
|
|
|
are primarily for a language concerning propositional logic, which we dub the
|
|
|
|
Spoofax Propositional Language (SPL). It is defined
|
2021-01-14 18:19:35 +00:00
|
|
|
at the top of {! docrefs/sec4.1.md !} of the manual.
|
|
|
|
It consists of the following signature of constructors:
|
2021-01-12 16:41:01 +00:00
|
|
|
|
|
|
|
```stratego
|
2021-01-15 17:57:30 +00:00
|
|
|
{! src-gen/signatures/Spoofax-Propositional-Language-sig.str extract:
|
2021-01-12 16:41:01 +00:00
|
|
|
start: '(signature[\s]*)$'
|
2021-01-15 17:57:30 +00:00
|
|
|
stop: '^(\s*Eq\s*:.*)'
|
2021-01-12 16:41:01 +00:00
|
|
|
!}
|
|
|
|
```
|
|
|
|
<!-- /md -->
|
2021-01-14 18:19:35 +00:00
|
|
|
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.
|
2021-01-22 17:29:57 +00:00
|
|
|
|
|
|
|
### Building the documentation
|
|
|
|
|
|
|
|
In order to build the documentation from a clone of this repository, you must
|
|
|
|
install [MkDocs](http://mkdocs.org) and the `semiliterate` plug-in for MkDocs,
|
|
|
|
which is available in
|
|
|
|
[pre-release form](https://code.studioinfinity.org/glen/mkdocs-semiliterate). Then
|
|
|
|
you can execute `mkdocs build` in the top-level directory of this project.
|