Community
Participate
Working Groups
Currently we only support specifying formatting rules against the grammar. In many common situations it is needed or at least easier to define formatting based on the actual parsed model.
It would be great to have the current EObject from the semantic model available in the formatter. This would allow to make formatting decisions based on the values of EAttributes, the amounts of values within an EList, etc... To pass the current AbstractNode to the formatter would be possible, too, but one shouldn't expect too much from it: - At first, when the formatter is called by the ParseTreeConstructor, some tokens might bot have an AbstractNode. The ParseTreeConstructor is called when XtextResource.save() is called. Some tokens don't have an AbstractNode when the semantic model has been modified *after* it has been created by the parser. E.g. by applying a Quickfix. Furthermore, *no* token will have an AbstractNode if the semantic model has not been created by the parser (e.g. an M2M transformation, EMyPackageFactory or read from XMI). - At second, the node model isn't needed to "access state of the parser", i.e. to see how the current stack of rule calls looks like. This information is implicitly available since it is possible to assign formatting instructions to rule calls and parser rules. However, these changes, would break API, so it's probably to late for Helios.
This does work with the new formatter infrastructure.