/// <summary> /// Parses a macro. /// </summary> /// <param name="inputText">The macro script text.</param> /// <returns>The parse tree, starting with the InstructionSet node.</returns> public new static ParseTree ParseMacro(string inputText) { if (inputText == null) { throw new ArgumentNullException(); } // Parse macro DocMacroGrammar grammar = _grammarPool.GetObject(); try { var parser = new Parser(grammar); parser.Parse(inputText); // Check for macro errors ParseTree parseTree = parser.Context.CurrentParseTree; grammar.CheckParseTreeOk(parseTree); return(parseTree); } finally { _grammarPool.PutObject(grammar); } }
/// <summary> /// Singleton instance of grammar. /// Thread-safe. Grammar is verified on first access. /// </summary> private static DocMacroGrammar CreateGrammar() { var grammar = new DocMacroGrammar(); // Verify the grammar on first load var parser = new Parser(grammar); var errors = parser.Language.Errors; if (errors.Count > 0) { throw new Exception("Internal error: macro grammar contains error(s): " + string.Join("\n", errors)); } return(grammar); }