コード例 #1
0
ファイル: SemPred.cs プロジェクト: sharwell/antlr4cs
        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);
            }
        }
コード例 #2
0
ファイル: SrcOp.cs プロジェクト: sharwell/antlr4cs
 protected SrcOp(OutputModelFactory factory, GrammarAST ast)
     : base(factory, ast)
 {
     if (ast != null)
         uniqueID = ast.Token.TokenIndex;
     enclosingBlock = factory.GetCurrentBlock();
     enclosingRuleRunction = factory.GetCurrentRuleFunction();
 }
コード例 #3
0
 protected SrcOp(OutputModelFactory factory, GrammarAST ast)
     : base(factory, ast)
 {
     if (ast != null)
     {
         uniqueID = ast.Token.TokenIndex;
     }
     enclosingBlock        = factory.GetCurrentBlock();
     enclosingRuleRunction = factory.GetCurrentRuleFunction();
 }
コード例 #4
0
ファイル: MatchSet.cs プロジェクト: sharwell/antlr4cs
 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);
 }
コード例 #5
0
ファイル: MatchSet.cs プロジェクト: yuanyong00/antlr4cs
        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);
        }
コード例 #6
0
ファイル: Action.cs プロジェクト: sharwell/antlr4cs
 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);
 }
コード例 #7
0
ファイル: Action.cs プロジェクト: yuanyong00/antlr4cs
        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);
        }
コード例 #8
0
ファイル: Action.cs プロジェクト: sharwell/antlr4cs
 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));
     }
 }
コード例 #9
0
ファイル: Action.cs プロジェクト: yuanyong00/antlr4cs
        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));
            }
        }
コード例 #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);
            }
        }