Ejemplo n.º 1
0
        public ITokenMatching <ISetUp <IBox <WeakPathOperation>, Tpn.TypeProblem2.Member> > TryMake(IMatchedTokenMatching tokenMatching)
        {
            var matching = tokenMatching
                           .Has(new BinaryOperationMatcher(SymbolsRegistry.StaticPathSymbol), out (ISetUp lhs, ISetUp rhs)match);

            if (matching is IMatchedTokenMatching matched)
            {
                var left  = OrType.Make <ISetUp <IBox <IFrontendCodeElement>, Tpn.ITypeProblemNode>, IError>(match.lhs.SafeCastTo(out ISetUp <IBox <IFrontendCodeElement>, Tpn.ITypeProblemNode> _));
                var right = OrType.Make <MemberPopulateScope, IError>(match.rhs.SafeCastTo(out MemberPopulateScope _));


                var res = new WeakPathOperationPopulateScope(left, right.TransformInner(x => x.memberName));

                //if (left.Is1(out var leftValue))
                //{
                //    tokenMatching.Context.Map.SetElementParent(leftValue, res);
                //}
                //if (right.Is1(out var rightValue))
                //{
                //    tokenMatching.Context.Map.SetElementParent(rightValue, res);
                //}

                return(TokenMatching <ISetUp <IBox <WeakPathOperation>, Tpn.TypeProblem2.Member> > .MakeMatch(
                           tokenMatching,
                           res,
                           matched.EndIndex));
            }

            return(TokenMatching <ISetUp <IBox <WeakPathOperation>, Tpn.TypeProblem2.Member> > .MakeNotMatch(
                       matching.Context));
        }
Ejemplo n.º 2
0
        public ITokenMatching <ISetUp <IBox <WeakTryAssignOperation>, Tpn.IValue> > TryMake(IMatchedTokenMatching tokenMatching)
        {
            var index = tokenMatching.EndIndex;

            if (tokenMatching.AllTokens.Count - 3 > index &&
                tokenMatching.AllTokens[index + 1].Is1(out var token) && token.SafeIs(out AtomicToken op) &&
                op.Item == SymbolsRegistry.TryAssignSymbol &&
                tokenMatching.AllTokens[index].Is2(out var lhs) &&
                tokenMatching.AllTokens[index + 2].Is2(out var rhs) &&
                tokenMatching.AllTokens[index + 3].Is2(out var rrhs))
            {
                var left  = OrType.Make <ISetUp <IBox <IFrontendCodeElement>, Tpn.ITypeProblemNode>, IError>(lhs.SafeCastTo(out ISetUp <IBox <IFrontendCodeElement>, Tpn.ITypeProblemNode> _));
                var right = OrType.Make <ISetUp <IBox <IFrontendCodeElement>, Tpn.ITypeProblemNode>, IError>(rhs.SafeCastTo(out ISetUp <IBox <IFrontendCodeElement>, Tpn.ITypeProblemNode> _));
                var block = OrType.Make <ISetUp <IBox <IFrontendCodeElement>, Tpn.ITypeProblemNode>, IError>(rrhs.SafeCastTo(out ISetUp <IBox <IFrontendCodeElement>, Tpn.ITypeProblemNode> _));


                var res = new TryAssignOperationPopulateScope(left, right, block);

                return(TokenMatching <ISetUp <IBox <WeakTryAssignOperation>, Tpn.IValue> > .MakeMatch(
                           tokenMatching,
                           res,
                           tokenMatching.EndIndex + 4
                           ));
            }

            return(TokenMatching <ISetUp <IBox <WeakTryAssignOperation>, Tpn.IValue> > .MakeNotMatch(
                       tokenMatching.Context));
        }
