Пример #1
0
        /// <summary>
        /// Parse code with a given parser.
        /// </summary>
        /// <param name="parser"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        public static CodeDocument Load(Parser parser, string input)
        {
            TextBuffer   buffer = new FlatBuffer(input);
            CodeDocument doc    = parser.ParseString(buffer);

            if (doc != null)
            {
                return(doc);
            }

            // only place to throw exception is CodeDocument.Load and Parser.SetGrammar (and MetaGrammar)
            var error = new ParserException(buffer.Status.Error.Message);

            error.AllErrors.AddRange(buffer.Status.AllErrors);
            throw error;
        }
Пример #2
0
        /// <summary>Read a Grammar definition from text. </summary>
        /// <param name="Grammar">Grammar text.</param>
        /// <returns>Grammar is Ok.</returns>
        /// <exclude/>
        private void SetGrammar(string Grammar)
        {
            CodeDocument grammarDoc = null;

            TextBuffer buffer = new FlatBuffer(Grammar);

            grammarDoc = MetaParser.Instance.ParseString(buffer);

            if (buffer.Status.Error != null || !ParserBuilder.BuildRules(this, grammarDoc, buffer.Status))
            {
                // only place to throw exception is CodeDocument.Load and Parser.SetGrammar (and MetaGrammar)
                var error = new ParserException(buffer.Status.Error.Message);
                error.AllErrors.AddRange(buffer.Status.AllErrors);
                throw error;
            }
        }