コード例 #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
        /** Build a file with a parser containing rule functions. Use the
         *  controller as factory in SourceGenTriggers so it triggers code generation
         *  extensions too, not just the factory functions in this factory.
         */
        public virtual OutputModelObject BuildParserOutputModel(bool header)
        {
            CodeGenerator gen  = @delegate.GetGenerator();
            ParserFile    file = ParserFile(gen.GetRecognizerFileName(header));

            SetRoot(file);
            file.parser = Parser(file);

            Grammar g = @delegate.GetGrammar();

            foreach (Rule r in g.rules.Values)
            {
                BuildRuleFunction(file.parser, r);
            }

            return(file);
        }
コード例 #3
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);
 }
コード例 #4
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);
        }
コード例 #5
0
        protected static string TranslateTokenStringToTarget(string tokenName, OutputModelFactory factory)
        {
            if (tokenName == null)
            {
                return(null);
            }

            if (tokenName[0] == '\'')
            {
                bool   addQuotes    = false;
                string targetString =
                    factory.GetTarget().GetTargetStringLiteralFromANTLRStringLiteral(factory.GetGenerator(), tokenName, addQuotes);
                return("\"'" + targetString + "'\"");
            }
            else
            {
                return(factory.GetTarget().GetTargetStringLiteralFromString(tokenName, true));
            }
        }
コード例 #6
0
ファイル: ActionTranslator.cs プロジェクト: sharwell/antlr4cs
 public ActionTranslator(OutputModelFactory factory, ActionAST node)
 {
     this.factory = factory;
     this.node = node;
     this.gen = factory.GetGenerator();
 }
コード例 #7
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);
            }
        }
コード例 #8
0
ファイル: Recognizer.cs プロジェクト: sharwell/antlr4cs
        protected static string TranslateTokenStringToTarget(string tokenName, OutputModelFactory factory)
        {
            if (tokenName == null)
            {
                return null;
            }

            if (tokenName[0] == '\'')
            {
                bool addQuotes = false;
                string targetString =
                    factory.GetTarget().GetTargetStringLiteralFromANTLRStringLiteral(factory.GetGenerator(), tokenName, addQuotes);
                return "\"'" + targetString + "'\"";
            }
            else
            {
                return factory.GetTarget().GetTargetStringLiteralFromString(tokenName, true);
            }
        }
コード例 #9
0
 public ActionTranslator(OutputModelFactory factory, ActionAST node)
 {
     this.factory = factory;
     this.node    = node;
     this.gen     = factory.GetGenerator();
 }