Kiama is a Scala library for language processing including attribute grammars, term rewriting, abstract state machines and pretty printing.
This is a simplification, enhancement and bug fix release cross-published for Scala 2.10, 2.11 and 2.12. It includes some API changes that may require source code changes in clients of the Tree
and Relation
components. It also includes major performance improvements in these components.
Kiama is now distributed under the Mozilla Public License, v. 2.0, rather than under the GNU Lesser General Public License.
Relation
: unapplySeq
replaces unapply
on relations and returns the image of the matched value as a sequence. The old usage of matching a single value and failing otherwise still works, since the pattern rel(x)
succeeds if the image contains one value. Since the whole image is now returned you can check for other image structures such as the empty image rel()
and one that contains at least one element rel(a, rest @ _*)
.
Relation
: the pair
extractor on relations now uses unapplySeq
. It returns the matched value and that value’s image in a single sequence. Thus, the pattern rel.pair(n, x, y)
succeeds if the matched value has a two-element image, binding n
to the matched value, x
to the first element of the image and y
to the second element of the image.
Relation
: API no longer contains uncommonly used relational operations (collect
, compose
, containsInRange
, index
, preImage
, preIndex
, projDomain
, projRange
, union
, withDomain
and withRange
).
Tree
: the constructor now has a shape
argument to specify constraints on the tree structure. The available shapes are: LeaveAlone
that means we assume the provided tree structure is ok, CheckTree
that causes a dynamic check that the structure is actually a tree and throws a StructureIsNotATreeException
if it isn’t, and EnsureTree
that ensures that the structure is a tree by cloning any shared nodes. By default, the shape
argument is LeaveAlone
which changes behaviour since shared node cloning was always performed in the previous version. If there is a chance that your structure is not already a tree, restore the previous behaviour by passing EnsureTree
. The rewriteTree
operation in the Rewriter
passes EnsureTree
by default since sharing often occurs after rewriting.
Tree
: old siblings
relation is now called sibling
which better matches the naming of relations such as child
.
Util
: simplify Memoiser
by removing use of traits and separate classes.
Relation
and Tree
: major performance improvements primarily due to replacing an embarrassing linear search with an identity-based cache to access relations.
Parsing
: distinguish between parser failures that are local and can be avoided by trying another alternative and parser errors that cause the parse to terminate without trying other alternatives. Added ~/
cut sequence operator that commits to the current alternative on the right. I.e., p1 ~/ p2
will return an error if p2
fails. In contrast, p1 ~ p2
fails if p2
fails. Similarly, added ~/>
and <~/
which are analogous to ~>
and <~
to ignore left and right side values, respectively. Added ‘nocut(p)’ to stop propagation of errors outward from within parser p
and commit(p)
to turn failures in p
into errors.
Util
: include message labels in sort criteria after message location so messages at the same location are now in a well-defined order.
Rewriter
: structures that contain case classes that extend AnyVal
are now rewritten correctly by unboxing the value where necessary.
Source.dropPrefix
:
** Avoid separator bug when dropping filename prefixes when there is no prefix.
** Don’t drop if there is a partial overlap.