Esempio n. 1
0
        internal static FileToken Tokenize(string text)
        {
            var tokenizer = new Parser.Tokenizer(StaticSymbolsRegistry.SymbolsRegistry.Symbols.Except(new[] { SymbolsRegistry.StaticSubtractSymbol, SymbolsRegistry.TryAssignSymbol }).ToArray());
            var res       = tokenizer.Tokenize(text);

            return(res);
        }
Esempio n. 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));
        }
Esempio n. 3
0
        private static void Text_Token(IWrappedTestCase sample)
        {
            var text = sample.Text;

            var tokenizer = new Parser.Tokenizer(StaticSymbolsRegistry.SymbolsRegistry.Symbols.ToArray());
            var res       = tokenizer.Tokenize(text);

            var target = sample.Token;

#pragma warning disable IDE0059 // Value assigned to symbol is never used
            var targetJson = JsonConvert.SerializeObject(target);
            var resJson    = JsonConvert.SerializeObject(res);
#pragma warning restore IDE0059 // Value assigned to symbol is never used

            Assert.Equal(target.ToString(), res.ToString());
        }