Ejemplo n.º 3
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.º 4
0
        public ITokenMatching <ISetUp <IBox <IFrontendType <IVerifiableType> >, Tpn.TypeProblem2.TypeReference> > TryMake(IMatchedTokenMatching tokenMatching)
        {
            if (tokenMatching.AllTokens[tokenMatching.EndIndex].Is2(out var setUp) && setUp.SafeIs(out ISetUp <IBox <IFrontendType <IVerifiableType> >, Tpn.TypeProblem2.TypeReference> alreadyMatched))
            {
                return(TokenMatching <ISetUp <IBox <IFrontendType <IVerifiableType> >, Tpn.TypeProblem2.TypeReference> > .MakeMatch(
                           tokenMatching,
                           alreadyMatched,
                           tokenMatching.EndIndex + 1));
            }

            if (tokenMatching.AllTokens[tokenMatching.EndIndex].Is1(out var token) && token.SafeIs(out ParenthesisToken parenthesisToken) && parenthesisToken.Tokens.Count() == 1)
            {
                var line = parenthesisToken.Tokens.First().SafeCastTo(out LineToken _);

                var matching = TokenMatching <ISetUp <IBox <IFrontendType <IVerifiableType> >, Tpn.TypeProblem2.TypeReference> > .MakeStart(line.Tokens.Select(x => OrType.Make <IToken, ISetUp>(x)).ToArray(), tokenMatching.Context, 0);

                // you can be an or again (z | b) | c is legal
                var res = new TypeMaker().TryMake(matching);
                if (res is IMatchedTokenMatching <ISetUp <IBox <IFrontendType <IVerifiableType> >, Tpn.TypeProblem2.TypeReference> > matched)
                {
                    return(TokenMatching <ISetUp <IBox <IFrontendType <IVerifiableType> >, Tpn.TypeProblem2.TypeReference> > .MakeMatch(
                               tokenMatching,
                               matched.Value,
                               tokenMatching.EndIndex + 1));
                }
                else
                {
                    return(TokenMatching <ISetUp <IBox <IFrontendType <IVerifiableType> >, Tpn.TypeProblem2.TypeReference> > .MakeNotMatch(
                               tokenMatching.Context));
                }
            }


            {
                if (tokenMatching.Has(new TypeDefinitionMaker(), out var type)
                    is IMatchedTokenMatching matched)
                {
                    return(TokenMatching <ISetUp <IBox <IFrontendType <IVerifiableType> >, Tpn.TypeProblem2.TypeReference> > .MakeMatch(
                               tokenMatching,
                               type,
                               matched.EndIndex));
                }
            }

            {
                if (tokenMatching.Has(new TypeReferanceMaker(), out var type)
                    is IMatchedTokenMatching matched)
                {
                    return(TokenMatching <ISetUp <IBox <IFrontendType <IVerifiableType> >, Tpn.TypeProblem2.TypeReference> > .MakeMatch(
                               tokenMatching,
                               type,
                               matched.EndIndex));
                }
            }


            return(TokenMatching <ISetUp <IBox <IFrontendType <IVerifiableType> >, Tpn.TypeProblem2.TypeReference> > .MakeNotMatch(
                       tokenMatching.Context));
        }
Ejemplo n.º 5
0
        public ITokenMatching <CurleyBracketToken> TryMake(IMatchedTokenMatching self)
        {
            if (self.Tokens.Any() &&
                self.Tokens.First() is CurleyBracketToken first)
            {
                return(TokenMatching <CurleyBracketToken> .MakeMatch(self.Tokens.Skip(1).ToArray(), self.Context, first));
            }

            return(TokenMatching <CurleyBracketToken> .MakeNotMatch(self.Context));
        }
Ejemplo n.º 6
0
        public ITokenMatching <AtomicToken> TryMake(IMatchedTokenMatching self)
        {
            var index = self.EndIndex;

            if (self.AllTokens.Count > index && self.AllTokens[index].Is1(out var v1) && v1.SafeIs(out AtomicToken first) &&
                first.Item == word)
            {
                return(TokenMatching <AtomicToken> .MakeMatch(self, first, index + 1));
            }
            return(TokenMatching <AtomicToken> .MakeNotMatch(self.Context));
        }
