How does Spoofax transform the source code to the target code?
Is there any reference for me to understand how Spoofax works step by step?
Asked by Guido Wachsmuth on 19 March 2013 at 04:50
2 Answers
When Spoofax loads your language, it performs the following two steps:
Spoofax loads your parse table. The location of the parse table and its start symbol are specified in
YourLanguage.main.esv:table : include/YourLanguage.tbl start symbols : StartThe parse table
include/YourLanguage.tblis generated from your syntax definition insyntax/YourLanguage.sdfwhen you build the project.Spoofax loads your compiled strategies and rewrite rules. The location of these are specified in
YourLanguage-Builders.esv:provider : include/yourlanguage.ctreeThe ctree file
include/yourlanguage.ctreeis generated fromtrans/yourlanguage.strwhen you build the project.When you edit a file, Spoofax performs the following steps:
Spoofax parses the file. Parse errors are shown in the editor.
Spoofax runs a static analysis on this file. Therefore, it calls a strategy, which needs to be specified in
editor/YourLanguage-Builders.esv:observer : editor-analyzeThe strategy must be implemented in
trans/yourlanguage.stror in modules which are imported into this module. It should return an analysed AST, a list of errors, a list of warnings, and a list of notes. The errors, warnings, and notes are shown in the editor.When you want to transform a file, you choose a builder from the Transform menu. This builder needs to be specified in
editor/YourLanguage-Builders.esv:builder : "Generate Java code" = editor-generate-javaThe corresponding strategy must be implemented in
trans/yourlanguage.stror in modules which are imported into this module. It should return a pair of file name and file content. Spoofax will apply this strategy to the analysed AST. If you want a builder to work on source ASTs, you need to add a(source)annotation. You can also run transformations when a file is saved. This also needs to be specified ineditor/YourLanguage-Builders.esv:Answered by Guido Wachsmuth on 19 March 2013 at 05:15on-save : editor-generate-java
If you are interested in more details, check our publications.
Answered by Guido Wachsmuth on 19 March 2013 at 05:35