Ejemplo n.º 1
0
        protected override bool InternalMatch(ParserState p)
        {
            if (p == null)
            {
                throw new ArgumentNullException(nameof(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.");
                }
            }
        }
Ejemplo n.º 2
0
        protected override bool InternalMatch(ParserState p)
        {
            Rule r = Rules[0];

            r.Match(p);
            return(true);
        }
Ejemplo n.º 3
0
        protected override bool InternalMatch(ParserState p)
        {
            Trace.Assert(Rules.Count == 1);
            Rule r = Rules[0];

            if (r.Match(p))
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 4
0
        protected override bool InternalMatch(ParserState p)
        {
            if (p == null)
            {
                throw new ArgumentNullException(nameof(p));
            }

            Rule r = Rules[0];

            if (!r.Match(p))
            {
                ParsingException ex = new ParsingException(p.Peek(), r, p);
                throw ex;
            }
            return(true);
        }
Ejemplo n.º 5
0
        public ParseNode Parse(Stream stream)
        {
            Rule   parseRule = Grammar.file;
            string text;

            using (TextReader reader = new StreamReader(stream))
            {
                text = reader.ReadToEnd();
            }
            ParserState state = new ParserState(text);

            try
            {
                Succeeded = parseRule.Match(state) && state.AtEndOfInput();
            }
            catch (ParsingException e)
            {
                state.ForceCompletion();
                Succeeded = false;
                Exception = e;
            }

            return(state.GetRoot());
        }
Ejemplo n.º 6
0
        protected override bool InternalMatch(ParserState p)
        {
            Rule r = func();

            return(r.Match(p));
        }