private IParseResult <ExpressionMetaData> TryGetGroupExpression(ITokenStream tokenStream, out IExpression expression) { tokenStream.Pop(); var closePrecedenceToken = tokenStream.LookAhead(0).GetType <RegexTokenType>(); if (closePrecedenceToken == RegexTokenType.ClosePrecedence) { tokenStream.Pop(); expression = new EmptyExpression(); return(new SuccessParseResult <ExpressionMetaData>(tokenStream.CurrentPosition, new ExpressionMetaData())); } var unionExpressionResult = TryGetUnionExpression <UnionExpression>(tokenStream, out expression); if (!unionExpressionResult.IsSuccess) { return(unionExpressionResult); } closePrecedenceToken = tokenStream.LookAhead(0).GetType <RegexTokenType>(); if (closePrecedenceToken != RegexTokenType.ClosePrecedence) { return(new FailureParseResult <ExpressionMetaData>(tokenStream.CurrentPosition, RegSeedErrorType.ClosePrecedenceExpected)); } tokenStream.Pop(); return(new SuccessParseResult <ExpressionMetaData>(tokenStream.CurrentPosition, unionExpressionResult.Value)); }
private static IntegerInterval GetRepeatConcatenationInterval(ITokenStream tokenStream) { var nextToken = tokenStream.LookAhead(0).GetType <RegexTokenType>(); return(nextToken != RegexTokenType.IntegerRange ? new IntegerInterval(1) : tokenStream.Pop().GetValue <IntegerInterval>()); }
private IParseResult <ExpressionMetaData> TryGetCharacterClassExpression(ITokenStream tokenStream, out IExpression expression) { expression = null; var nextTokenType = tokenStream.Pop().GetType <RegexTokenType>(); var getComplement = nextTokenType == RegexTokenType.OpenNegateCharacterClass; nextTokenType = tokenStream.LookAhead(0).GetType <RegexTokenType>(); var characters = new List <string>(); while (nextTokenType == RegexTokenType.Character || nextTokenType == RegexTokenType.CharacterRange) { var nextToken = tokenStream.Pop(); if (nextToken.GetType <RegexTokenType>() == RegexTokenType.Character) { characters.Add(nextToken.GetValue <string>()); } else { characters.AddRange(nextToken.GetValue <CharacterRange>().Characters); } nextTokenType = tokenStream.LookAhead(0).GetType <RegexTokenType>(); } if (nextTokenType != RegexTokenType.CloseCharacterClass) { return(new FailureParseResult <ExpressionMetaData>(tokenStream.CurrentPosition, RegSeedErrorType.CloseCharacterClassExpected)); } tokenStream.Pop(); var characterClassExpression = new CharacterClassExpression(_alphabet, _random, _maxCharClassInverseLength); characterClassExpression.AddCharacters(characters); expression = getComplement ? characterClassExpression.GetComplement() : characterClassExpression; return(new SuccessParseResult <ExpressionMetaData>(tokenStream.CurrentPosition, new ExpressionMetaData())); }
private IParseResult <ExpressionMetaData> TryGetAnyCharacterExpression(ITokenStream tokenStream, out IExpression expression) { tokenStream.Pop(); var characterExpression = new CharacterClassExpression(_alphabet, _random, _maxCharClassInverseLength); characterExpression.AddCharacters(_alphabet.GetAllCharacters()); expression = characterExpression; return(new SuccessParseResult <ExpressionMetaData>(tokenStream.CurrentPosition, new ExpressionMetaData())); }
private IParseResult <ExpressionMetaData> TryGetSingleCharacterExpression(ITokenStream tokenStream, out IExpression expression) { expression = null; var tokenValue = tokenStream.Pop().GetValue <string>(); var characterClassExpression = new CharacterClassExpression(_alphabet, _random, _maxCharClassInverseLength); characterClassExpression.AddCharacters(new List <string> { tokenValue }); expression = characterClassExpression; return(new SuccessParseResult <ExpressionMetaData>(tokenStream.CurrentPosition, new ExpressionMetaData())); }
private IParseResult <ExpressionMetaData> TryGetInverseElementaryExpression(ITokenStream tokenStream, out IExpression expression) { expression = null; tokenStream.Pop(); var elementaryResult = TryGetElementaryExpression(tokenStream, out var toInvertExpression); if (!elementaryResult.IsSuccess) { return(elementaryResult); } expression = toInvertExpression.GetInverse(); expression.MaxExpansionRange = IntegerInterval.MaxInterval; return(new SuccessParseResult <ExpressionMetaData>(tokenStream.CurrentPosition, elementaryResult.Value)); }
private IParseResult <ExpressionMetaData> TryGetSubExpressionList(RegexTokenType token, ITokenStream tokenStream, out List <IExpression> subExpressionList) { subExpressionList = null; var subExpressionResult = _regexTokenToExpressionListMapper[token](tokenStream, out var subExpression); if (!subExpressionResult.IsSuccess) { return(subExpressionResult); } subExpressionList = new List <IExpression> { subExpression }; var nextToken = tokenStream.LookAhead(0).GetType <RegexTokenType>(); var metaData = subExpressionResult.Value; while (nextToken == token) { if (token == RegexTokenType.Intersection) { metaData.HasIntersection = true; } tokenStream.Pop(); subExpressionResult = _regexTokenToExpressionListMapper[token](tokenStream, out subExpression); if (!subExpressionResult.IsSuccess) { return(subExpressionResult); } metaData.UpdateWith(subExpressionResult.Value); subExpressionList.Add(subExpression); nextToken = tokenStream.LookAhead(0).GetType <RegexTokenType>(); } return(new SuccessParseResult <ExpressionMetaData>(tokenStream.CurrentPosition, metaData)); }