Stratego uses terms to represent the abstract syntax of programs or documents. A term consists of a constructor and a list of argument term. Sometimes it is useful to record additional information about a term without adapting its structure, i.e., creating a constructor with additional arguments. For this purpose terms can be annotated. Term annotation has the syntax
   t1 { t2 }
where term t2 is the annotation of term t1. By making the annotation a list, any number of annotations can be attached to a term. The annotations of a term can be retrieved in a pattern match and set in a build. For example, the following rule checks that the two subterms of the Plus have annotation Int and then attaches the annotation Int to the whole term:
  TypeCheck :
    Plus(e1{Int}, e2{Int}) -> Plus(e1, e2){Int}
Naturally, annotation matching and building can be done in the match ?t and build !t constructs. Also congruences over annotations are supported. Thus, if s1 and s2 are strategies, then s1{s2} is also a strategy, which applies s1 to the term and s2 to its annotation.

The GenericTermTraversal operators preserve annotations.

Support for TermAnnotations has been available from StrategoRelease07.

-- EelcoVisser - 07 Mar 2002


CategoryToDo? | LanguageExtensions

Revision: r1.5 - 23 Jan 2003 - 20:40 - MartinBravenboer
Stratego > TermAnnotation
Copyright © 1999-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback