当前位置: 首页>>代码示例>>C#>>正文


C# GrammarAST.GetAncestor方法代码示例

本文整理汇总了C#中Antlr4.Tool.Ast.GrammarAST.GetAncestor方法的典型用法代码示例。如果您正苦于以下问题:C# GrammarAST.GetAncestor方法的具体用法?C# GrammarAST.GetAncestor怎么用?C# GrammarAST.GetAncestor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Antlr4.Tool.Ast.GrammarAST的用法示例。


在下文中一共展示了GrammarAST.GetAncestor方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: A

        /**
         Make sure that action is last element in outer alt; here action,
         a2, z, and zz are bad, but a3 is ok:
         (RULE A (BLOCK (ALT {action} 'a')))
         (RULE B (BLOCK (ALT (BLOCK (ALT {a2} 'x') (ALT 'y')) {a3})))
         (RULE C (BLOCK (ALT 'd' {z}) (ALT 'e' {zz})))
         */
        protected virtual void CheckElementIsOuterMostInSingleAlt(GrammarAST tree)
        {
            CommonTree alt = (CommonTree)tree.Parent;
            CommonTree blk = (CommonTree)alt.Parent;
            bool outerMostAlt = blk.Parent.Type == RULE;
            ITree rule = tree.GetAncestor(RULE);
            string fileName = tree.Token.InputStream.SourceName;
            if (!outerMostAlt || blk.ChildCount > 1)
            {
                ErrorType e = ErrorType.LEXER_COMMAND_PLACEMENT_ISSUE;
                g.tool.errMgr.GrammarError(e,
                                           fileName,
                                           tree.Token,
                                           rule.GetChild(0).Text);

            }
        }
开发者ID:sharwell,项目名称:antlr4cs,代码行数:24,代码来源:BasicSemanticChecks.cs

示例2: RuleOption

 public override void RuleOption(GrammarAST ID, GrammarAST valueAST)
 {
     CheckOptions((GrammarAST)ID.GetAncestor(RULE), ID.Token, valueAST);
 }
开发者ID:sharwell,项目名称:antlr4cs,代码行数:4,代码来源:BasicSemanticChecks.cs

示例3: BlockOption

 public override void BlockOption(GrammarAST ID, GrammarAST valueAST)
 {
     CheckOptions((GrammarAST)ID.GetAncestor(BLOCK), ID.Token, valueAST);
 }
开发者ID:sharwell,项目名称:antlr4cs,代码行数:4,代码来源:BasicSemanticChecks.cs

示例4: TranslateLeftFactoredElement

        protected virtual GrammarAST TranslateLeftFactoredElement(GrammarAST element, string factoredRule, bool variant, DecisionFactorMode mode, bool includeFactoredElement)
        {
            if (mode == DecisionFactorMode.PARTIAL_UNFACTORED && includeFactoredElement)
            {
                throw new ArgumentException("Cannot include the factored element in unfactored alternatives.");
            }

            if (mode == DecisionFactorMode.COMBINED_FACTOR)
            {
                throw new InvalidOperationException("Cannot return a combined answer.");
            }

            Debug.Assert(!mode.IncludeFactoredAlts() || !mode.IncludeUnfactoredAlts());

            switch (element.Type)
            {
            case ANTLRParser.ASSIGN:
            case ANTLRParser.PLUS_ASSIGN:
                {
                    /* label=a
                     *
                     * ==>
                     *
                     * factoredElement label=a_factored
                     */

                    GrammarAST translatedChildElement = TranslateLeftFactoredElement((GrammarAST)element.GetChild(1), factoredRule, variant, mode, includeFactoredElement);
                    if (translatedChildElement == null)
                    {
                        return null;
                    }

                    RuleAST ruleAST = (RuleAST)element.GetAncestor(ANTLRParser.RULE);

#if false
                    LOGGER.log(Level.WARNING, "Could not left factor ''{0}'' out of decision in rule ''{1}'': labeled rule references are not yet supported.",
                        new object[] { factoredRule, ruleAST.GetChild(0).Text });
#endif

                    return null;
                    //if (!translatedChildElement.IsNil)
                    //{
                    //    GrammarAST root = (GrammarAST)adaptor.Nil();
                    //    object factoredElement = translatedChildElement;
                    //    if (outerRule)
                    //    {
                    //        adaptor.AddChild(root, factoredElement);
                    //    }

                    //    string action = string.Format("_localctx.{0} = (ContextType)_localctx.getParent().getChild(_localctx.getParent().getChildCount() - 1);", element.GetChild(0).Text);
                    //    adaptor.AddChild(root, new ActionAST(adaptor.CreateToken(ANTLRParser.ACTION, action)));
                    //    return root;
                    //}
                    //else
                    //{
                    //    GrammarAST root = (GrammarAST)adaptor.Nil();
                    //    object factoredElement = adaptor.DeleteChild(translatedChildElement, 0);
                    //    if (outerRule)
                    //    {
                    //        adaptor.AddChild(root, factoredElement);
                    //    }

                    //    adaptor.AddChild(root, element);
                    //    adaptor.ReplaceChildren(element, 1, 1, translatedChildElement);
                    //    return root;
                    //}
                }

            case ANTLRParser.RULE_REF:
                {
                    if (factoredRule.Equals(element.Token.Text))
                    {
                        if (!mode.IncludeFactoredAlts())
                        {
                            return null;
                        }

                        if (includeFactoredElement)
                        {
                            // this element is already left factored
                            return element;
                        }

                        GrammarAST root1 = (GrammarAST)adaptor.Nil();
                        root1.AddChild((ITree)adaptor.Create(TokenConstants.Epsilon, "EPSILON"));
                        root1.DeleteChild(0);
                        return root1;
                    }

                    Rule targetRule;
                    if (!_rules.TryGetValue(element.Token.Text, out targetRule))
                    {
                        return null;
                    }

                    RuleVariants ruleVariants = CreateLeftFactoredRuleVariant(targetRule, factoredRule);
                    switch (ruleVariants)
                    {
                    case RuleVariants.NONE:
                        if (!mode.IncludeUnfactoredAlts())
//.........这里部分代码省略.........
开发者ID:sharwell,项目名称:antlr4cs,代码行数:101,代码来源:LeftFactoringRuleTransformer.cs


注:本文中的Antlr4.Tool.Ast.GrammarAST.GetAncestor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。