the source file is:

module example

entity User {
  name     : String
  password : String
  homepage : URL
}

entity BlogPosting {
  poster : User
  body   : String
}

entity URL {
  location : String
}

How can I generate three java entity files(URL.java,BlogPosting .java,User.java)?

Asked by ZJG on 19 March 2013 at 09:07
  1. Have a rule which translates an entity to a pair (filename, filecontent).
  2. Have a rule which translates a module (= a file) to a list of pairs [(filename1, filecontent1), (filename2, filecontent2), ...]
  3. Have a rule which takes a list of pairs and writes a file for each of them.

Useful strategies in this context are map and filter.

You can find an introduction to rewriting here and an introduction to code generation here.

Answered by Guido Wachsmuth on 19 March 2013 at 12:03

Note that an alternative answer is also in the original Spoofax FAQ.

Answered by Lennart Kats on 19 March 2013 at 18:57