Esempio n. 1
0
        /// <summary>  Parse the input and return the root of the AST node structure.
        /// *
        /// </summary>
        /// <param name="InputStream">inputstream retrieved by a resource loader
        /// </param>
        /// <param name="String">name of the template being parsed
        /// </param>
        /// <param name="dumpNamespace">flag to dump the Velocimacro namespace for this template
        ///
        /// </param>
        public virtual SimpleNode parse(System.IO.TextReader reader, System.String templateName, bool dumpNamespace)
        {
            SimpleNode ast = null;

            Parser.Parser parser  = (Parser.Parser)parserPool.get();
            bool          madeNew = false;

            if (parser == null)
            {
                /*
                 *  if we couldn't get a parser from the pool
                 *  make one and log it.
                 */

                error("Runtime : ran out of parsers. Creating new.  " + " Please increment the parser.pool.size property." + " The current value is too small.");

                parser = createNewParser();

                if (parser != null)
                {
                    madeNew = true;
                }
            }

            /*
             *  now, if we have a parser
             */

            if (parser != null)
            {
                try {
                    /*
                     *  dump namespace if we are told to.  Generally, you want to
                     *  do this - you don't in special circumstances, such as
                     *  when a VM is getting init()-ed & parsed
                     */

                    if (dumpNamespace)
                    {
                        dumpVMNamespace(templateName);
                    }

                    ast = parser.parse(reader, templateName);
                } finally {
                    /*
                     *  if this came from the pool, then put back
                     */
                    if (!madeNew)
                    {
                        parserPool.put(parser);
                    }
                }
            }
            else
            {
                error("Runtime : ran out of parsers and unable to create more.");
            }
            return(ast);
        }
	/// <summary> Returns a JavaCC generated Parser.
	/// </summary>
	/// <returns>Parser javacc generated parser
	///
	/// </returns>
	public virtual Parser.Parser createNewParser() {
	    Parser.Parser parser = new Parser.Parser(this);
	    parser.Directives = runtimeDirectives;
	    return parser;
	}
Esempio n. 3
0
 /// <summary> Returns a JavaCC generated Parser.
 /// </summary>
 /// <returns>Parser javacc generated parser
 ///
 /// </returns>
 public virtual Parser.Parser createNewParser()
 {
     Parser.Parser parser = new Parser.Parser(this);
     parser.Directives = runtimeDirectives;
     return(parser);
 }