Пример #1
0
 public ITokenMatching <string> TryMake(IMatchedTokenMatching self)
 {
     if (self.EndIndex < self.AllTokens.Count &&
         self.AllTokens[self.EndIndex].Is1(out var token) && token.SafeIs(out AtomicToken first) &&
         first.Item.StartsWith('"') && first.Item.EndsWith('"'))
     {
         var res = first.Item[1..^ 1];
Пример #2
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));
        }
Пример #3
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));
        }
Пример #4
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));
        }
Пример #5
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));
        }
Пример #6
0
        public ITokenMatching <IKey[]> TryMake(IMatchedTokenMatching elementToken)
        {
            if (elementToken.Has(new GenericNMaker(), out var collection).SafeIs(out IMatchedTokenMatching <IKey[]> matched))
            {
                return(TokenMatching <IKey[]> .MakeMatch(
                           elementToken,
                           collection !,
                           matched.EndIndex));
            }

            return(TokenMatching <IKey[]> .MakeNotMatch(elementToken.Context));
        }
Пример #7
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));
            }
Пример #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));
        }
Пример #9
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));
        }
Пример #10
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));
        }
Пример #11
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));
        }
Пример #12
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));
        }
Пример #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 SquareBacketToken typeParameters) &&
                typeParameters.Tokens.All(x => x.SafeIs(out LineToken lt) && lt.Tokens.First().SafeIs(out AtomicToken _)) &&
                TryToToken(self.Context, typeParameters, out var res))
            {
                return(TokenMatching <IKey[]> .MakeMatch(
                           self,
                           res !,
                           index + 1));
            }

            return(TokenMatching <IKey[]> .MakeNotMatch(self.Context));
        }
Пример #14
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));
        }
Пример #15
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));
        }
Пример #16
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));
            }
Пример #17
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));
            }
Пример #18
0
        public ITokenMatching <IKey> TryMake(IMatchedTokenMatching tokenMatching)
        {
            var matching = tokenMatching
                           .Has(new NameMaker(), out var typeName);

            if (matching is IMatchedTokenMatching matched)
            {
                var list            = new List <IKey>();
                var genericMatachig = matching
                                      .HasSquare(x =>
                {
                    while (true)
                    {
                        // colin, why! w x y z
                        // you are an adult arn't you?
                        var item = default(IKey);
                        var y    = x.HasLine(z => z.Has(new KeyMatcher(), out item));
                        if (y is IMatchedTokenMatching w)
                        {
                            x = w;
                            list.Add(item !);
                            if (w.AllTokens.Any().Not())
                            {
                                return(w);
                            }
                        }
                        else
                        {
                            return(y);
                        }
                    }
                });


                if (genericMatachig is IMatchedTokenMatching genericMatched)
                {
                    return(TokenMatching <IKey> .MakeMatch(tokenMatching, new GenericNameKey(new NameKey(typeName.Item), list.Select(x => OrType.Make <IKey, IError>(x)).ToArray().ToArray()), genericMatched.EndIndex));
                }
                return(TokenMatching <IKey> .MakeMatch(tokenMatching, new NameKey(typeName.Item), matched.EndIndex));
            }

            return(TokenMatching <IKey> .MakeNotMatch(matching.Context));
        }
Пример #19
0
        public ITokenMatching <IPopulateScope <WeakAssignOperation> > TryMake(IMatchedTokenMatching tokenMatching)
        {
            var matching = tokenMatching
                           .Has(new BinaryOperationMatcher(SymbolsRegistry.StaticAssertAssignSymbol), out (IReadOnlyList <IToken> perface, AtomicToken token, IToken rhs)match);

            if (matching is IMatchedTokenMatching matched)
            {
                var left  = matching.Context.ParseLine(match.perface);
                var right = matching.Context.ParseParenthesisOrElement(match.rhs);

                return(TokenMatching <IPopulateScope <WeakAssignOperation> > .MakeMatch(
                           matched.Tokens,
                           matched.Context,
                           new WeakAssignOperationPopulateScope(left, right)));
            }

            return(TokenMatching <IPopulateScope <WeakAssignOperation> > .MakeNotMatch(
                       matching.Context));
        }
Пример #20
0
        public ITokenMatching <IPopulateScope <IWeakTypeReference> > TryMake(IMatchedTokenMatching tokenMatching)
        {
            var matching = tokenMatching
                           .Has(new BinaryOperationMatcher(Symbol), out (IReadOnlyList <IToken> perface, AtomicToken token, IToken rhs)match);

            if (matching is IMatchedTokenMatching matched)
            {
                var left  = matching.Context.ParseTypeLine(match.perface);
                var right = matching.Context.ParseParenthesisOrElementType(match.rhs);

                return(TokenMatching <IPopulateScope <IWeakTypeReference> > .MakeMatch(
                           matched.Tokens,
                           matched.Context,
                           new BinaryPopulateScope(left, right, Make)));
            }

            return(TokenMatching <IPopulateScope <IWeakTypeReference> > .MakeNotMatch(
                       matching.Context));
        }
