Ejemplo n.º 1
0
        public void TryGetToken_ReturnsFailureResult_WhenInputIsNoCharacterOrClassRange()
        {
            _primitiveParser.TryParseCharacterRange(Arg.Any <IStringStream>()).Returns(_classRangeParserFailure);
            _primitiveParser.TryParseCharacter(Arg.Any <IStringStream>()).Returns(_stringParserFailure);
            var parser = new CharacterParser(_primitiveParser);

            var result = parser.TryGetToken(_stream, out _);

            Assert.IsFalse(result.IsSuccess);
            _primitiveParser.Received(1).TryParseCharacterRange(Arg.Any <IStringStream>());
            _primitiveParser.Received(1).TryParseCharacter(Arg.Any <IStringStream>());
        }
Ejemplo n.º 2
0
        protected override IParseResult TryGetTokenWithoutNullCheck(IStringStream inputStream, out IToken token)
        {
            token = null;

            if (EnforceCharacterRangeSeparatorEscaping && IsCharacterRangeSeparator(inputStream))
            {
                return(new FailureParseResult(inputStream.CurrentPosition, RegSeedErrorType.InvalidRange));
            }

            var rangeResult = _primitiveParser.TryParseCharacterRange(inputStream);

            if (rangeResult.IsSuccess)
            {
                var rangeTokenLength = (int)(inputStream.CurrentPosition - _initialStreamPosition);
                token = new CharacterRangeToken(rangeResult.Value, inputStream.CurrentPosition, rangeTokenLength);
                return(new SuccessParseResult());
            }

            if (!rangeResult.IsSuccess && rangeResult.ErrorType != RegSeedErrorType.None)
            {
                return(rangeResult);
            }

            var characterResult = _primitiveParser.TryParseCharacter(inputStream);

            if (!characterResult.IsSuccess)
            {
                return(characterResult);
            }

            var characterTokenLength = (int)(inputStream.CurrentPosition - _initialStreamPosition);

            token = new CharacterToken(characterResult.Value, inputStream.CurrentPosition, characterTokenLength);
            return(new SuccessParseResult());
        }