To parse the text as if the macros were replaced, you'd likely want to create a separate CodeDocument as your "working" document.
- Load the working document with the same text as the original document.
- Get a reference to the current snapshot as this will be important later.
- Replace the macros with their "real text".
- Allow the parser to run on the expanded document and generate any parse errors.
The important thing to keep in mind is that the offsets of your parse errors will not match the offsets of the original document since the text was changed with the macro replacement. This is why taking a snapshot before the replacement is important. You can use snapshot translation to convert the offset of any parse errors back to the equivalent offset before the macros were replaced.
Keep in mind, though, that snapshot translation is not a perfect solution since some of your parse errors might cover text ranges that are only present in the macro replacement and not in the original document. How you present those errors would be more complicated.
A creative alternative might be to use code outlining functionality to present your macros...
- Replace each macro with the equivalant text.
- Manually collapse that range of text as an outlined node.
- Set the collapsed text to match the name of the original macro text.
When all the nodes are collapsed, it would look like the original document where you see the macro text, not the code. But the user could choose to expand a macro to see the full text as it would appear in the final document. This would also allow you to present all parse errors at their reported offsets without having to translate back to the original document and would even allow the user to see any parse errors that might appear within the expanded macro. This approach may be difficult to support live editing, but could be used in a read-only scenario for full visualization of the document and any errors.