This document explains some aspects of Spoofax that we got questions about. It also describes some common mistakes and pitfalls. Finally, it describes Spoofax' internals more in-depth, with the goal of clarifying some of its behaviour.
- Disambiguation tests. Disambiguation tests are tests of the form
test ... [[1+2+3]] parse to [[(1+2)+3]]
. SPT will parse both fragments and compare the ASTs. A common mistake is to introduce a constructor when parsing parenthesized expressions, e.g.Exp.Parens = <(<Exp>)>
. When you make this mistake, the AST for the second fragment will containParens
nodes and hence be different from the AST for the first fragment.
The solution is to not introduce a constructor. This is semantically cleaner anyway, as a Parens
node does not convey any semantic content (remember: the AST is a tree, not a string, and as such it already encodes what you would otherwise achieve by adding parenthesis). Spoofax will show an error "Missing bracket attribute or constructor name" whi