本文整理汇总了C#中Antlr4.Tool.Ast.GrammarAST.GetAltLabel方法的典型用法代码示例。如果您正苦于以下问题:C# GrammarAST.GetAltLabel方法的具体用法?C# GrammarAST.GetAltLabel怎么用?C# GrammarAST.GetAltLabel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Antlr4.Tool.Ast.GrammarAST
的用法示例。
在下文中一共展示了GrammarAST.GetAltLabel方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: TokenRef
public override IList<SrcOp> TokenRef(GrammarAST ID, GrammarAST labelAST, GrammarAST args)
{
MatchToken matchOp = new MatchToken(this, (TerminalAST)ID);
if (labelAST != null)
{
string label = labelAST.Text;
RuleFunction rf = GetCurrentRuleFunction();
if (labelAST.Parent.Type == ANTLRParser.PLUS_ASSIGN)
{
// add Token _X and List<Token> X decls
DefineImplicitLabel(ID, matchOp); // adds _X
TokenListDecl l = GetTokenListLabelDecl(label);
rf.AddContextDecl(ID.GetAltLabel(), l);
}
else
{
Decl d = GetTokenLabelDecl(label);
matchOp.labels.Add(d);
rf.AddContextDecl(ID.GetAltLabel(), d);
}
// Decl d = getTokenLabelDecl(label);
// ((MatchToken)matchOp).labels.add(d);
// getCurrentRuleFunction().addContextDecl(ID.getAltLabel(), d);
// if ( labelAST.parent.getType() == ANTLRParser.PLUS_ASSIGN ) {
// TokenListDecl l = getTokenListLabelDecl(label);
// getCurrentRuleFunction().addContextDecl(ID.getAltLabel(), l);
// }
}
if (controller.NeedsImplicitLabel(ID, matchOp))
DefineImplicitLabel(ID, matchOp);
AddToLabelList listLabelOp = GetAddToListOpIfListLabelPresent(matchOp, labelAST);
return List(matchOp, listLabelOp);
}
示例3: DefineImplicitLabel
// support
public virtual void DefineImplicitLabel(GrammarAST ast, LabeledOp op)
{
Decl d;
if (ast.Type == ANTLRParser.SET || ast.Type == ANTLRParser.WILDCARD)
{
string implLabel =
GetTarget().GetImplicitSetLabel(ast.Token.TokenIndex.ToString());
d = GetTokenLabelDecl(implLabel);
((TokenDecl)d).isImplicit = true;
}
else if (ast.Type == ANTLRParser.RULE_REF)
{ // a rule reference?
Rule r = g.GetRule(ast.Text);
string implLabel = GetTarget().GetImplicitRuleLabel(ast.Text);
string ctxName =
GetTarget().GetRuleFunctionContextStructName(r);
d = new RuleContextDecl(this, implLabel, ctxName);
((RuleContextDecl)d).isImplicit = true;
}
else
{
string implLabel = GetTarget().GetImplicitTokenLabel(ast.Text);
d = GetTokenLabelDecl(implLabel);
((TokenDecl)d).isImplicit = true;
}
op.GetLabels().Add(d);
// all labels must be in scope struct in case we exec action out of context
GetCurrentRuleFunction().AddContextDecl(ast.GetAltLabel(), d);
}
示例4: GetChoiceBlock
public override Choice GetChoiceBlock(BlockAST blkAST, IList<CodeBlockForAlt> alts, GrammarAST labelAST)
{
int decision = ((DecisionState)blkAST.atnState).decision;
Choice c;
if (!g.tool.force_atn && AnalysisPipeline.Disjoint(g.decisionLOOK[decision]))
{
c = GetLL1ChoiceBlock(blkAST, alts);
}
else
{
c = GetComplexChoiceBlock(blkAST, alts);
}
if (labelAST != null)
{ // for x=(...), define x or x_list
string label = labelAST.Text;
Decl d = GetTokenLabelDecl(label);
c.label = d;
GetCurrentRuleFunction().AddContextDecl(labelAST.GetAltLabel(), d);
if (labelAST.Parent.Type == ANTLRParser.PLUS_ASSIGN)
{
string listLabel = GetTarget().GetListLabel(label);
TokenListDecl l = new TokenListDecl(this, listLabel);
GetCurrentRuleFunction().AddContextDecl(labelAST.GetAltLabel(), l);
}
}
return c;
}
示例5: Wildcard
public override IList<SrcOp> Wildcard(GrammarAST ast, GrammarAST labelAST)
{
Wildcard wild = new Wildcard(this, ast);
// TODO: dup with tokenRef
if (labelAST != null)
{
string label = labelAST.Text;
Decl d = GetTokenLabelDecl(label);
wild.labels.Add(d);
GetCurrentRuleFunction().AddContextDecl(ast.GetAltLabel(), d);
if (labelAST.Parent.Type == ANTLRParser.PLUS_ASSIGN)
{
TokenListDecl l = GetTokenListLabelDecl(label);
GetCurrentRuleFunction().AddContextDecl(ast.GetAltLabel(), l);
}
}
if (controller.NeedsImplicitLabel(ast, wild))
DefineImplicitLabel(ast, wild);
AddToLabelList listLabelOp = GetAddToListOpIfListLabelPresent(wild, labelAST);
return List(wild, listLabelOp);
}
示例6: Set
public override IList<SrcOp> Set(GrammarAST setAST, GrammarAST labelAST, bool invert)
{
MatchSet matchOp;
if (invert)
matchOp = new MatchNotSet(this, setAST);
else
matchOp = new MatchSet(this, setAST);
if (labelAST != null)
{
string label = labelAST.Text;
RuleFunction rf = GetCurrentRuleFunction();
if (labelAST.Parent.Type == ANTLRParser.PLUS_ASSIGN)
{
DefineImplicitLabel(setAST, matchOp);
TokenListDecl l = GetTokenListLabelDecl(label);
rf.AddContextDecl(setAST.GetAltLabel(), l);
}
else
{
Decl d = GetTokenLabelDecl(label);
matchOp.labels.Add(d);
rf.AddContextDecl(setAST.GetAltLabel(), d);
}
}
if (controller.NeedsImplicitLabel(setAST, matchOp))
DefineImplicitLabel(setAST, matchOp);
AddToLabelList listLabelOp = GetAddToListOpIfListLabelPresent(matchOp, labelAST);
return List(matchOp, listLabelOp);
}