aspen-tree¶
aspen-tree analyzes and transforms programs written in any language with a tree-sitter grammar, with transformations written in answer set programming (ASP). It is mostly used for the clingo ASP language itself.
aspen-tree has two main functionality:
- Reify. Each source is parsed by tree-sitter, and its syntax tree
is turned into facts such as
node(3),type(3, "rule")andchild(3, 4). - Transform. A meta-encoding, an ordinary clingo program over
these facts, derives terms like
aspen(replace(node(N), "c"))that describe edits of the source text, and messages to report via printing, exceptions or logging.
The edits defined via a transformation are applied to the text, so everything not edited (layout,
comments) stays as it was. For example, renaming the identifier b to
c in a clingo program takes one rule:
$ printf 'a :- b.\nb.\n' | aspen transform - -l clingo \
-s 'aspen(replace(node(N), "c")) :- type(N, "identifier"), leaf_text(N, "b").'
a :- c.
c.
- Getting started explains installation and the command line and Python interfaces.
- Examples shows common kinds of transformations.
- The reference describes the fact representation, the meta-encoding interface and the bundled encodings, such as one compiling away the pools of clingo programs.
Info
aspen-tree is part of the Potassco suite.