|
|
Re: How to generate/serialize pretty printed HTML-output [message #1715776 is a reply to message #1715679] |
Thu, 26 November 2015 06:51 |
Bernd Hofner Messages: 68 Registered: July 2009 |
Member |
|
|
Good morning Christian,
Thank you for the hint. The puzzle pieces seem to be all there, but I still have problems to stick them together.
I had a closer look at the node tree and dumped a sample of it to the console. I have some difficulties to understand what I see.
First - it seems that the tree had a terrible radiation accident:
It contains two tree hierarchies at the same time, as a CompositeNode can have children AND leaves at the same time. To make matters worse to understand, a LeafNode can itself contain further leaves - these branching leaves must be a mutation due to too much radiation exposure.
In which order to I have to traverse - when to I go down the child hierarchy and when to step into the leaves hierarchy?
Next - the tree seems to contain the same information multiple times - in the parsed example file, the keyword "condition:" is contained once, but the dumped tree contains it four or five times. How to decide when to pick up the information in a node for serialization and when to ignore it?
I stumpled across a class NodeUtil - could it help to make sense of the tree?
Ciao, Bernd
[Updated on: Thu, 26 November 2015 06:53] Report message to a moderator
|
|
|
|
|
Re: How to generate/serialize pretty printed HTML-output [message #1715781 is a reply to message #1715779] |
Thu, 26 November 2015 08:24 |
Bernd Hofner Messages: 68 Registered: July 2009 |
Member |
|
|
This got me considerable forward.
Now I can iterate in the right order over the tree:
XtextResource resource= (XtextResource)me.eResource();
CompositeNode rootNode= resource.getParseResult().getRootNode();
Iterable<AbstractNode> nodes= NodeUtil.getAllContents(rootNode);
for(AbstractNode n : nodes) {
if (node instanceof LeafNode) {
TextFragment t= new TextFragment((LeafNode)node);
t.seralize();
}
}
And identify a lot of sematic data for each node:
public class TextFragment {
public String text;
boolean isKeyword= false;
boolean isWhitespace= false;
boolean isComment= false;
public TextFragment(LeafNode node) {
text= node.getText();
if (node.getGrammarElement() instanceof CrossReference) {
CrossReference ref = (CrossReference) node.getGrammarElement();
// TODO: The targets seem not to be filled
} else if (node.getGrammarElement() instanceof RuleCall) {
RuleCall rc = (RuleCall) node.getGrammarElement();
// TODO: some of the rule calls should be cross references...
} else if (node.getGrammarElement() instanceof Keyword) {
Keyword kw= (Keyword)node.getGrammarElement();
isKeyword= true;
} else if (node.getGrammarElement() instanceof TerminalRule) {
TerminalRule term= (TerminalRule)node.getGrammarElement();
if(term.getName().equals("WS")) {
isWhitespace= true;
}
else if( term.getName().equals("ML_COMMENT")
|| term.getName().equals("SL_COMMENT"))
{
isComment= true;
}
}
}
}
Resolving the cross references now seems to be the next hurdle.
It seems that the results of the linking are not reflected in the node tree.
What I mean is when I inspect the a node representing a cross reference,
the targets are empty - the reference references nothing?:
CrossReference ref = (CrossReference) node.getGrammarElement();
EList<EObject> targets= ref.eCrossReferences();
[Updated on: Thu, 26 November 2015 08:31] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03981 seconds