Concrete Syntax Package
Stratego -- Strategies for Program Transformation
Description
The
concrete-syntax
package provides =parse-cs,
a generic program for parsing programs with embedded
concrete syntax. The program is parameterized with meta-data indicating
components for various aspects such as parsing, exploding,
desugaring, and pretty-printing. The meta data can be specified in
a .meta file specific for a program to be parsed, or it can be
associated with an extension and registered in an
XTC repository.
For example, the following is the contents of pl.meta, the
meta-data for Prolog programs with embedded syntax. The assumption
(in this example) is that syntax embeddings use a standard
(
ToTerm?) convention for indicating the boundary between meta- and
object-syntax.
Meta([
Syntax("Prolog"),
ParseTable("Prolog.tbl"),
Explode("prolog-explode"),
PrettyPrintTable("Prolog-pretty.pp.af")
])
This information can be overridden in a file specific .meta file
with the same extension. For example, the following indicates an
embedding of ABIR in Prolog and a specific desugaring tool for
this format:
Meta([
Syntax("PrologABIR"),
PostExplodeDesugar("abir-in-prolog-implode")
])
It overrides the syntax component, and adds a desugaring component.
In order to define such meta-data for a whole class of programs,
it can be defined in a meta file associated with a new
extension. For example, the following is the contents plabir.meta,
which defines all meta-data for preprocessing Prolog with embedded
ABIR in files with extension .plabir.
Meta([
Syntax("PrologABIR"),
Explode("prolog-explode"),
PostExplodeDesugar("abir-in-prolog-implode"),
PrettyPrintTable("Prolog-pretty.pp.af")
])
Concrete Syntax Tools
Parse-cs is the only tool provided by the package at the moment. Other
tools that might be provided in the future include:
- embed-syntax : combines two syntax definitions embedding one in the other by generating quotation productions and variable schemas according to a standard schema which might be adapted.
- gen-explode : a generic explosion transformation for embeddings that can be expressed locally (term-like API in host language) and generically
Implementation
Browse the implementation in the subversion repository:
The package is available in the
daily distribution of
StrategoXT and will be
available in
StrategoRelease094.
The instantiation of the tool for Prolog is available in the
PrologTools package.