Exemple #1
0
 public override void Visit(ModuleId moduleId)
 {
     //Check if path exists
     String path = ModuleCache.Instance.GetPath(moduleId);
     if (!File.Exists(path))
     {
         ExceptionList.Add(new NonExistingModule(moduleId));
     }
 }
Exemple #2
0
        public void GetElementsTest()
        {
            //Add elements to list and retrieve them and check if they are correct
            Module node1 = new Module();
            ModuleId node2 = new ModuleId();

            nodes.Add(node1);
            nodes.Add(node2);

            ISyntaxNode[] list = nodes.GetElements();

            Assert.IsTrue(list.Length == 2);
            Assert.AreSame(node1, list[0]);
            Assert.AreSame(node2, list[1]);
        }
Exemple #3
0
 /// <summary>
 /// Set identifier of import
 /// </summary>
 /// <param name="identifier">Identifier for this import</param>
 public void SetModuleId(ModuleId identifier)
 {
     ModuleIdentifier = identifier;
 }
Exemple #4
0
 /// <summary>
 /// Set identifier of this module
 /// </summary>
 /// <param name="identifier">Identifier to set</param>
 public void SetModuleId(ModuleId identifier)
 {
     this.Identifier = identifier;
 }
 public virtual void Visit(ModuleId module)
 {
     VisitSubNodes(module);
 }
Exemple #6
0
 /// <summary>
 /// Check if ModuleCache contains a specified module
 /// </summary>
 /// <param name="module">ModuleId of module</param>
 /// <returns>True if module is in Cache, otherwise false</returns>
 public bool ContainsModule(ModuleId module)
 {
     return ModuleTable.Contains(module.ToString());
 }
Exemple #7
0
        /// <summary>
        /// Request an specified module
        /// </summary>
        /// <param name="indentifier">ModuleId of requested module</param>
        /// <returns>Requested module if available</returns>
        public Module RequestModule(ModuleId identifier)
        {
            if (ModuleTable.ContainsKey(identifier))
            {   //Module already loaded so return instance of module
                return (Module) ModuleTable[identifier];
            }

            //Module not cached, so load it
            StreamReader moduleStream = new StreamReader(GetPath(identifier));

            //Lexicalize and parse it
            WaebricLexer lexer = new WaebricLexer(moduleStream);
            lexer.LexicalizeStream();
            WaebricParser parser = new WaebricParser(lexer.GetTokenIterator());
            parser.Parse();

            //Get module of tree
            SyntaxTree tree = parser.GetTree();

            //Add module to hashtable
            Module requestedModule = tree.GetRoot();
            ModuleTable.Add(identifier, requestedModule);

            return requestedModule;
        }
Exemple #8
0
        /// <summary>
        /// Determine relative path of specified identifier
        /// </summary>
        /// <param name="identifier">Identifier of module</param>
        /// <returns>Path of module</returns>
        public String GetPath(ModuleId identifier)
        {
            String[] identifierList = identifier.GetIdentifiers().ToArray();
            String path = DirectoryPath;

            //Create path
            for (int i = 0; i <= (identifierList.Length - 1); i++)
            {
                path += identifierList[i];
                if (i != (identifierList.Length - 1))
                {
                    path += "/";
                }
            }

            //Add extension
            path += ".wae";

            return path;
        }
 public NonExistingModule(ModuleId moduleId)
 {
     Console.WriteLine("Error: Module " + moduleId.ToString() + " not found.");
 }
Exemple #10
0
        /// <summary>
        /// Parse a module identifier
        /// </summary>
        /// <param name="identifier">Identifier to parse</param>
        public ModuleId ParseModuleId()
        {
            ModuleId moduleId = new ModuleId();

            //parse module identifier
            while (TokenStream.HasNext())
            {
                if (NextToken("identifier", "module identifier.identifier", TokenType.IDENTIFIER))
                {
                    moduleId.AddIdentifier(CurrentToken.GetValue().ToString());
                }
                else
                {
                    //Raise exception
                    throw new UnexpectedToken("Unexpected token found:", CurrentToken.GetValue().ToString(), CurrentToken.GetLine());
                }

                if (TokenStream.HasNext() && TokenStream.Peek(1).GetValue().ToString() == ".")
                {   //Period, so another identifier will appear after this one
                    NextToken(".", "module identifier.identifier", '.');
                }
                else
                {
                    break; //No more module identifier stuff will appear
                }
            }

            return moduleId;
        }
Exemple #11
0
        public void GetTest()
        {
            //Add elements to list and retrieve them and check if they are correct
            Module node1 = new Module();
            ModuleId node2 = new ModuleId();

            nodes.Add(node1);
            nodes.Add(node2);

            ISyntaxNode[] list = nodes.GetElements();

            Assert.IsTrue(list.Length == 2);
            //Test if get with index works
            Assert.AreSame(nodes.Get(1), node2);
        }