Beispiel #1
0
        public static CppRipper.ParseNode GenerateCppAst(string cppContent, out string status)
        {
            CppStructuralGrammar grammar = new CppStructuralGrammar();
            Rule        parse_rule       = grammar.file;
            ParserState state            = new ParserState(cppContent);

            try
            {
                if (!parse_rule.Match(state))
                {
                    status = "Failed to parse c++ content";
                    return(null);
                }
                else
                {
                    if (state.AtEndOfInput())
                    {
                        status = "Successfully parsed c++ content";
                        return(state.GetRoot());
                    }
                    else
                    {
                        status = "Failed to read end of c++ content";
                        return(null);
                    }
                }
            }
            catch (ParsingException e)
            {
                state.ForceCompletion();
                status = e.Message;
                return(null);
            }
        }
Beispiel #2
0
        public static ParserState Parse(string source, IAbstractSyntaxTreePrinter printer = null, Rule rule = null)
        {
            if (rule == null)
                rule = _grammar.file;

            var state = new ParserState(source);
            try
            {
                if (rule.Match(state))
                {
                    if (state.AtEndOfInput())
                    {
                        if (printer != null)
                            printer.Print(state.GetRoot());

                        return state;
                    }

                    throw new ParsingException(state, rule, message: "Failed to read end of input");
                }

                throw new ParsingException(state, rule, message: "Failed to parse source");
            }
            catch (ParsingException e)
            {
                return state.Exception(e);
            }
        }
Beispiel #3
0
        public static ParserState Parse(string source, IAbstractSyntaxTreePrinter printer = null, Rule rule = null)
        {
            if (rule == null)
            {
                rule = _grammar.file;
            }

            var state = new ParserState(source);

            try
            {
                if (rule.Match(state))
                {
                    if (state.AtEndOfInput())
                    {
                        if (printer != null)
                        {
                            printer.Print(state.GetRoot());
                        }

                        return(state);
                    }

                    throw new ParsingException(state, rule, message: "Failed to read end of input");
                }

                throw new ParsingException(state, rule, message: "Failed to parse source");
            }
            catch (ParsingException e)
            {
                return(state.Exception(e));
            }
        }