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)); }
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)); }
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)); }
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)); }
public static bool TryToToken(ElementMatchingContext context, SquareBacketToken typeParameters, out IKey[]?typeSourcesInner) { var typeSourcesBuilding = new List <IKey>(); foreach (var elementToken in typeParameters.Tokens.OfType <LineToken>()) { var matcher = TokenMatching <object> .MakeStart(elementToken.Tokens.Select(x => OrType.Make <IToken, ISetUp>(x)).ToArray(), context, 0); IKey?typeSource = null; if (matcher .Has(new TypeNameMaker(), out typeSource) .Has(new DoneMaker()).SafeIs(out IMatchedTokenMatching <IKey?> _)) { typeSourcesBuilding.Add(typeSource !); } else { typeSourcesInner = default; return(false); } } typeSourcesInner = typeSourcesBuilding.ToArray(); return(true); }