Ejemplo n.º 1
0
 public void PushScope(CompilationScope scope)
 {
     this.AddCompilationScope(scope);
     this.scopeStack.Push(scope);
     this.CurrentScope  = scope;
     this.CurrentLocale = scope.Locale;
     this.UpdateLanguage(this.CurrentScope);
 }
Ejemplo n.º 2
0
 public void PushScope(CompilationScope scope)
 {
     this.AddCompilationScope(scope);
     this.scopeStack.Push(scope);
     this.CurrentScope     = scope;
     this.CurrentLocale    = scope.Locale;
     this.Keywords         = this.CurrentLocale.Keywords;
     this.ReservedKeywords = new HashSet <string>(this.CurrentLocale.GetKeywordsList());
 }
Ejemplo n.º 3
0
 public FileScope(string filename, string content, CompilationScope scope, int id)
 {
     this.Name    = filename;
     this.ID      = id;
     this.Content = content;
     this.Imports = new HashSet <ImportStatement>();
     this.FileScopeEntityLookup = new FileScopedEntityLookup().SetFileScope(this);
     this.CompilationScope      = scope;
 }
Ejemplo n.º 4
0
        private void UpdateLanguage(CompilationScope scope)
        {
            this.Keywords         = this.CurrentLocale.Keywords;
            this.ReservedKeywords = new HashSet <string>(this.CurrentLocale.GetKeywordsList());

            switch (scope.ProgrammingLanguage)
            {
            case ProgrammingLanguage.CRAYON:
                this.TopLevelParser   = new Crayon.CrayonTopLevelParser(this);
                this.ExpressionParser = new Crayon.CrayonExpressionParser(this);
                this.ExecutableParser = new Crayon.CrayonExecutableParser(this);
                this.AnnotationParser = new Crayon.CrayonAnnotationParser(this);
                this.TypeParser       = new Crayon.CrayonTypeParser();
                break;

            case ProgrammingLanguage.ACRYLIC:
                this.TopLevelParser   = new Acrylic.AcrylicTopLevelParser(this);
                this.ExpressionParser = new Acrylic.AcrylicExpressionParser(this);
                this.ExecutableParser = new Acrylic.AcrylicExecutableParser(this);
                this.AnnotationParser = new Acrylic.AcrylicAnnotationParser(this);
                this.TypeParser       = new Acrylic.AcrylicTypeParser();
                break;
            }
        }
Ejemplo n.º 5
0
 public void AddCompilationScope(CompilationScope scope)
 {
     this.compilationScopes.Add(scope.ScopeKey, scope);
     this.localeCount = -1;
 }
Ejemplo n.º 6
0
        private LocalizedAssemblyView GetOrImportAssemblyImpl(ParserContext parser, Token throwToken, string fullImportNameWithDots)
        {
            // TODO: allow importing from a user-specified locale
            Locale fromLocale = parser.CurrentLocale;
            string name       = fullImportNameWithDots.Contains('.') ? fullImportNameWithDots.Split('.')[0] : fullImportNameWithDots;

            string           secondAttemptedKey = name;
            AssemblyMetadata assemblyMetadata   = this.assemblyFinder.GetAssemblyMetadataFromAnyPossibleKey(fromLocale.ID + ":" + name);
            Locale           effectiveLocale    = fromLocale;

            if (assemblyMetadata == null)
            {
                assemblyMetadata = this.assemblyFinder.GetAssemblyMetadataFromAnyPossibleKey(name);
                if (assemblyMetadata != null &&
                    assemblyMetadata.SupportedLocales.Contains(fromLocale) &&
                    assemblyMetadata.InternalLocale != fromLocale)
                {
                    // Coincidental cross-language collision.
                    return(null);
                }

                if (assemblyMetadata == null)
                {
                    // Simply no matches at all.
                    return(null);
                }

                effectiveLocale = assemblyMetadata.InternalLocale;
            }

            // Are there any restrictions on importing that library from this location?
            if (!assemblyMetadata.IsAllowedImport(parser.CurrentLibrary))
            {
                throw new ParserException(throwToken, "This library cannot be imported from here.");
            }

            // Ensure all secondary lookups for each locale is instantiated to make the upcoming code more readable.
            if (!this.importedAssembliesByLocalizedName.ContainsKey(effectiveLocale))
            {
                this.importedAssembliesByLocalizedName[effectiveLocale] = new Dictionary <string, LocalizedAssemblyView>();
            }
            if (!this.importedAssembliesByLocalizedName.ContainsKey(assemblyMetadata.InternalLocale))
            {
                this.importedAssembliesByLocalizedName[assemblyMetadata.InternalLocale] = new Dictionary <string, LocalizedAssemblyView>();
            }

            // Check to see if this library has been imported before.
            if (this.importedAssembliesById.ContainsKey(assemblyMetadata.ID))
            {
                // Is it imported by the same locale?
                if (this.importedAssembliesByLocalizedName[effectiveLocale].ContainsKey(name))
                {
                    // Then just return the previous instance as-is.
                    return(this.importedAssembliesByLocalizedName[effectiveLocale][name]);
                }

                // Wrap the previous instance in the new locale.
                LocalizedAssemblyView output = new LocalizedAssemblyView(effectiveLocale, this.importedAssembliesById[assemblyMetadata.ID]);
                this.importedAssembliesByLocalizedName[effectiveLocale][output.Name] = output;
                return(output);
            }

            // If the assembly exists but hasn't been imported before, instantiate it and
            // add it to all the lookups. This needs to happen before parsing the embedded
            // code to prevent infinite recursion.
            CompilationScope compilationScope = new CompilationScope(parser.BuildContext, assemblyMetadata);

            this.assembliesAlreadyImportedIndexByKey[assemblyMetadata.CanonicalKey] = this.ImportedAssemblyScopes.Count;
            this.ImportedAssemblyScopes.Add(compilationScope);
            this.importedAssembliesById[assemblyMetadata.ID] = compilationScope;
            LocalizedAssemblyView localizedView = new LocalizedAssemblyView(effectiveLocale, compilationScope);

            this.importedAssembliesByLocalizedName[effectiveLocale][name] = localizedView;

            // Parse the assembly.
            parser.PushScope(compilationScope);
            Dictionary <string, string> sourceCode = assemblyMetadata.GetSourceCode();

            foreach (string file in sourceCode.Keys.OrderBy(s => s.ToLowerInvariant()))
            {
                string fakeName = "[" + file + "]";
                string code     = sourceCode[file];
                parser.ParseFile(fakeName, code);
            }
            parser.PopScope();

            return(localizedView);
        }
Ejemplo n.º 7
0
 public LocalizedAssemblyView(Locale locale, CompilationScope scope)
 {
     this.Locale = locale;
     this.Scope  = scope;
     this.FullyQualifiedEntityLookup = null;
 }