コード例 #1
0
ファイル: BasicMakers.cs プロジェクト: rauldoblem/Tac
        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));
        }
コード例 #2
0
        public ITokenMatching <ISetUp <IBox <WeakRealizeMethodOperation>, Tpn.IValue> > TryMake(IMatchedTokenMatching tokenMatching)
        {
            var index = tokenMatching.EndIndex;

            if (tokenMatching.AllTokens.Count - 2 > 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].Is1(out var rhs) && rhs.SafeIs(out SquareBacketToken square) && GenericNMaker.TryToToken(tokenMatching.Context, square, out var types))
            {
                return(TokenMatching <ISetUp <IBox <WeakRealizeMethodOperation>, Tpn.IValue> > .MakeMatch(
                           tokenMatching,
                           new RealizeMethodOperationPopulateScope(
                               lhs,
                               types !.Select(key => new TypeReferancePopulateScope(key)).ToArray()),
                           tokenMatching.EndIndex + 3));
            }

            return(TokenMatching <ISetUp <IBox <WeakRealizeMethodOperation>, Tpn.IValue> > .MakeNotMatch(tokenMatching.Context));
        }