Exemplo n.º 1
0
        public SemPred(OutputModelFactory factory, [NotNull] ActionAST ast)
            : base(factory, ast)
        {

            Debug.Assert(ast.atnState != null
                && ast.atnState.NumberOfTransitions == 1
                && ast.atnState.Transition(0) is AbstractPredicateTransition);

            GrammarAST failNode = ast.GetOptionAST("fail");
            predicate = ast.Text;
            if (predicate.StartsWith("{") && predicate.EndsWith("}?"))
            {
                predicate = predicate.Substring(1, predicate.Length - 3);
            }
            predicate = factory.GetTarget().GetTargetStringLiteralFromString(predicate);

            if (failNode == null)
                return;

            if (failNode is ActionAST)
            {
                ActionAST failActionNode = (ActionAST)failNode;
                RuleFunction rf = factory.GetCurrentRuleFunction();
                failChunks = ActionTranslator.TranslateAction(factory, rf,
                                                              failActionNode.Token,
                                                              failActionNode);
            }
            else
            {
                msg = factory.GetTarget().GetTargetStringLiteralFromANTLRStringLiteral(factory.GetGenerator(),
                                                                              failNode.Text,
                                                                              true);
            }
        }
Exemplo n.º 2
0
 protected SrcOp(OutputModelFactory factory, GrammarAST ast)
     : base(factory, ast)
 {
     if (ast != null)
         uniqueID = ast.Token.TokenIndex;
     enclosingBlock = factory.GetCurrentBlock();
     enclosingRuleRunction = factory.GetCurrentRuleFunction();
 }
Exemplo n.º 3
0
 protected SrcOp(OutputModelFactory factory, GrammarAST ast)
     : base(factory, ast)
 {
     if (ast != null)
     {
         uniqueID = ast.Token.TokenIndex;
     }
     enclosingBlock        = factory.GetCurrentBlock();
     enclosingRuleRunction = factory.GetCurrentRuleFunction();
 }
Exemplo n.º 4
0
 public MatchSet(OutputModelFactory factory, GrammarAST ast)
     : base(factory, ast)
 {
     SetTransition st = (SetTransition)ast.atnState.Transition(0);
     int wordSize = factory.GetGenerator().GetTarget().GetInlineTestSetWordSize();
     expr = new TestSetInline(factory, null, st.set, wordSize);
     Decl.Decl d = new TokenTypeDecl(factory, expr.varName);
     factory.GetCurrentRuleFunction().AddLocalDecl(d);
     capture = new CaptureNextTokenType(factory, expr.varName);
 }
Exemplo n.º 5
0
        public MatchSet(OutputModelFactory factory, GrammarAST ast)
            : base(factory, ast)
        {
            SetTransition st       = (SetTransition)ast.atnState.Transition(0);
            int           wordSize = factory.GetGenerator().GetTarget().GetInlineTestSetWordSize();

            expr = new TestSetInline(factory, null, st.set, wordSize);
            Decl.Decl d = new TokenTypeDecl(factory, expr.varName);
            factory.GetCurrentRuleFunction().AddLocalDecl(d);
            capture = new CaptureNextTokenType(factory, expr.varName);
        }
Exemplo n.º 6
0
 public Action(OutputModelFactory factory, ActionAST ast)
     : base(factory, ast)
 {
     RuleFunction rf = factory.GetCurrentRuleFunction();
     if (ast != null)
     {
         chunks = ActionTranslator.TranslateAction(factory, rf, ast.Token, ast);
     }
     else
     {
         chunks = new List<ActionChunk>();
     }
     //System.out.println("actions="+chunks);
 }
Exemplo n.º 7
0
        public Action(OutputModelFactory factory, ActionAST ast)
            : base(factory, ast)
        {
            RuleFunction rf = factory.GetCurrentRuleFunction();

            if (ast != null)
            {
                chunks = ActionTranslator.TranslateAction(factory, rf, ast.Token, ast);
            }
            else
            {
                chunks = new List <ActionChunk>();
            }
            //System.out.println("actions="+chunks);
        }
Exemplo n.º 8
0
 public Action(OutputModelFactory factory, StructDecl ctx, string action)
     : base(factory, null)
 {
     ActionAST ast = new ActionAST(new CommonToken(ANTLRParser.ACTION, action));
     RuleFunction rf = factory.GetCurrentRuleFunction();
     if (rf != null)
     { // we can translate
         ast.resolver = rf.rule;
         chunks = ActionTranslator.TranslateActionChunk(factory, rf, action, ast);
     }
     else
     {
         chunks = new List<ActionChunk>();
         chunks.Add(new ActionText(ctx, action));
     }
 }
Exemplo n.º 9
0
        public Action(OutputModelFactory factory, StructDecl ctx, string action)
            : base(factory, null)
        {
            ActionAST    ast = new ActionAST(new CommonToken(ANTLRParser.ACTION, action));
            RuleFunction rf  = factory.GetCurrentRuleFunction();

            if (rf != null)
            { // we can translate
                ast.resolver = rf.rule;
                chunks       = ActionTranslator.TranslateActionChunk(factory, rf, action, ast);
            }
            else
            {
                chunks = new List <ActionChunk>();
                chunks.Add(new ActionText(ctx, action));
            }
        }
Exemplo n.º 10
0
        public SemPred(OutputModelFactory factory, [NotNull] ActionAST ast)
            : base(factory, ast)
        {
            Debug.Assert(ast.atnState != null &&
                         ast.atnState.NumberOfTransitions == 1 &&
                         ast.atnState.Transition(0) is AbstractPredicateTransition);

            GrammarAST failNode = ast.GetOptionAST("fail");

            predicate = ast.Text;
            if (predicate.StartsWith("{") && predicate.EndsWith("}?"))
            {
                predicate = predicate.Substring(1, predicate.Length - 3);
            }
            predicate = factory.GetTarget().GetTargetStringLiteralFromString(predicate);

            if (failNode == null)
            {
                return;
            }

            if (failNode is ActionAST)
            {
                ActionAST    failActionNode = (ActionAST)failNode;
                RuleFunction rf             = factory.GetCurrentRuleFunction();
                failChunks = ActionTranslator.TranslateAction(factory, rf,
                                                              failActionNode.Token,
                                                              failActionNode);
            }
            else
            {
                msg = factory.GetTarget().GetTargetStringLiteralFromANTLRStringLiteral(factory.GetGenerator(),
                                                                                       failNode.Text,
                                                                                       true);
            }
        }