Ejemplo n.º 7
0
        public ITokenMatching <double> TryMake(IMatchedTokenMatching self)
        {
            if (self.Tokens.Any() &&
                self.Tokens.First() is AtomicToken first &&
                double.TryParse(first.Item, out var res))
            {
                return(TokenMatching <double> .MakeMatch(self.Tokens.Skip(1).ToArray(), self.Context, res));
            }

            return(TokenMatching <double> .MakeNotMatch(self.Context));
        }
Ejemplo n.º 8
0
        public ITokenMatching <AtomicToken> TryMake(IMatchedTokenMatching elementToken)
        {
            if (elementToken.Tokens.Any() &&
                elementToken.Tokens.First() is AtomicToken first &&
                !double.TryParse(first.Item, out var _) &&
                IsNotKeyWord(first.Item))
            {
                return(TokenMatching <AtomicToken> .MakeMatch(elementToken.Tokens.Skip(1).ToArray(), elementToken.Context, first));
            }

            return(TokenMatching <AtomicToken> .MakeNotMatch(elementToken.Context));
        }
Ejemplo n.º 9
0
        public ITokenMatching <IPopulateScope <WeakConstantString, ISetUpValue> > TryMake(IMatchedTokenMatching tokenMatching)
        {
            var match = tokenMatching
                        .Has(new StringMaker(), out var str);

            if (match
                is IMatchedTokenMatching matched)
            {
                return(TokenMatching <IPopulateScope <WeakConstantString, ISetUpValue> > .MakeMatch(matched.Tokens.Skip(1).ToArray(), matched.Context, new ConstantStringPopulateScope(str)));
            }
            return(TokenMatching <IPopulateScope <WeakConstantString, ISetUpValue> > .MakeNotMatch(tokenMatching.Context));
        }
Ejemplo n.º 10
0
            public ITokenMatching <string> TryMake(IMatchedTokenMatching self)
            {
                if (self.Tokens.Any() &&
                    self.Tokens.First() is AtomicToken first &&
                    first.Item.StartsWith('"') && first.Item.EndsWith('"'))
                {
                    var res = first.Item.Substring(1, first.Item.Length - 2);
                    return(TokenMatching <string> .MakeMatch(self.Tokens.Skip(1).ToArray(), self.Context, res));
                }

                return(TokenMatching <string> .MakeNotMatch(self.Context));
            }
Ejemplo n.º 11
0
        public ITokenMatching <CurleyBracketToken> TryMake(IMatchedTokenMatching self)
        {
            var index = self.EndIndex;

            if (self.AllTokens.Count > index &&
                self.AllTokens[index].Is1(out var v1) && v1.SafeIs(out CurleyBracketToken first))
            {
                return(TokenMatching <CurleyBracketToken> .MakeMatch(self, first, index + 1));
            }

            return(TokenMatching <CurleyBracketToken> .MakeNotMatch(self.Context));
        }
Ejemplo n.º 12
0
        public ITokenMatching <ISetUp <IBox <WeakConstantNumber>, Tpn.IValue> > TryMake(IMatchedTokenMatching tokenMatching)
        {
            var match = tokenMatching
                        .Has(new NumberMaker(), out var dub);

            if (match
                is IMatchedTokenMatching matched)
            {
                return(TokenMatching <ISetUp <IBox <WeakConstantNumber>, Tpn.IValue> > .MakeMatch(tokenMatching, new ConstantNumberPopulateScope(dub), matched.EndIndex));
            }
            return(TokenMatching <ISetUp <IBox <WeakConstantNumber>, Tpn.IValue> > .MakeNotMatch(tokenMatching.Context));
        }
