private void ParseKeyContent(HoconValue value, string currentPath) { while (!_reader.EoF) { Token t = _reader.PullNext(); switch (t.Kind) { case TokenKind.Dot: ParseObject(value, false, currentPath); return; case TokenKind.Assign: if (!value.IsObject()) { value.Clear(); } ParseValue(value, currentPath); return; case TokenKind.ObjectStart: ParseObject(value, true, currentPath); return; } } }
private static void ParseObject( HoconValue owner, string currentPath, IConfiguration conf) { if (!owner.IsObject()) { owner.NewValue(new HoconObject()); } HoconObject hoconObject = owner.GetObject(); foreach (var section in conf.GetChildren()) { if (int.TryParse(section.Key, out _)) { if (!owner.Values[0].IsArray()) { owner.Clear(); owner.NewValue(new HoconArray()); } var array = (HoconArray)owner.Values[0]; var value = new HoconValue(); ParseSection(currentPath, section, value); array.Add(value); } else { ParseSection(currentPath, section, hoconObject.GetOrCreateKey(section.Key)); } } }
private void ParseObject(HoconValue owner, bool root, string currentPath) { if (!owner.IsObject()) { owner.NewValue(new HoconObject()); } HoconObject currentObject = owner.GetObject(); while (!_reader.EoF) { Token t = _reader.PullNext(); switch (t.Kind) { case TokenKind.Include: if (_includeCallback == null) { throw new InvalidOperationException("include callback is null"); } var included = _includeCallback(t.Value); var substitutions = included.Substitutions; foreach (var substitution in substitutions) { substitution.Path = currentPath + "." + substitution.Path; } this.substitutions.AddRange(substitutions); var otherObj = included.Value.GetObject(); owner.GetObject().Merge(otherObj); break; case TokenKind.EoF: break; case TokenKind.Key: HoconValue value = currentObject.GetOrCreateKey(t.Value); var nextPath = currentPath == "" ? t.Value : currentPath + "." + t.Value; ParseKeyContent(value, nextPath); if (!root) { return; } break; case TokenKind.ObjectEnd: return; } } }
public void ParseValue(HoconValue owner, string currentPath) { if (_reader.EoF) { throw new Exception("End of file reached while trying to read a value"); } _reader.PullWhitespaceAndComments(); while (_reader.IsValue()) { Token t = _reader.PullValue(); switch (t.Kind) { case TokenKind.EoF: break; case TokenKind.LiteralValue: if (owner.IsObject()) { owner.Clear(); } var lit = new HoconLiteral(t.Value); owner.AppendValue(lit); break; case TokenKind.ObjectStart: ParseObject(owner, true, currentPath); break; case TokenKind.ArrayStart: HoconArray arr = ParseArray(currentPath); owner.AppendValue(arr); break; case TokenKind.Substitute: HoconSubstitution sub = ParseSubstitution(t.Value); substitutions.Add(sub); owner.AppendValue(sub); break; } if (_reader.IsSpaceOrTab()) { ParseTrailingWhitespace(owner); } } IgnoreComma(); }
private static void ParseValue( string value, HoconValue owner) { if (owner.IsObject()) { owner.Clear(); } HoconLiteral hoconLiteral = new HoconLiteral() { Value = value }; owner.AppendValue(hoconLiteral); }
private void VisitHoconValue(string path, HoconValue value) { if (value.IsEmpty) { return; } if (value.IsString()) { Data.Add(path, value.GetString()); } else if (value.IsObject()) { VisitHoconObject(path, value.GetObject()); } else if (value.IsArray()) { VisitHoconArray(path, value.GetArray()); } }
private void VisitHoconValue(string path, HoconValue value) { if (value.IsEmpty) { return; } if (value.IsObject()) { VisitHoconObject(path, value.GetObject()); } else if (value.IsArray()) { VisitHoconArray(path, value.GetArray()); } else if (value.IsString()) { Output.WriteLine($"{path} = {value.GetString()}"); } }