Description

An asfix to asfix tool that reserves comments that were of the input source code by putting them in annotations of the AST.

It is difficult to decide what a comment actually comments on. The tool uses the heuristic that a comment is usually about the next construct. Therefore, it adds the comment to the first term with a constructor in the the subtree of the next symbol in the production rule. If this next symbol is a literal, then the comment will not be preserved.

Example

This simple tool works remarkably well. Let me illustrate this with an example input that I used during the development of this tool.

  /**
   * Voodoo
   */
  class Voodoo
  {
    /**
     * Bla bla
     */
    public void foo(/*let me explain this */ int x)
    {
      // just return
      return /* foo */ x;
    }
  }

An example fragment of the AST:

  Param([], Int, Id("x")){(Comment, "/*let me explain this */")}

The JavaFront pretty-printer has been extended to support these Comment annotations. The following pipe:

  sglr -2 -s CompilationUnit -p ~/wc/java-front/syn/v1.5/Java-15.tbl 
     -i ~/Foo.java
  | ./asfix-anno-comments
  | implode-asfix
  | pp-java

produces the following output:

  /**
   * Voodoo
   */
  class Voodoo
  {
    /**
     * Bla bla
     */
    public void foo(/*let me explain this */ int x)
    {
      // just return
      return /* foo */ x;
    }
  }

Revision: r1.2 - 28 Apr 2005 - 22:24 - Main.wiki
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