Ejemplo n.º 13
0
        public ITokenMatching <IKey> TryMake(IMatchedTokenMatching self)
        {
            var index = self.EndIndex;

            if (self.AllTokens.Count > index &&
                self.AllTokens[index].Is1(out var v1) && v1.SafeIs(out AtomicToken first) &&
                !double.TryParse(first.Item, out var _) &&
                IsNotKeyWord(first.Item))
            {
                {
                    var at = TokenMatching <NameKey> .MakeStart(self.AllTokens, self.Context, index + 1);

                    var match = new DefineGenericNMaker().TryMake(at);
                    if (match.SafeIs(out IMatchedTokenMatching <string[]> mathced))
                    {
                        var at2 = TokenMatching <NameKey> .MakeStart(self.AllTokens, self.Context, index + 2);

                        var match2 = new GenericNMaker().TryMake(at2);

                        if (match2.SafeIs(out IMatchedTokenMatching <IKey[]> mathced2))
                        {
                            return(TokenMatching <IKey> .MakeMatch(
                                       self,
                                       new DoubleGenericNameKey(
                                           new NameKey(first.Item),
                                           mathced.Value.Select(x => new NameKey(x)).ToArray(),
                                           mathced2.Value.Select(x => OrType.Make <IKey, IError>(x)).ToArray()),
                                       mathced2.EndIndex));
                        }
                    }
                }

                {
                    var at = TokenMatching <NameKey> .MakeStart(self.AllTokens, self.Context, index + 1);

                    var match = new GenericNMaker().TryMake(at);
                    if (match.SafeIs(out IMatchedTokenMatching <IKey[]> mathced))
                    {
                        return(TokenMatching <IKey> .MakeMatch(
                                   self,
                                   new GenericNameKey(
                                       new NameKey(first.Item),
                                       mathced.Value.Select(x => OrType.Make <IKey, IError>(x)).ToArray()),
                                   mathced.EndIndex));
                    }
                }

                return(TokenMatching <IKey> .MakeMatch(self, new NameKey(first.Item), index + 1));
            }

            return(TokenMatching <IKey> .MakeNotMatch(self.Context));
        }
Ejemplo n.º 14
0
        public ITokenMatching <AtomicToken> TryMake(IMatchedTokenMatching elementToken)
        {
            var index = elementToken.EndIndex;

            if (elementToken.AllTokens.Count > index &&
                elementToken.AllTokens[index].Is1(out var v1) && v1.SafeIs(out AtomicToken first) &&
                first.Item == s)
            {
                return(TokenMatching <AtomicToken> .MakeMatch(elementToken, first, index + 1));
            }

            return(TokenMatching <AtomicToken> .MakeNotMatch(elementToken.Context));
        }
Ejemplo n.º 15
0
        public ITokenMatching <double> TryMake(IMatchedTokenMatching self)
        {
            var index = self.EndIndex;

            if (self.AllTokens.Count > index &&
                self.AllTokens[index].Is1(out var v1) && v1.SafeIs(out AtomicToken first) &&
                double.TryParse(first.Item, out var res))
            {
                return(TokenMatching <double> .MakeMatch(self, res, index + 1));
            }

            return(TokenMatching <double> .MakeNotMatch(self.Context));
        }
Ejemplo n.º 16
0
        public ITokenMatching <IPopulateScope <WeakEmptyInstance, ISetUpValue> > TryMake(IMatchedTokenMatching tokenMatching)
        {
            // change key word to nothing?
            var match = tokenMatching
                        .Has(new KeyWordMaker("new-empty"), out var _);

            if (match
                is IMatchedTokenMatching matched)
            {
                return(TokenMatching <IPopulateScope <WeakEmptyInstance, ISetUpValue> > .MakeMatch(matched.Tokens.Skip(1).ToArray(), matched.Context, new EmptyInstancePopulateScope()));
            }
            return(TokenMatching <IPopulateScope <WeakEmptyInstance, ISetUpValue> > .MakeNotMatch(tokenMatching.Context));
        }
