private void ParseBlockContent <T>( T result, IIniFieldParserProvider <T> fieldParserProvider) where T : class, new() { var done = false; while (!done) { if (_tokenReader.EndOfFile) { throw new InvalidOperationException(); } _tokenReader.GoToNextLine(); var token = _tokenReader.NextToken(Separators); if (token == null) { continue; } if (string.Equals(token.Value.Text, EndToken, StringComparison.InvariantCultureIgnoreCase)) { done = true; } else { var fieldName = token.Value.Text; if (fieldParserProvider.TryGetFieldParser(fieldName, out var fieldParser)) { _currentBlockOrFieldStack.Push(fieldName); fieldParser(this, result); _currentBlockOrFieldStack.Pop(); } else { throw new IniParseException($"Unexpected field '{fieldName}' in block '{_currentBlockOrFieldStack.Peek()}'.", token.Value.Position); } } } }
private void ParseBlockContent <T>( T result, IIniFieldParserProvider <T> fieldParserProvider) where T : class, new() { while (Current.TokenType == IniTokenType.Identifier || Current.TokenType == IniTokenType.IntegerLiteral) { if (Current.TokenType == IniTokenType.Identifier && Current.StringValue.ToUpper() == "END") { NextToken(); // ODDITY: ZH AmericaVehicle.ini:1993 has Upgrade_AmericaHellfireDrone after "End" NextTokenIf(IniTokenType.Identifier); break; } else { var fieldName = Current.TokenType == IniTokenType.Identifier ? Current.StringValue : Current.IntegerValue.ToString(); if (fieldParserProvider.TryGetFieldParser(fieldName, out var fieldParser)) { _currentBlockOrFieldStack.Push(fieldName); NextToken(); NextTokenIf(IniTokenType.Equals); // ODDITY: FactionBuilding.ini:13383 has a redundant = NextTokenIf(IniTokenType.Equals); fieldParser(this, result); NextToken(IniTokenType.EndOfLine); _currentBlockOrFieldStack.Pop(); } else { throw new IniParseException($"Unexpected field '{fieldName}' in block '{_currentBlockOrFieldStack.Peek()}'.", Current.Position); } } } }
public T ParseAttributeList <T>( IIniFieldParserProvider <T> fieldParserProvider) where T : class, new() { var result = new T(); var done = false; while (!done) { if (_tokenReader.EndOfFile) { throw new InvalidOperationException(); } var nameToken = GetNextTokenOptional(SeparatorsColon); if (!nameToken.HasValue) { break; } var fieldName = nameToken.Value.Text; if (fieldParserProvider.TryGetFieldParser(fieldName, out var fieldParser)) { _currentBlockOrFieldStack.Push(fieldName); fieldParser(this, result); _currentBlockOrFieldStack.Pop(); } else { throw new IniParseException($"Unexpected field '{fieldName}' in block '{_currentBlockOrFieldStack.Peek()}'.", nameToken.Value.Position); } } return(result); }