private void AssemblyLoaded(Assembly assembly) { if (assembly is AssemblyBuilder) { return; } foreach (Type type in assembly.GetExportedTypes()) { Module module = rootModule; if (type.Namespace != null) { foreach (string part in type.Namespace.Split(new char[] { Type.Delimiter })) { if (module.IsDefined(part)) { module = (Module)module.GetName(part); } else { Module child = new Module(module, part); module.SetName(child.Name, child); module = child; } } } module.SetName(type.Name, type); } }
public object GetName(string name) { // Look for special names switch (name) { case "scope": return(this); case "names": return(names); case "globals": if (parent == null) { return(this); } else { return(parent.GetName(name)); } } // Module names if (names.ContainsKey(name)) { return(names[name]); } // Check for root if (parent == null) { throw new Exception("name " + TextEscape.Quote(name) + " not defined"); } // Pass it up return(parent.GetName(name)); }
public void Import(string fileName) { if (!hasBeenSetUp) { throw new Exception(); } fileName = pathResolver.Resolve(fileName); string absoluteFileName = Path.GetFullPath(fileName); if (imported.Contains(absoluteFileName)) { return; } if (verbose) { Console.WriteLine("importing " + fileName); } imported.Add(absoluteFileName); if (Path.GetExtension(fileName).ToLower() == ".dll") { Assembly.LoadFrom(fileName); } else { pathResolver.PushDirectory(fileName); Lexer lexer = new Lexer(parseTrace, fileName); RuntimeState runtimeState = new RuntimeState(this, rootModule); currentLexer = lexer; Pattern oldRoot = grammar.RootPattern; try { string extension = Path.GetExtension(fileName).ToLower(); if ((extension != "") && (extension != ".kat")) { IDictionary languages = (IDictionary)rootModule.GetName("languages"); object callable = languages[extension]; Type rootType = (Type)CallNode.Call(runtimeState, callable, null); grammar.RootPattern = Pattern.PatternForType(rootType); } grammar.Parse(lexer, runtimeState); } catch (Exception exception) { if (runtimeState.RunningSource != null) { Console.WriteLine(runtimeState.RunningSource); } throw exception; } finally { grammar.RootPattern = oldRoot; } pathResolver.PopDirectory(); } }