Пример #21
0
        public ITokenMatching <NameKey> TryMake(IMatchedTokenMatching self)
        {
            if (self.Tokens.Any() &&
                self.Tokens.First() is AtomicToken first &&
                !double.TryParse(first.Item, out var _))
            {
                var at = TokenMatching <NameKey> .MakeStart(self.Tokens.Skip(1).ToArray(), self.Context);

                var match = new GenericNMaker().TryMake(at);
                if (match is IMatchedTokenMatching <NameKey[]> mathced)
                {
                    return(TokenMatching <NameKey> .MakeMatch(
                               self.Tokens.Skip(2).ToArray(),
                               self.Context,
                               new GenericNameKey(new NameKey(first.Item), mathced.Value)));
                }

                return(TokenMatching <NameKey> .MakeMatch(self.Tokens.Skip(1).ToArray(), self.Context, new NameKey(first.Item)));
            }

            return(TokenMatching <NameKey> .MakeNotMatch(self.Context));
        }
Пример #22
0
        public ITokenMatching <IPopulateScope <WeakTryAssignOperation> > TryMake(IMatchedTokenMatching tokenMatching)
        {
            var matching = tokenMatching
                           .Has(new BinaryOperationMatcher(SymbolsRegistry.TryAssignSymbol), out (IReadOnlyList <IToken> perface, AtomicToken token, IToken rhs)res);

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

                return(TokenMatching <IPopulateScope <WeakTryAssignOperation> > .MakeMatch(
                           matched.Tokens,
                           matched.Context,
                           BinaryOperationMaker <WeakTryAssignOperation, ITryAssignOperation> .PopulateScope(left, right, (l, r) =>
                                                                                                             Possibly.Is(
                                                                                                                 new WeakTryAssignOperation(l, r)))));
            }

            return(TokenMatching <IPopulateScope <WeakTryAssignOperation> > .MakeNotMatch(
                       matching.Context));
        }
Пример #23
0
        public ITokenMatching <IPopulateScope <WeakPathOperation> > TryMake(IMatchedTokenMatching tokenMatching)
        {
            var matching = tokenMatching
                           .Has(new BinaryOperationMatcher(SymbolsRegistry.StaticPathSymbol), out (IReadOnlyList <IToken> perface, AtomicToken token, IToken rhs)match);

            if (matching is IMatchedTokenMatching matched)
            {
                var matching2 = matched.Has(new NameMaker(), out var first);
                if (matching2 is IMatchedTokenMatching matched2)
                {
                    var left = matching.Context.ParseLine(match.perface);
                    //var right = matching.Context.ExpectPathPart(box).ParseParenthesisOrElement(match.rhs);

                    return(TokenMatching <IPopulateScope <WeakPathOperation> > .MakeMatch(
                               matched2.Tokens,
                               matched2.Context,
                               new WeakPathOperationPopulateScope(left, first.Item)));
                }
            }

            return(TokenMatching <IPopulateScope <WeakPathOperation> > .MakeNotMatch(
                       matching.Context));
        }
Пример #24
0
        public ITokenMatching <IPopulateScope <WeakModuleDefinition, ISetUpObject> > TryMake(IMatchedTokenMatching tokenMatching)
        {
            var matching = tokenMatching
                           .Has(new KeyWordMaker("module"), out _)
                           .Has(new NameMaker(), out var name)
                           .Has(new BodyMaker(), out var third);

            if (matching is IMatchedTokenMatching matched)
            {
                var elements = matching.Context.ParseBlock(third);
                var nameKey  = new NameKey(name.Item);

                return(TokenMatching <IPopulateScope <WeakModuleDefinition, ISetUpObject> > .MakeMatch(
                           matched.Tokens,
                           matched.Context,
                           new ModuleDefinitionPopulateScope(elements, nameKey)));
            }
            return(TokenMatching <IPopulateScope <WeakModuleDefinition, ISetUpObject> > .MakeNotMatch(
                       matching.Context));
        }
Пример #25
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));
        }
Пример #26
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));
        }
Пример #27
0
 public ITokenMatching <ISetUp <IBox <IFrontendType <IVerifiableType> >, Tpn.TypeProblem2.TypeReference> > TryMake(IMatchedTokenMatching tokenMatching)
 {
     return(tokenMatching
            .Has(new TypeNameMaker())
            .ConvertIfMatched(name => new TypeReferancePopulateScope(name), tokenMatching));
 }
Пример #28
0
 public ITokenMatching <ISetUp <IBox <WeakGenericTypeDefinition>, Tpn.IExplicitType> > TryMake(IMatchedTokenMatching tokenMatching)
 {
     return(tokenMatching
            .Has(new KeyWordMaker("type"), out var _)
            .Has(new DefineGenericNMaker())
            .Has(new NameMaker())
            .Has(new BodyMaker())
            .ConvertIfMatched((_, generics, name, lines) => {
         return new GenericTypeDefinitionPopulateScope(
             new NameKey(name.Item),
             tokenMatching.Context.ParseBlock(lines),
             generics.Select(x => new NameKey(x)).ToArray());
     }, tokenMatching));
 }
Пример #29
0
 public ITokenMatching <ISetUp <IBox <WeakMemberReference>, Tpn.TypeProblem2.Member> > TryMake(IMatchedTokenMatching tokenMatching)
 {
     return(tokenMatching
            .Has(new NameMaker())
            .ConvertIfMatched(token => new MemberPopulateScope(token.Item), tokenMatching));
 }
Пример #30
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));
        }