Example #1
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();
        }
Example #2
0
        /// <summary>
        /// Configure the current configuration with a secondary source.
        /// </summary>
        /// <param name="fallback">The configuration to use as a secondary source.</param>
        /// <exception cref="ArgumentException">This exception is thrown if the given <paramref name="fallback"/> is a reference to this instance.</exception>
        /// <returns>The current configuration configured with the specified fallback.</returns>
        public virtual Config WithFallback(Config fallback)
        {
            if (fallback == this)
            {
                throw new ArgumentException("Config can not have itself as fallback", nameof(fallback));
            }
            if (fallback == null)
            {
                return(this);
            }
            if (IsEmpty)
            {
                return(fallback);
            }

            if (Contains(fallback))
            {
                return(this);
            }

            var mergedRoot = fallback.Root.GetObject().MergeImmutable(Root.GetObject());
            var newRoot    = new HoconValue();

            newRoot.AppendValue(mergedRoot);
            var mergedConfig = Copy(fallback);

            mergedConfig.Root = newRoot;
            return(mergedConfig);
        }
Example #3
0
        private void ParseTrailingWhitespace(HoconValue owner)
        {
            Token ws = _reader.PullSpaceOrTab();

            if (ws.Value.Length > 0)
            {
                var wsLit = new HoconLiteral(ws.Value);
                owner.AppendValue(wsLit);
            }
        }
        private static void ParseValue(
            string value,
            HoconValue owner)
        {
            if (owner.IsObject())
            {
                owner.Clear();
            }
            HoconLiteral hoconLiteral = new HoconLiteral()
            {
                Value = value
            };

            owner.AppendValue(hoconLiteral);
        }