Ejemplo n.º 17
0
        public ITokenMatching <ISetUp <IBox <IFrontendType <IVerifiableType> >, Tpn.TypeProblem2.TypeReference> > TryMake(IMatchedTokenMatching tokenMatching)
        {
            var at = tokenMatching.EndIndex;

            if (tokenMatching.AllTokens[at].Is2(out var v2) && v2.SafeIs(out ISetUp <IBox <IFrontendType <IVerifiableType> >, Tpn.TypeProblem2.TypeReference> mySetUp))
            {
                return(TokenMatching <ISetUp <IBox <IFrontendType <IVerifiableType> >, Tpn.TypeProblem2.TypeReference> > .MakeMatch(
                           tokenMatching,
                           mySetUp,
                           tokenMatching.EndIndex + 1));
            }
            return(TokenMatching <ISetUp <IBox <IFrontendType <IVerifiableType> >, Tpn.TypeProblem2.TypeReference> > .MakeNotMatch(tokenMatching.Context));
        }
Ejemplo n.º 18
0
        public ITokenMatching <IPopulateScope <IWeakTypeReference, ISetUpTypeReference> > TryMake(IMatchedTokenMatching tokenMatching)
        {
            {
                if (tokenMatching.Has(new TypeDefinitionMaker(), out var type)
                    is IMatchedTokenMatching matched)
                {
                    return(TokenMatching <IPopulateScope <IWeakTypeReference, ISetUpTypeReference> > .MakeMatch(
                               matched.Tokens,
                               matched.Context,
                               type));
                }
            }


            {
                if (tokenMatching.Has(new TypeReferanceMaker(), out var type)
                    is IMatchedTokenMatching matched)
                {
                    return(TokenMatching <IPopulateScope <IWeakTypeReference, ISetUpTypeReference> > .MakeMatch(
                               matched.Tokens,
                               matched.Context,
                               type));
                }
            }

            // TODO

            // I need a more well-rounded approach to parenthesis
            // I don't think this will work generally at all

            // gosh, what to do? I don't really want to kick the can down the road,
            // but I don't feel like I understand it well enough to make changes

            // I mean for the short term I am just going to jam all the type operators in here
            // maybe that is ok

            if (tokenMatching.Tokens.First() is ParenthesisToken parenthesisToken)
            {
                if (TokenMatching <IPopulateScope <IWeakTypeReference, ISetUpType> > .MakeStart(parenthesisToken.Tokens.ToArray(), tokenMatching.Context).Has(new TypeOrOperationMaker(), out var type)
                    is IMatchedTokenMatching matched)
                {
                    return(TokenMatching <IPopulateScope <IWeakTypeReference, ISetUpTypeReference> > .MakeMatch(
                               tokenMatching.Tokens.Skip(1).ToArray(),
                               matched.Context,
                               type));
                }
            }

            return(TokenMatching <IPopulateScope <IWeakTypeReference, ISetUpTypeReference> > .MakeNotMatch(
                       tokenMatching.Context));
        }
Ejemplo n.º 19
0
        public ITokenMatching <IPopulateScope <IWeakTypeReference, ISetUpTypeReference> > TryMake(IMatchedTokenMatching tokenMatching)
        {
            var matching = tokenMatching
                           .Has(new TypeNameMaker(), out var name);

            if (matching is IMatchedTokenMatching matched)
            {
                return(TokenMatching <IPopulateScope <IWeakTypeReference, ISetUpTypeReference> > .MakeMatch(
                           matched.Tokens,
                           matched.Context,
                           new TypeReferancePopulateScope(name)));
            }

            return(TokenMatching <IPopulateScope <IWeakTypeReference, ISetUpTypeReference> > .MakeNotMatch(matching.Context));
        }
Ejemplo n.º 20
0
        public ITokenMatching <IPopulateScope <WeakMemberReference, ISetUpMember> > TryMake(IMatchedTokenMatching tokenMatching)
        {
            var matching = tokenMatching
                           .Has(new NameMaker(), out var first);

            if (matching is IMatchedTokenMatching matched)
            {
                return(TokenMatching <IPopulateScope <WeakMemberReference, ISetUpMember> > .MakeMatch(
                           matched.Tokens,
                           matched.Context,
                           new MemberPopulateScope(first.Item)));;
            }
            return(TokenMatching <IPopulateScope <WeakMemberReference, ISetUpMember> > .MakeNotMatch(
                       matching.Context));
        }
