Exemple #1
0
        public IOrType <IProject <TAssembly, TBacking>, IReadOnlyList <IError> > Parse <TAssembly, TBacking>(string text, IReadOnlyList <TAssembly> dependencies, string name)
            where TAssembly : IAssembly <TBacking>
        {
            var tokenizer = new Tokenizer(StaticSymbolsRegistry.SymbolsRegistry.Symbols.Except(new[] { SymbolsRegistry.StaticSubtractSymbol }).ToArray());
            var tokens    = tokenizer.Tokenize(text);

            var elementMatchingContest = new ElementMatchingContext();

            var scopePopulator = elementMatchingContest.ParseFile(tokens);

            var dependencyConverter = new DependencyConverter();

            var problem = new Tpn.TypeProblem2(new WeakScopeConverter(), scopePopulator, prob => {
                foreach (var dependency in dependencies)
                {
                    var type = prob.builder.CreateTypeExternalType(prob.Dependency, new WeakTypeDefinitionConverter(), dependency.Scope);

                    foreach (var memberPair in dependency.Scope.Members)
                    {
                        var innerType = ConvertType(prob.builder, type, OrType.Make <IVerifiableType, IError>(memberPair.Type));
                        innerType.Switch(x =>
                        {
                            prob.builder.CreatePublicMember(type, type, memberPair.Key, OrType.Make <IKey, IError>(x));
                        }, y =>
                        {
                            prob.builder.CreatePublicMember(type, memberPair.Key, y);
                        });
                    }
                    prob.builder.CreatePrivateMember(prob.Dependency, dependency.Key, OrType.Make <Tpn.TypeProblem2.MethodType, Tpn.TypeProblem2.Type, Tpn.TypeProblem2.Object, Tpn.TypeProblem2.OrType, Tpn.TypeProblem2.InferredType, Tpn.TypeProblem2.GenericTypeParameter, IError>(type));
                }
            });


            var populateScopeContex = new SetUpContext(problem.builder);
            var referanceResolver   = scopePopulator.Run(problem.ModuleRoot, populateScopeContex).Resolve;

            var solution = problem.Solve();

            var rootScope = referanceResolver.Run(solution, new List <Tpn.ITypeProblemNode>()
            {
                problem.Dependency,
                problem.ModuleRoot
            }).GetValue();

            var errors = rootScope.Validate().ToArray();

            if (errors.Any())
            {
                return(OrType.Make <IProject <TAssembly, TBacking>, IReadOnlyList <IError> >(errors));
            }

            var dependencyScope = problem.Dependency.Converter.Convert(solution, problem.Dependency, Array.Empty <Tpn.ITypeProblemNode>()).Is2OrThrow();


            var context = TransformerExtensions.NewConversionContext();

            return(OrType.Make <IProject <TAssembly, TBacking>, IReadOnlyList <IError> >(new Project <TAssembly, TBacking>(rootScope.Convert(context), dependencies, dependencyScope.Convert(context))));
        }
Exemple #2
0
        public static IProject <TBacking> Parse <TBacking>(string text, IReadOnlyList <IAssembly <TBacking> > dependencies, string name)
            where TBacking : IBacking
        {
            var tokenizer = new Parser.Tokenizer(StaticSymbolsRegistry.SymbolsRegistry.Symbols.ToArray());
            var tokens    = tokenizer.Tokenize(text);

            var elementMatchingContest = new ElementMatchingContext();

            var scopePopulators = elementMatchingContest.ParseFile(tokens);

            var dependencyConverter = new DependencyConverter();

            var dependendcyScope = new PopulatableScope();

            foreach (var dependency in dependencies)
            {
                var convertedDependency = dependencyConverter.ConvertToType <TBacking>(dependency);
                if (!dependendcyScope.TryAddMember(DefintionLifetime.Instance, dependency.Key, new Box <IIsPossibly <WeakMemberDefinition> >(Possibly.Is(
                                                                                                                                                 new WeakMemberDefinition(true, dependency.Key, Possibly.Is(
                                                                                                                                                                              new WeakTypeReference(
                                                                                                                                                                                  Possibly.Is(
                                                                                                                                                                                      new Box <IIsPossibly <IConvertableFrontendType <IVerifiableType> > >(
                                                                                                                                                                                          Possibly.Is <IConvertableFrontendType <IVerifiableType> >(
                                                                                                                                                                                              convertedDependency))))))))))
                {
                    throw new Exception("could not add dependency!");
                }
            }

            var scope = new PopulatableScope(dependendcyScope);

            var populateScopeContex = new PopulateScopeContext();
            var referanceResolvers  = scopePopulators.Select(populateScope => populateScope.Run(scope, populateScopeContex)).ToArray();

            var resolvableDependencyScope = dependendcyScope.GetResolvelizableScope().FinalizeScope();

            var resolvalbe           = scope.GetResolvelizableScope().FinalizeScope(resolvableDependencyScope);
            var finalizeScopeContext = new FinalizeScopeContext();
            var populateBoxes        = referanceResolvers.Select(reranceResolver => reranceResolver.Run(resolvalbe, finalizeScopeContext)).ToArray();

            var resolveReferenceContext = new ResolveReferanceContext();

            var module = new WeakModuleDefinition(
                resolvalbe,
                populateBoxes.Select(reranceResolver => reranceResolver.Run(resolvalbe, resolveReferenceContext)).ToArray(),
                new NameKey(name));

            var resolveReferanceContext = new ResolveReferanceContext();


            var context = TransformerExtensions.NewConversionContext();


            return(new Project <TBacking>(module.Convert <IModuleDefinition>(context), dependencies));
        }