Exemplo n.º 1
0
        private HoconRoot ParseText(string text, bool resolveSubstitutions, HoconIncludeCallbackAsync includeCallback)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                throw new HoconParserException(
                          $"Parameter {nameof(text)} is null or empty.\n" +
                          "If you want to create an empty Hocon HoconRoot, use \"{}\" instead.");
            }

            if (includeCallback != null)
            {
                _includeCallback = includeCallback;
            }

            try
            {
                _tokens = new HoconTokenizer(text).Tokenize();
                _root   = new HoconValue(null);
                ParseTokens();
                if (resolveSubstitutions)
                {
                    ResolveSubstitutions();
                }
            }
            catch (HoconTokenizerException e)
            {
                throw HoconParserException.Create(e, null, $"Error while tokenizing Hocon: {e.Message}", e);
            }
            catch (HoconException e)
            {
                throw HoconParserException.Create(_tokens.Current, Path, e.Message, e);
            }

            return(new HoconRoot(_root, _substitutions));
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Generates a configuration defined in the supplied
        ///     HOCON (Human-Optimized Config Object Notation) string.
        /// </summary>
        /// <param name="hocon">A string that contains configuration options to use.</param>
        /// <param name="includeCallback">callback used to resolve includes</param>
        /// <returns>The configuration defined in the supplied HOCON string.</returns>
        public static Config ParseString(string hocon, HoconIncludeCallbackAsync includeCallback)
        {
            HoconRoot res = HoconParser.Parse(hocon, includeCallback);

            return(new Config(res));
        }
Exemplo n.º 3
0
 /// <summary>
 ///     Parses the supplied HOCON configuration string into a root element.
 /// </summary>
 /// <param name="text">The string that contains a HOCON configuration string.</param>
 /// <param name="includeCallback">Callback used to resolve includes</param>
 /// <returns>The root element created from the supplied HOCON configuration string.</returns>
 /// <exception cref="HoconParserException">
 ///     This exception is thrown when an unresolved substitution is encountered.
 ///     It also occurs when any error is encountered while tokenizing or parsing the configuration string.
 /// </exception>
 public static HoconRoot Parse(string text, HoconIncludeCallbackAsync includeCallback = null)
 {
     return(new HoconParser().ParseText(text, true, includeCallback).Normalize());
 }
Exemplo n.º 4
0
 /// <summary>
 ///     Generates a configuration defined in the supplied
 ///     HOCON (Human-Optimized Config Object Notation) string.
 /// </summary>
 /// <param name="hocon">A string that contains configuration options to use.</param>
 /// <param name="includeCallback">callback used to resolve includes</param>
 /// <returns>The configuration defined in the supplied HOCON string.</returns>
 public static Config ParseString(string hocon, HoconIncludeCallbackAsync includeCallback)
 => new Config(HoconParser.Parse(hocon, includeCallback));