예제 #1
0
파일: Rule.cs 프로젝트: PLCnext/PLCnext_CLI
        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);
        }
예제 #2
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());
        }