OperationStatus ReadString(char closeStringChar, bool interpolated, char?escapeChar) { while (_reader.TryPeek(out char curr)) { Advance(); if (escapeChar.HasValue && curr == escapeChar.Value) { //We met an escape char if (closeStringChar == escapeChar.Value) { //we are on an odd escape char. strings like @"""" double the termination string to escape the double-quote. if (!_reader.TryPeek(out char secondEscape)) { return(NotEnoughData(TokenType.StringDeclaration)); } if (secondEscape != escapeChar.Value) { return(PreviousCharsAsToken(TokenType.StringDeclaration)); } } Advance(); } else if (curr == closeStringChar) { return(PreviousCharsAsToken(TokenType.StringDeclaration)); } if (interpolated && curr == '{') { CTokenizer nestedTokenizer = new CTokenizer(_reader.Sequence.Slice(_reader.Position, _reader.Length - _reader.Consumed)); //TODO: UnreadSequence in .NET 5 while (true) { OperationStatus status = nestedTokenizer.Read(); if (status == OperationStatus.NeedMoreData) { return(NotEnoughData(TokenType.Unknown)); } Token currToken = nestedTokenizer.CurrentToken; if (currToken.TokenType != TokenType.BlockClose) { continue; } if (currToken.Value.Length != 1) { continue; } if (currToken.Value.FirstSpan[0] != '}') { continue; } _reader.Advance(nestedTokenizer._reader.Consumed); break; } } } return(NotEnoughData(TokenType.StringDeclaration)); }
static void ParseSelf(string filePath, ReadOnlySequence <char> content) { var c = new CTokenizer(content); while (true) { var stats = c.Read(); if (stats == OperationStatus.NeedMoreData) { if (!c.End) { //Console.WriteLine( "Invalid EoS" ); } break; } if (c.CurrentToken.TokenType == TokenType.Unknown) //if( c.CurrentToken.TokenType != TokenType.Whitespace ) //if( c.CurrentToken.TokenType == TokenType.Number ) { Console.WriteLine(filePath + " " + c.CurrentToken.TokenType + " " + ToLiteral(new string( c.CurrentToken.Value.ToArray()))); } } }