Example #1
0
        // 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);
        }
Example #2
0
        public override bool NeedsImplicitLabel(GrammarAST ID, LabeledOp op)
        {
            Alternative currentOuterMostAlt = GetCurrentOuterMostAlt();
            bool        actionRefsAsToken   = currentOuterMostAlt.tokenRefsInActions.ContainsKey(ID.Text);
            bool        actionRefsAsRule    = currentOuterMostAlt.ruleRefsInActions.ContainsKey(ID.Text);

            return(op.GetLabels().Count == 0 && (actionRefsAsToken || actionRefsAsRule));
        }
        public virtual bool NeedsImplicitLabel(GrammarAST ID, LabeledOp op)
        {
            bool needs = @delegate.NeedsImplicitLabel(ID, op);

            foreach (CodeGeneratorExtension ext in extensions)
            {
                needs |= ext.NeedsImplicitLabel(ID, op);
            }
            return(needs);
        }
Example #4
0
        public virtual AddToLabelList GetAddToListOpIfListLabelPresent(LabeledOp op, GrammarAST label)
        {
            AddToLabelList labelOp = null;

            if (label != null && label.Parent.Type == ANTLRParser.PLUS_ASSIGN)
            {
                string listLabel = GetTarget().GetListLabel(label.Text);
                labelOp = new AddToLabelList(this, listLabel, op.GetLabels()[0]);
            }
            return(labelOp);
        }
 public virtual bool NeedsImplicitLabel(GrammarAST ID, LabeledOp op)
 {
     return false;
 }
 public virtual bool NeedsImplicitLabel(GrammarAST ID, LabeledOp op)
 {
     return(false);
 }
 public virtual bool NeedsImplicitLabel(GrammarAST ID, LabeledOp op)
 {
     bool needs = @delegate.NeedsImplicitLabel(ID, op);
     foreach (CodeGeneratorExtension ext in extensions)
         needs |= ext.NeedsImplicitLabel(ID, op);
     return needs;
 }
Example #8
0
 public virtual AddToLabelList GetAddToListOpIfListLabelPresent(LabeledOp op, GrammarAST label)
 {
     AddToLabelList labelOp = null;
     if (label != null && label.Parent.Type == ANTLRParser.PLUS_ASSIGN)
     {
         string listLabel = GetTarget().GetListLabel(label.Text);
         labelOp = new AddToLabelList(this, listLabel, op.GetLabels()[0]);
     }
     return labelOp;
 }
Example #9
0
        // 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);
        }
Example #10
0
 public override bool NeedsImplicitLabel(GrammarAST ID, LabeledOp op)
 {
     Alternative currentOuterMostAlt = GetCurrentOuterMostAlt();
     bool actionRefsAsToken = currentOuterMostAlt.tokenRefsInActions.ContainsKey(ID.Text);
     bool actionRefsAsRule = currentOuterMostAlt.ruleRefsInActions.ContainsKey(ID.Text);
     return op.GetLabels().Count == 0 && (actionRefsAsToken || actionRefsAsRule);
 }