Ejemplo n.º 1
0
        public ITokenMatching <IPopulateScope <WeakImplementationDefinition, ISetUpMethod> > TryMake(IMatchedTokenMatching tokenMatching)
        {
            IPopulateScope <IWeakTypeReference, ISetUpTypeReference> context = null, input = null, output = null;

            var match = tokenMatching
                        .Has(new KeyWordMaker("implementation"), out var _)
                        .HasSquare(x => x
                                   .HasLine(y => y
                                            .HasElement(z => z.Has(new TypeMaker(), out context))
                                            .Has(new DoneMaker()))
                                   .HasLine(y => y
                                            .HasElement(z => z.Has(new TypeMaker(), out input))
                                            .Has(new DoneMaker()))
                                   .HasLine(y => y
                                            .HasElement(z => z.Has(new TypeMaker(), out output))
                                            .Has(new DoneMaker()))
                                   .Has(new DoneMaker()))
                        .OptionalHas(new NameMaker(), out var contextName)
                        .OptionalHas(new NameMaker(), out var parameterName)
                        .Has(new BodyMaker(), out var body);

            if (match is IMatchedTokenMatching matched)
            {
                var elements = tokenMatching.Context.ParseBlock(body);

                var contextNameString = contextName?.Item ?? "context";
                var contextDefinition = MemberDefinitionMaker.PopulateScope(
                    new NameKey(contextNameString),
                    false,
                    context
                    );

                var parameterNameString = parameterName?.Item ?? "input";
                var parameterDefinition = MemberDefinitionMaker.PopulateScope(
                    new NameKey(parameterNameString),
                    false,
                    input
                    );


                var resultDefinition = MemberDefinitionMaker.PopulateScope(
                    new ImplicitKey(),
                    false,
                    output
                    );

                return(TokenMatching <IPopulateScope <WeakImplementationDefinition, ISetUpMethod> > .MakeMatch(
                           matched.Tokens,
                           matched.Context,
                           new PopulateScopeImplementationDefinition(
                               contextDefinition,
                               parameterDefinition,
                               elements,
                               resultDefinition)));
            }


            return(TokenMatching <IPopulateScope <WeakImplementationDefinition, ISetUpMethod> > .MakeNotMatch(match.Context));
        }
Ejemplo n.º 2
0
        public ITokenMatching <IPopulateScope <WeakMethodDefinition, ISetUpMethod> > TryMake(IMatchedTokenMatching tokenMatching)
        {
            {
                IPopulateScope <IWeakTypeReference, ISetUpTypeReference> inputType = null, outputType = null;
                var matching = tokenMatching
                               .Has(new KeyWordMaker("method"), out var _)
                               .HasSquare(x => x
                                          .HasLine(y => y
                                                   .HasElement(z => z.Has(new TypeMaker(), out inputType))
                                                   .Has(new DoneMaker()))
                                          .HasLine(y => y
                                                   .HasElement(z => z.Has(new TypeMaker(), out outputType))
                                                   .Has(new DoneMaker()))
                                          .Has(new DoneMaker()))
                               .OptionalHas(new NameMaker(), out var parameterName)
                               .Has(new BodyMaker(), out var body);

                if (matching
                    is IMatchedTokenMatching matched)
                {
                    var elements = matching.Context.ParseBlock(body);

                    var parameterDefinition = MemberDefinitionMaker.PopulateScope(
                        new NameKey(parameterName?.Item ?? "input"),
                        false,
                        inputType
                        );

                    var resultDefinition = MemberDefinitionMaker.PopulateScope(
                        new ImplicitKey(),
                        false,
                        outputType
                        );

                    return(TokenMatching <IPopulateScope <WeakMethodDefinition, ISetUpMethod> > .MakeMatch(
                               matched.Tokens,
                               matched.Context,
                               new MethodDefinitionPopulateScope(
                                   parameterDefinition,
                                   elements,
                                   resultDefinition,
                                   false)
                               ));
                }
            }
            {
                var matching = tokenMatching
                               .Has(new KeyWordMaker("entry-point"), out var _)
                               .Has(new BodyMaker(), out var body);
                if (matching
                    is IMatchedTokenMatching matched)
                {
                    var elements = matching.Context.ParseBlock(body);

                    var parameterDefinition = MemberDefinitionMaker.PopulateScope(
                        new NameKey("input"),
                        false,
                        TypeReferanceMaker.PopulateScope(new NameKey("empty"))
                        );


                    var resultDefinition = MemberDefinitionMaker.PopulateScope(
                        new ImplicitKey(),
                        false,
                        TypeReferanceMaker.PopulateScope(new NameKey("empty"))
                        );

                    return(TokenMatching <IPopulateScope <WeakMethodDefinition, ISetUpMethod> > .MakeMatch(
                               matched.Tokens,
                               matched.Context,
                               new MethodDefinitionPopulateScope(
                                   parameterDefinition,
                                   elements,
                                   resultDefinition,
                                   true)
                               ));
                }

                return(TokenMatching <IPopulateScope <WeakMethodDefinition, ISetUpMethod> > .MakeNotMatch(
                           matching.Context));
            }
        }