Ejemplo n.º 21
0
        public ITokenMatching <IPopulateScope <WeakBlockDefinition, ISetUpScope> > TryMake(IMatchedTokenMatching tokenMatching)
        {
            var match = tokenMatching
                        .Has(new BodyMaker(), out var body);

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

                return(TokenMatching <IPopulateScope <WeakBlockDefinition, ISetUpScope> > .MakeMatch(matched.Tokens.Skip(1).ToArray(), matched.Context,
                                                                                                     new BlockDefinitionPopulateScope(elements)));
            }

            return(TokenMatching <IPopulateScope <WeakBlockDefinition, ISetUpScope> > .MakeNotMatch(tokenMatching.Context));
        }
Ejemplo n.º 22
0
        public ITokenMatching <ISetUp <IBox <WeakBlockDefinition>, Tpn.IScope> > TryMake(IMatchedTokenMatching tokenMatching)
        {
            var match = tokenMatching
                        .Has(new BodyMaker(), out var body);

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

                return(TokenMatching <ISetUp <IBox <WeakBlockDefinition>, Tpn.IScope> > .MakeMatch(tokenMatching,
                                                                                                   new BlockDefinitionPopulateScope(elements), matched.EndIndex));
            }

            return(TokenMatching <ISetUp <IBox <WeakBlockDefinition>, Tpn.IScope> > .MakeNotMatch(tokenMatching.Context));
        }
Ejemplo n.º 23
0
        public ITokenMatching <ISetUp> TryMake(IMatchedTokenMatching self)
        {
            var index = self.EndIndex;

            if (self.AllTokens.Count - 1 > index &&
                self.AllTokens[index + 1].Is1(out var v1) &&
                v1.SafeIs(out AtomicToken op) &&
                op.Item == s &&
                self.AllTokens[index].Is2(out var setUp))
            {
                return(TokenMatching <ISetUp> .MakeMatch(self, setUp, index + 2));
            }


            return(TokenMatching <ISetUp> .MakeNotMatch(self.Context));
        }
Ejemplo n.º 24
0
            public ITokenMatching <bool> TryMake(IMatchedTokenMatching self)
            {
                if (self.Tokens.Any() &&
                    self.Tokens.First() is AtomicToken first)
                {
                    if (first.Item == "true")
                    {
                        return(TokenMatching <bool> .MakeMatch(self.Tokens.Skip(1).ToArray(), self.Context, true));
                    }
                    else if (first.Item == "false")
                    {
                        return(TokenMatching <bool> .MakeMatch(self.Tokens.Skip(1).ToArray(), self.Context, false));
                    }
                }

                return(TokenMatching <bool> .MakeNotMatch(self.Context));
            }
Ejemplo n.º 25
0
        public ITokenMatching <IPopulateScope <TFrontendCodeElement> > TryMake(IMatchedTokenMatching tokenMatching)
        {
            var matching = tokenMatching
                           .Has(new TrailingOperationMatcher(Symbol), out (IEnumerable <IToken> perface, AtomicToken _)res);

            if (matching is IMatchedTokenMatching matched)
            {
                var left = matching.Context.ParseLine(res.perface);

                return(TokenMatching <IPopulateScope <TFrontendCodeElement> > .MakeMatch(
                           matched.Tokens,
                           matched.Context,
                           new TrailingPopulateScope(left, Make)));
            }
            return(TokenMatching <IPopulateScope <TFrontendCodeElement> > .MakeNotMatch(
                       matching.Context));
        }
Ejemplo n.º 26
0
        public ITokenMatching <IPopulateScope <WeakMemberReference, ISetUpMember> > TryMake(IMatchedTokenMatching tokenMatching)
        {
            var matching = tokenMatching
                           .OptionalHas(new KeyWordMaker("readonly"), out var readonlyToken)
                           .Has(new TypeMaker(), out var type)
                           .Has(new NameMaker(), out var nameToken);

            if (matching is IMatchedTokenMatching matched)
            {
                return(TokenMatching <IPopulateScope <WeakMemberReference, ISetUpMember> > .MakeMatch(
                           matched.Tokens,
                           matched.Context,
                           new MemberDefinitionPopulateScope(new NameKey(nameToken.Item), readonlyToken != default, type)));
            }
            return(TokenMatching <IPopulateScope <WeakMemberReference, ISetUpMember> > .MakeNotMatch(
                       matching.Context));
        }
