PullWhitespaceAndComments() public méthode

Advances the tokenizer to the next non-whitespace, non-comment token.
public PullWhitespaceAndComments ( ) : void
Résultat void
Exemple #1
0
        public void ParseValue(HoconValue owner)
        {
            if (reader.EoF)
            {
                throw new Exception("End of file reached while trying to read a value");
            }

            bool isObject = owner.IsObject();

            reader.PullWhitespaceAndComments();
            while (reader.IsValue())
            {
                Token t = reader.PullValue();

                switch (t.Type)
                {
                case TokenType.EoF:
                    break;

                case TokenType.LiteralValue:
                    if (isObject)
                    {
                        //needed to allow for override objects
                        isObject = false;
                        owner.Clear();
                    }
                    var lit = new HoconLiteral
                    {
                        Value = t.Value
                    };
                    owner.AppendValue(lit);

                    break;

                case TokenType.ObjectStart:
                    ParseObject(owner, true);
                    break;

                case TokenType.ArrayStart:
                    HoconArray arr = ParseArray();
                    owner.AppendValue(arr);
                    break;

                case TokenType.Substitute:
                    HoconSubstitution sub = ParseSubstitution(t.Value);
                    substitutions.Add(sub);
                    owner.AppendValue(sub);
                    break;
                }
                if (reader.IsSpaceOrTab())
                {
                    ParseTrailingWhitespace(owner);
                }
            }

            IgnoreComma();
        }
Exemple #2
0
        /// <summary>
        /// Parses the text.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <returns>HoconValue.</returns>
        /// <exception cref="System.Exception">Unresolved substitution: + sub.Path</exception>
        private HoconRoot ParseText(string text)
        {
            root = new HoconValue();
            reader = new HoconTokenizer(text);
            reader.PullWhitespaceAndComments();
            ParseObject(root, true);

            var c = new Config(new HoconRoot(root,Enumerable.Empty<HoconSubstitution>()));
            foreach (HoconSubstitution sub in substitutions)
            {
                HoconValue res = c.GetValue(sub.Path);
                if (res == null)
                    throw new Exception("Unresolved substitution:" + sub.Path);
                sub.ResolvedValue = res;
            }
            return new HoconRoot(root, substitutions);
        }
Exemple #3
0
        private HoconRoot ParseText(string text,Func<string,HoconRoot> includeCallback)
        {
            _includeCallback = includeCallback;
            _root = new HoconValue();
            _reader = new HoconTokenizer(text);
            _reader.PullWhitespaceAndComments();
            ParseObject(_root, true,"");

            var c = new Config(new HoconRoot(_root, Enumerable.Empty<HoconSubstitution>()));
            foreach (HoconSubstitution sub in _substitutions)
            {
                HoconValue res = c.GetValue(sub.Path);
                if (res == null)
                    throw new FormatException("Unresolved substitution:" + sub.Path);
                sub.ResolvedValue = res;
            }
            return new HoconRoot(_root, _substitutions);
        }
Exemple #4
0
        private HoconValue ParseText(string text)
        {
            root   = new HoconValue();
            reader = new HoconTokenizer(text);
            reader.PullWhitespaceAndComments();
            ParseObject(root, true);

            var c = new Config(root);

            foreach (HoconSubstitution sub in substitutions)
            {
                HoconValue res = c.GetValue(sub.Path);
                if (res == null)
                {
                    throw new Exception("Unresolved substitution:" + sub.Path);
                }
                sub.ResolvedValue = res;
            }
            return(root);
        }
Exemple #5
0
        /// <summary>
        ///     Parses the text.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <returns>HoconValue.</returns>
        /// <exception cref="System.Exception">Unresolved substitution: + sub.Path</exception>
        private HoconRoot ParseText(string text)
        {
            _root   = new HoconValue();
            _reader = new HoconTokenizer(text);
            _reader.PullWhitespaceAndComments();
            ParseObject(_root, true);

            var c = new Config(new HoconRoot(_root, Enumerable.Empty <HoconSubstitution>()));

            foreach (HoconSubstitution sub in _substitutions)
            {
                HoconValue res = c.GetValue(sub.Path);
                if (res == null)
                {
                    throw new Exception("Unresolved substitution:" + sub.Path);
                }
                sub.ResolvedValue = res;
            }
            return(new HoconRoot(_root, _substitutions));
        }
Exemple #6
0
        private HoconRoot ParseText(string text, Func <string, HoconRoot> includeCallback)
        {
            _includeCallback = includeCallback;
            _root            = new HoconValue();
            _reader          = new HoconTokenizer(text);
            _reader.PullWhitespaceAndComments();
            ParseObject(_root, true, "");

            var c = new Config(new HoconRoot(_root, Enumerable.Empty <HoconSubstitution>()));

            foreach (HoconSubstitution sub in _substitutions)
            {
                HoconValue res = c.GetValue(sub.Path);
                if (res == null)
                {
                    throw new FormatException($"Unresolved substitution: {sub.Path}");
                }
                sub.ResolvedValue = res;
            }
            return(new HoconRoot(_root, _substitutions));
        }
Exemple #7
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>
        public void ParseValue(HoconValue owner, string currentPath)
        {
            if (_reader.EoF)
            {
                throw new HoconParserException("End of file reached while trying to read a value");
            }

            _reader.PullWhitespaceAndComments();
            var start = _reader.Index;

            try
            {
                while (_reader.IsValue())
                {
                    Token t = _reader.PullValue();

                    switch (t.Type)
                    {
                    case TokenType.EoF:
                        break;

                    case TokenType.LiteralValue:
                        if (owner.IsObject())
                        {
                            //needed to allow for override objects
                            owner.Clear();
                        }
                        var lit = new HoconLiteral
                        {
                            Value = t.Value
                        };
                        owner.AppendValue(lit);

                        break;

                    case TokenType.ObjectStart:
                        ParseObject(owner, true, currentPath);
                        break;

                    case TokenType.ArrayStart:
                        HoconArray arr = ParseArray(currentPath);
                        owner.AppendValue(arr);
                        break;

                    case TokenType.Substitute:
                        HoconSubstitution sub = ParseSubstitution(t.Value);
                        _substitutions.Add(sub);
                        owner.AppendValue(sub);
                        break;
                    }
                    if (_reader.IsSpaceOrTab())
                    {
                        ParseTrailingWhitespace(owner);
                    }
                }

                IgnoreComma();
            }
            catch (HoconTokenizerException tokenizerException)
            {
                throw new HoconParserException(string.Format("{0}\r{1}", tokenizerException.Message, GetDiagnosticsStackTrace()), tokenizerException);
            }
            finally
            {
                //no value was found, tokenizer is still at the same position
                if (_reader.Index == start)
                {
                    throw new HoconParserException(string.Format("Hocon syntax error {0}\r{1}", _reader.GetHelpTextAtIndex(start), GetDiagnosticsStackTrace()));
                }
            }
        }