public void PushScope(CompilationScope scope) { this.AddCompilationScope(scope); this.scopeStack.Push(scope); this.CurrentScope = scope; this.CurrentLibrary = scope.Library; this.CurrentLocale = scope.Locale; this.Keywords = this.CurrentLocale.Keywords; this.ReservedKeywords = new HashSet <string>(this.CurrentLocale.GetKeywordsList()); }
public void DoWorkImpl(CompilationScope scope) { AssemblyMetadata[] libraryMetadata = scope.Dependencies .Select(localizedLibView => localizedLibView.Scope.Metadata) .ToArray(); string depTree = AssemblyDependencyResolver.GetDependencyTreeJson(libraryMetadata).Trim(); ConsoleWriter.Print(ConsoleMessageType.LIBRARY_TREE, depTree); }
public Library ImportLibrary(Parser parser, Token throwToken, string name) { name = name.Split('.')[0]; string key = parser.CurrentLocale.ID + ":" + name; LibraryMetadata libraryMetadata = this.GetLibraryMetadataFromAnyPossibleKey(key); if (libraryMetadata == null) { // check for default locale libraryMetadata = this.GetLibraryMetadataFromAnyPossibleKey(name); if (libraryMetadata == null) { // No library found. Could just be a local namespace import. // If this is a bogus import, it'll throw in the Resolver. return(null); } if (libraryMetadata.SupportedLocales.Contains(parser.CurrentLocale)) { // If you import something by its default name from a supported locale, then it doesn't count. // Don't throw an error. A user should be able to define a namespace that happens to have the // same name as a library in some locale they aren't using. return(null); } } Library library = librariesAlreadyImportedIndexByKey.ContainsKey(libraryMetadata.CanonicalKey) ? librariesAlreadyImported[librariesAlreadyImportedIndexByKey[libraryMetadata.CanonicalKey]] : null; if (library == null) { string platformName = parser.BuildContext.Platform; Platform.AbstractPlatform platform = platformName == null || this.PlatformProvider == null ? null : this.PlatformProvider.GetPlatform(platformName); library = new Library(libraryMetadata, platform); CompilationScope scope = new CompilationScope(parser.BuildContext, library); library.Scope = scope; library.AddLocaleAccess(parser.CurrentLocale); this.librariesAlreadyImportedIndexByKey[libraryMetadata.CanonicalKey] = this.librariesAlreadyImported.Count; this.librariesAlreadyImported.Add(library); this.importedLibraries[name] = library; this.librariesByKey[name.ToLowerInvariant()] = library; parser.PushScope(scope); Dictionary <string, string> embeddedCode = library.GetEmbeddedCode(); foreach (string embeddedFile in embeddedCode.Keys) { string fakeName = "[" + embeddedFile + "]"; string code = embeddedCode[embeddedFile]; parser.ParseInterpretedCode(fakeName, code); } parser.PopScope(); } // Even if already imported, still must check to see if this import is allowed here. if (!library.IsAllowedImport(parser.CurrentLibrary)) { throw new ParserException(throwToken, "This library cannot be imported from here."); } return(library); }
public void AddCompilationScope(CompilationScope scope) { string scopeKey = scope.Library == null ? "." : scope.Library.Metadata.CanonicalKey; this.compilationScopes.Add(scopeKey, scope); }