Exemplo n.º 1
0
        /// <summary>
        /// Interprets root and generates XHTML files
        /// </summary>
        /// <param name="tree">Tree to interpret</param>
        public void InterpretAST(SyntaxTree tree)
        {
            Module root = tree.GetRoot();

            //Get dependency's and add functions to SymbolTable
            List<Module> dependencyList = ModuleCache.Instance.RequestDependencies(root);
            SymbolTable = new SymbolTable();
            foreach (Module module in dependencyList)
            {
                foreach (FunctionDefinition function in module.GetFunctionDefinitions())
                {
                    SymbolTable.AddFunctionDefinition(function);
                }
            }

            //Interpret the main function
            if (SymbolTable.ContainsFunction("main"))
            {
                XHTMLVisitor xhtmlVisitor = new XHTMLVisitor(SymbolTable);
                SymbolTable.GetFunctionDefinition("main").AcceptVisitor(xhtmlVisitor);

                //Write xhtml output
                XHTMLStreamWriter writer = new XHTMLStreamWriter(Console.Out, XHTMLStreamWriter.DocType.TRANSITIONAL, xhtmlVisitor.GetTree());
                writer.WriteStream();
            }

            //Interpret all sites an write to files
            foreach (Module module in dependencyList)
            {
                foreach (Site site in module.GetSites())
                {
                    foreach (Mapping mapping in site.GetMappings())
                    {
                        //Get function which should be called
                        Markup markup = mapping.GetMarkup();

                        //Determine site path and open writer and lets interpret it
                        Writer = CreateOutputStream(mapping.GetPath().ToString());
                        XHTMLVisitor xhtmlVisitor = new XHTMLVisitor(SymbolTable);
                        markup.AcceptVisitor(xhtmlVisitor);

                        //Write xhtml output
                        XHTMLStreamWriter writer = new XHTMLStreamWriter(Writer, XHTMLStreamWriter.DocType.TRANSITIONAL, xhtmlVisitor.GetTree());
                        writer.WriteStream();
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void ModuleParserSiteTest()
        {
            SyntaxTree tree = new SyntaxTree();

            //Create lexer to tokenize stream
            WaebricLexer lexer = new WaebricLexer(new StringReader("module test\n\nsite\n  site/index.html : home() ; site/index2.html : home()\nend"));
            lexer.LexicalizeStream();

            //Parse tokenized stream
            ModuleParser parser = new ModuleParser(lexer.GetTokenIterator());
            tree.SetRoot(parser.ParseModule());

            //Check module
            Module module = tree.GetRoot();
            Assert.IsTrue(module.GetModuleId().ToString() == "test");
            Assert.AreEqual(0, module.GetImports().Count); //No imports
            Assert.AreEqual(0, module.GetFunctionDefinitions().Count); //No function definitions
            Assert.AreEqual(1, module.GetSites().Count); //One site

            //Check site
            Site site = (Site) module.GetSites().Get(0);
            Assert.AreEqual(2, site.GetMappings().Count);
        }