Exemplo n.º 1
0
        private void buildToolStripMenuItem_Click(object sender, EventArgs e)
        {
            List <Handler.Error> Errors = new List <Handler.Error>();

            if (ActiveEditor == null)
            {
                return;
            }
            Scanner.Scanner S = new Scanner.Scanner(ActiveEditor.getCode());
            S.Scan();
            if (S.ErrorList.Count > 0)
            {
                Errors.AddRange(S.ErrorList);
            }
            Parser.Parser parser    = new Parser.Parser(S.Tokens);
            Tree          parseTree = parser.parse();

            if (parser.ErrorList.Count > 0)
            {
                Errors.AddRange(S.ErrorList);
            }
            Preview.UpdateTree(parseTree);
            Preview.showPane(false);
            if (Errors.Count > 0)
            {
                Preview.showPane(true);
                Output ErrorsWin = new Output(Errors);
                Controls.Add(ErrorsWin);
                ErrorsWin.BringToFront();
            }
        }
Exemplo n.º 2
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 SimpleNode parse(TextReader reader, 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);
        }