예제 #1
0
        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));
                }
            }
        }
예제 #3
0
        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);
        }