예제 #1
0
        public string Parse(IParserInput input)
        {
            var sb = new StringBuilder();

            if (!input.TryReadChar(out var ch))
            {
                throw new ParserException("parser error in word.");
            }

            sb.Append(ch);
            var done = false;

            do
            {
                if (input.TryPeekChar(out ch) && _isValidWordCharFunc(ch))
                {
                    input.ReadLookahead();
                    sb.Append(ch);
                }
                else
                {
                    done = true;
                }
            } while (!done);

            return(sb.ToString());
        }
예제 #2
0
        public string Parse(IParserInput input)
        {
            _builder.Clear();

            if (!input.TryReadChar(out var quotation))
            {
                if (quotation != _quotation)
                {
                    throw new ArgumentException($"strings must start with the quotation char '{quotation}' 0x{quotation.ToHexString()}", nameof(input));
                }
            }
            var done = false;

            while (!done)
            {
                if (!input.TryReadChar(out var nextChar))
                {
                    throw new ParserException("end of input in string error");
                }

                if (nextChar == '\n')
                {
                    throw new ParserException("unclosed string error");
                }

                if (nextChar == _quotation)
                {
                    if (_allowDoubleQuotationEscaping && input.TryPeekChar(out var doubleQuoteEscapeCandidate) && doubleQuoteEscapeCandidate == _quotation)
                    {
                        input.ReadLookahead();
                        _builder.Append(nextChar);
                    }
                    else
                    {
                        done = true;
                    }
                }