Exemplo n.º 1
0
 /// <inheritdoc cref="HoconRoot()"/>
 /// <param name="value">The value to associate with this element.</param>
 /// <param name="substitutions">An enumeration of substitutions to associate with this element.</param>
 public HoconRoot(HoconValue value, IEnumerable <HoconSubstitution> substitutions)
 {
     Value         = value;
     Substitutions = substitutions;
 }
Exemplo n.º 2
0
 /// <inheritdoc cref="HoconRoot()"/>
 /// <param name="value">The value to associate with this element.</param>
 public HoconRoot(HoconValue value) : this(value, Enumerable.Empty <HoconSubstitution>())
 {
 }
Exemplo n.º 3
0
        /// <inheritdoc cref="GetValue(string)"/>
        public HoconValue GetValue(HoconPath path)
        {
            HoconValue value = GetNode(path);

            return(value);
        }
Exemplo n.º 4
0
        static HoconObject()
        {
            var value = new HoconValue(null);

            _empty = new HoconObject(value);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HoconRoot"/> class.
 /// </summary>
 /// <param name="value">The value to associate with this element.</param>
 public HoconRoot(HoconValue value)
 {
     Value         = value;
     Substitutions = Enumerable.Empty <HoconSubstitution>();
 }
Exemplo n.º 6
0
 /// <inheritdoc cref="Config(HoconValue)" />
 protected Config(HoconValue value, Config fallback) : this(value)
 {
     MergeConfig(fallback);
 }
Exemplo n.º 7
0
 /// <inheritdoc />
 /// <summary>
 ///     Initializes a new instance of the <see cref="Config" /> class.
 /// </summary>
 protected Config(HoconValue value)
 {
     Value = (HoconValue)value.Clone(null);
 }
Exemplo n.º 8
0
 static Config()
 {
     EmptyValue = new HoconValue(null);
     EmptyValue.Add(new HoconObject(EmptyValue));
 }
Exemplo n.º 9
0
 protected bool Equals(HoconValue other)
 {
     return(Type == other.Type && GetString() == other.GetString());
 }
Exemplo n.º 10
0
        /// <summary>
        /// Retrieves the next value token from the tokenizer and appends it
        /// to the supplied element <paramref name="owner"/>.
        /// </summary>
        /// <param name="owner">The element to append the next token.</param>
        /// <exception cref="System.Exception">End of file reached while trying to read a value</exception>
        private HoconValue ParseValue(IHoconElement owner)
        {
            var value   = new HoconValue(owner);
            var parsing = true;

            while (parsing)
            {
                switch (_tokens.Current.Type)
                {
                case TokenType.Include:
                    value.Add(ParseInclude(value));
                    break;

                case TokenType.LiteralValue:
                    // Consume leading whitespaces.
                    if (_tokens.Current.IsNonSignificant())
                    {
                        ConsumeWhitespace();
                    }
                    if (_tokens.Current.Type != TokenType.LiteralValue)
                    {
                        break;
                    }

                    while (_tokens.Current.Type == TokenType.LiteralValue)
                    {
                        value.Add(HoconLiteral.Create(value, _tokens.Current));
                        _tokens.Next();
                    }
                    break;

                case TokenType.StartOfObject:
                    value.Add(ParseObject(value));
                    break;

                case TokenType.StartOfArray:
                    value.Add(ParseArray(value));
                    break;

                case TokenType.SubstituteOptional:
                case TokenType.SubstituteRequired:
                    var pointerPath       = HoconPath.Parse(_tokens.Current.Value);
                    HoconSubstitution sub = new HoconSubstitution(value, pointerPath, _tokens.Current,
                                                                  _tokens.Current.Type == TokenType.SubstituteRequired);
                    _substitutions.Add(sub);
                    value.Add(sub);
                    _tokens.Next();
                    break;

                case TokenType.EndOfObject:
                case TokenType.EndOfArray:
                    parsing = false;
                    break;

                // comments automatically stop value parsing.
                case TokenType.Comment:
                    ConsumeWhitelines();
                    parsing = false;
                    break;

                case TokenType.EndOfLine:
                    parsing = false;
                    break;

                case TokenType.EndOfFile:
                case TokenType.Comma:
                    parsing = false;
                    break;

                case TokenType.PlusEqualAssign:
                    HoconSubstitution subAssign = new HoconSubstitution(value, new HoconPath(Path), _tokens.Current, false);
                    _substitutions.Add(subAssign);
                    value.Add(subAssign);

                    value.Add(ParsePlusEqualAssignArray(value));
                    parsing = false;
                    break;

                case TokenType.Assign:
                    ConsumeWhitelines();
                    break;

                default:
                    throw HoconParserException.Create(_tokens.Current, Path,
                                                      $"Failed to parse Hocon value. Unexpected token: `{_tokens.Current.Type}`");
                }
            }

            // trim trailing whitespace if result is a literal
            if (value.Type == HoconType.Literal)
            {
                if (value[value.Count - 1] is HoconWhitespace)
                {
                    value.RemoveAt(value.Count - 1);
                }
            }
            return(value);
        }