Ejemplo n.º 1
0
        private async Task <Possible <ParsedModule> > CreatePreludeModuleAsync()
        {
            var moduleName = FrontEndHost.PreludeModuleName;

            string       preludeRootDir     = GetPreludeRoot();
            AbsolutePath preludeRootDirPath = AbsolutePath.Create(m_pathTable, preludeRootDir);

            if (!m_engine.DirectoryExists(preludeRootDirPath))
            {
                return(new Failure <string>($"Prelude root folder '{preludeRootDir}' does not exist"));
            }

            var specs = DiscoverPreludeSpecs(preludeRootDirPath, out AbsolutePath mainSpec, out AbsolutePath moduleConfigSpec);

            if (!mainSpec.IsValid)
            {
                return(new Failure <string>($"Prelude main spec file ('{PreludeMainFile}') not found inside the '{preludeRootDir}' folder"));
            }

            if (!moduleConfigSpec.IsValid)
            {
                return(new Failure <string>($"Prelude module configuration spec file ('{PreludeModuleConfigName}') not found inside the '{preludeRootDir}' folder"));
            }

            ModuleDefinition preludeModuleDefinition = ModuleDefinition.CreateModuleDefinitionWithExplicitReferencesWithEmptyQualifierSpace(
                descriptor: new ModuleDescriptor(
                    id: ModuleIdProvider.GetNextId(),
                    name: moduleName,
                    displayName: moduleName,
                    version: "0",
                    resolverKind: KnownResolverKind.DScriptResolverKind,
                    resolverName:  "DScriptPrelude"),
                main: mainSpec,
                moduleConfigFile: moduleConfigSpec,
                specs: specs,
                pathTable: PathTable);

            var parsedPreludeFiles = await Task.WhenAll(specs.Select(m_parser));

            var failures = parsedPreludeFiles.Where(r => !r.Succeeded).ToList();

            if (failures.Count > 0)
            {
                var separator = Environment.NewLine + "  ";
                var message   = "Parsing built-in prelude failed:" + separator + string.Join(separator, failures.Select(f => f.Failure.Describe()));
                return(new Failure <string>(message));
            }

            Dictionary <AbsolutePath, ISourceFile> specFileMap = parsedPreludeFiles
                                                                 .ToDictionary(
                maybeSourceFile => AbsolutePath.Create(PathTable, maybeSourceFile.Result.FileName),
                maybeSourceFile => maybeSourceFile.Result);

            return(new ParsedModule(preludeModuleDefinition, specFileMap));
        }
Ejemplo n.º 2
0
 /// <inheritdoc/>
 public override bool IsDirectory(AbsolutePath path)
 {
     return(m_engine.DirectoryExists(path));
 }