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

When Spoofax loads your language, it performs the following two steps:

  1. 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 : Start
    

    The parse table include/YourLanguage.tbl is generated from your syntax definition in syntax/YourLanguage.sdf when you build the project.

  2. Spoofax loads your compiled strategies and rewrite rules. The location of these are specified in YourLanguage-Builders.esv:

    provider : include/yourlanguage.ctree
    

    The ctree file include/yourlanguage.ctree is generated from trans/yourlanguage.str when you build the project.

When you edit a file, Spoofax performs the following steps:

  1. Spoofax parses the file. Parse errors are shown in the editor.

  2. 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-analyze
    

    The strategy must be implemented in trans/yourlanguage.str or 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-java

The corresponding strategy must be implemented in trans/yourlanguage.str or 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 in editor/YourLanguage-Builders.esv:

  on-save  :  editor-generate-java
Answered by Guido Wachsmuth on 19 March 2013 at 05:15

If you are interested in more details, check our publications.

Answered by Guido Wachsmuth on 19 March 2013 at 05:35