本文整理汇总了C#中Antlr4.Tool.Ast.GrammarAST.GetFirstChildWithType方法的典型用法代码示例。如果您正苦于以下问题:C# GrammarAST.GetFirstChildWithType方法的具体用法?C# GrammarAST.GetFirstChildWithType怎么用?C# GrammarAST.GetFirstChildWithType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Antlr4.Tool.Ast.GrammarAST
的用法示例。
在下文中一共展示了GrammarAST.GetFirstChildWithType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InvokeRule
public InvokeRule(ParserFactory factory, GrammarAST ast, GrammarAST labelAST)
: base(factory, ast)
{
if (ast.atnState != null)
{
RuleTransition ruleTrans = (RuleTransition)ast.atnState.Transition(0);
stateNumber = ast.atnState.stateNumber;
}
this.name = ast.Text;
Rule r = factory.GetGrammar().GetRule(name);
ctxName = factory.GetTarget().GetRuleFunctionContextStructName(r);
// TODO: move to factory
RuleFunction rf = factory.GetCurrentRuleFunction();
if (labelAST != null)
{
// for x=r, define <rule-context-type> x and list_x
string label = labelAST.Text;
if (labelAST.Parent.Type == ANTLRParser.PLUS_ASSIGN)
{
factory.DefineImplicitLabel(ast, this);
string listLabel = factory.GetTarget().GetListLabel(label);
RuleContextListDecl l = new RuleContextListDecl(factory, listLabel, ctxName);
rf.AddContextDecl(ast.GetAltLabel(), l);
}
else
{
RuleContextDecl d = new RuleContextDecl(factory, label, ctxName);
labels.Add(d);
rf.AddContextDecl(ast.GetAltLabel(), d);
}
}
ActionAST arg = (ActionAST)ast.GetFirstChildWithType(ANTLRParser.ARG_ACTION);
if (arg != null)
{
argExprsChunks = ActionTranslator.TranslateAction(factory, rf, arg.Token, arg);
}
// If action refs rule as rulename not label, we need to define implicit label
if (factory.GetCurrentOuterMostAlt().ruleRefsInActions.ContainsKey(ast.Text))
{
string label = factory.GetTarget().GetImplicitRuleLabel(ast.Text);
RuleContextDecl d = new RuleContextDecl(factory, label, ctxName);
labels.Add(d);
rf.AddContextDecl(ast.GetAltLabel(), d);
}
}
示例2: HasImmediateRecursiveRuleRefs
/**
* Match (RULE RULE_REF (BLOCK (ALT .*) (ALT RULE_REF[self] .*) (ALT .*)))
* Match (RULE RULE_REF (BLOCK (ALT .*) (ALT (ASSIGN ID RULE_REF[self]) .*) (ALT .*)))
*/
public static bool HasImmediateRecursiveRuleRefs(GrammarAST t, string ruleName)
{
if (t == null)
return false;
GrammarAST blk = (GrammarAST)t.GetFirstChildWithType(BLOCK);
if (blk == null)
return false;
int n = blk.Children.Count;
for (int i = 0; i < n; i++)
{
GrammarAST alt = (GrammarAST)blk.Children[i];
ITree first = alt.GetChild(0);
if (first == null)
continue;
if (first.Type == ELEMENT_OPTIONS)
{
first = alt.GetChild(1);
if (first == null)
{
continue;
}
}
if (first.Type == RULE_REF && first.Text.Equals(ruleName))
return true;
ITree rref = first.GetChild(1);
if (rref != null && rref.Type == RULE_REF && rref.Text.Equals(ruleName))
return true;
}
return false;
}