Exemplo n.º 1
0
        protected override bool InternalMatch(ParserState p)
        {
            Trace.Assert(rules.Count == 1);
            Rule r = rules[0];

            if (!r.Match(p))
            {
                return(false);
            }
            while (true)
            {
                int old = p.index;
                if (!r.Match(p))
                {
                    return(true);
                }

                // Avoid infinite loops.
                if (p.index <= old)
                {
                    throw new Exception("Failed to advance parser input pointer, while parsing rule '" +
                                        r.RuleNameOrDefinition + "'. This means the grammar is invalid, maybe because of nested star rules.");
                }
            }
        }
Exemplo n.º 2
0
        public CppFileParser(IAstPrinter printer, string file)
        {
            Rule parse_rule = grammar.file;

            string text = File.ReadAllText(file);

            printer.Clear();
            ParserState state = new ParserState(text);

            try
            {
                if (!parse_rule.Match(state))
                {
                    message = "Failed to parse file " + file;
                }
                else
                {
                    if (state.AtEndOfInput())
                    {
                        message = "Successfully parsed file";
                    }
                    else
                    {
                        message = "Failed to read end of input";
                    }
                }
            }
            catch (ParsingException e)
            {
                state.ForceCompletion();
                message = e.Message;
            }

            printer.PrintNode(state.GetRoot(), 0);
        }
Exemplo n.º 3
0
        protected override bool InternalMatch(ParserState p)
        {
            Rule r = rules[0];

            r.Match(p);
            return(true);
        }
Exemplo n.º 4
0
        protected override bool InternalMatch(ParserState p)
        {
            Rule r = rules[0];

            if (!r.Match(p))
            {
                ParsingException ex = new ParsingException(p.Peek(), r, p);
                throw ex;
            }
            return(true);
        }
Exemplo n.º 5
0
        protected override bool InternalMatch(ParserState p)
        {
            Trace.Assert(rules.Count == 1);
            Rule r = rules[0];

            if (r.Match(p))
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 6
0
        protected override bool InternalMatch(ParserState p)
        {
            Rule r = func();

            return(r.Match(p));
        }