Beispiel #1
0
        /// <summary>
        /// Parses the input with the given identifier
        /// </summary>
        /// <param name="name">The input's name</param>
        /// <param name="reader">The input's reader</param>
        /// <returns><c>true</c> if the operation succeed</returns>
        private bool LoadInput(string name, TextReader reader)
        {
            reporter.Info("Reading input " + name + " ...");
            bool              hasErrors = false;
            HimeGrammarLexer  lexer     = new HimeGrammarLexer(reader);
            HimeGrammarParser parser    = new HimeGrammarParser(lexer);
            ParseResult       result    = null;

            try
            {
                result = parser.Parse();
            }
            catch (System.Exception ex)
            {
                reporter.Error("Fatal error in " + name);
                reporter.Error(ex);
                hasErrors = true;
            }
            foreach (ParseError error in result.Errors)
            {
                reporter.Error(name + error.Message, result.Input, error.Position);
                hasErrors = true;
            }
            if (result.IsSuccess)
            {
                foreach (ASTNode gnode in result.Root.Children)
                {
                    Grammars.Loader loader = new Grammars.Loader(name, result.Input, gnode, reporter);
                    inners.Add(loader.Grammar.Name, loader);
                }
            }
            reader.Close();
            return(!hasErrors);
        }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the parser
 /// </summary>
 /// <param name="lexer">The input lexer</param>
 public HimeGrammarParser(HimeGrammarLexer lexer) : base(commonAutomaton, variables, virtuals, null, lexer)
 {
 }