/** Rules in tree grammar that use -> rewrites and are spitting out
* templates via output=template and then use rewrite=true must only
* use -> on alts that are simple nodes or trees or single rule refs
* that match either nodes or trees. The altAST is the ALT node
* for an ALT. Verify that its first child is simple. Must be either
* ( ALT ^( A B ) <end-of-alt> ) or ( ALT A <end-of-alt> ) or
* other element.
*
* Ignore predicates in front and labels.
*/
public virtual void EnsureAltIsSimpleNodeOrTree(GrammarAST altAST,
GrammarAST elementAST,
int outerAltNum)
{
if (IsValidSimpleElementNode(elementAST))
{
GrammarAST next = (GrammarAST)elementAST.Parent.GetChild(elementAST.ChildIndex + 1);
if (!IsNextNonActionElementEOA(next))
{
ErrorManager.GrammarWarning(ErrorManager.MSG_REWRITE_FOR_MULTI_ELEMENT_ALT,
grammar,
next.Token,
outerAltNum);
}
return;
}
switch (elementAST.Type)
{
case ANTLRParser.ASSIGN: // labels ok on non-rule refs
case ANTLRParser.PLUS_ASSIGN:
if (IsValidSimpleElementNode((GrammarAST)elementAST.GetChild(1)))
{
return;
}
break;
case ANTLRParser.ACTION: // skip past actions
case ANTLRParser.SEMPRED:
case ANTLRParser.SYN_SEMPRED:
case ANTLRParser.BACKTRACK_SEMPRED:
case ANTLRParser.GATED_SEMPRED:
EnsureAltIsSimpleNodeOrTree(altAST,
(GrammarAST)elementAST.Parent.GetChild(elementAST.ChildIndex + 1),
outerAltNum);
return;
}
ErrorManager.GrammarWarning(ErrorManager.MSG_REWRITE_FOR_MULTI_ELEMENT_ALT,
grammar,
elementAST.Token,
outerAltNum);
}