Ejemplo n.º 27
0
            public ITokenMatching <bool> TryMake(IMatchedTokenMatching self)
            {
                if (self.AllTokens.Count > self.EndIndex &&
                    self.AllTokens[self.EndIndex].Is1(out var token) && token.SafeIs(out AtomicToken first))
                {
                    if (first.Item == "true")
                    {
                        return(TokenMatching <bool> .MakeMatch(self, true, self.EndIndex + 1));
                    }
                    else if (first.Item == "false")
                    {
                        return(TokenMatching <bool> .MakeMatch(self, false, self.EndIndex + 1));
                    }
                }

                return(TokenMatching <bool> .MakeNotMatch(self.Context));
            }
Ejemplo n.º 28
0
        public ITokenMatching <string[]> TryMake(IMatchedTokenMatching self)
        {
            var index = self.EndIndex;

            if (self.AllTokens.Count > index &&
                self.AllTokens[index].Is1(out var v1) && v1.SafeIs(out SquareBacketToken typeParameters) &&
                typeParameters.Tokens.All(x => x.SafeIs(out LineToken line) &&
                                          line.Tokens.Count == 1 &&
                                          line.Tokens.ElementAt(0).SafeIs(out AtomicToken _)))
            {
                return(TokenMatching <string[]> .MakeMatch(self,
                                                           typeParameters.Tokens.Select(x => x.CastTo <LineToken>().Tokens.Single().CastTo <AtomicToken>().Item).ToArray(),
                                                           index + 1));
            }

            return(TokenMatching <string[]> .MakeNotMatch(self.Context));
        }
Ejemplo n.º 29
0
        public ITokenMatching <IPopulateScope <WeakObjectDefinition, ISetUpObject> > TryMake(IMatchedTokenMatching tokenMatching)
        {
            var matching = tokenMatching
                           .Has(new KeyWordMaker("object"), out var _)
                           .Has(new BodyMaker(), out var block);

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

                return(TokenMatching <IPopulateScope <WeakObjectDefinition, ISetUpObject> > .MakeMatch(
                           matched.Tokens,
                           matched.Context,
                           new ObjectDefinitionPopulateScope(elements)));
            }
            return(TokenMatching <IPopulateScope <WeakObjectDefinition, ISetUpObject> > .MakeNotMatch(
                       matching.Context));
        }
Ejemplo n.º 30
0
        public ITokenMatching <ISetUp <IBox <WeakImplementationDefinition>, Tpn.IValue> > TryMake(IMatchedTokenMatching tokenMatching)
        {
            // this is not great
            // but the typing here is hard to get right
#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
            ISetUp <IBox <IFrontendType <IVerifiableType> >, Tpn.TypeProblem2.TypeReference> context = null, input = null, output = null;
#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type.

            var match = tokenMatching
                        .Has(new KeyWordMaker("implementation"), out var _)
                        .HasSquare(x => x
                                   .HasLine(y => y
                                            .Has(new TypeMaker(), out context)
                                            .Has(new DoneMaker()))
                                   .HasLine(y => y
                                            .Has(new TypeMaker(), out input)
                                            .Has(new DoneMaker()))
                                   .HasLine(y => y
                                            .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 !);


                return(TokenMatching <ISetUp <IBox <WeakImplementationDefinition>, IValue> > .MakeMatch(
                           tokenMatching,
                           new PopulateScopeImplementationDefinition(
                               context !,
                               input !,
                               elements,
                               output !,
                               contextName?.Item ?? "context",
                               parameterName?.Item ?? "input"),
                           matched.EndIndex));
            }


            return(TokenMatching <ISetUp <IBox <WeakImplementationDefinition>, IValue> > .MakeNotMatch(match.Context));
        }