コード例 #1
0
ファイル: Parser.cs プロジェクト: nagytech/HOCON
        private HoconField ParseField(HoconObject owner)
        {
            // sanity check
            if (_tokens.Current.Type != TokenType.LiteralValue)
            {
                throw HoconParserException.Create(_tokens.Current, Path,
                                                  $"Failed to parse Hocon field. Expected start of field {TokenType.LiteralValue}, " +
                                                  $"found {_tokens.Current.Type} instead.");
            }

            var pathDelta = ParseKey();

            if (_tokens.Current.IsNonSignificant())
            {
                ConsumeWhitelines();
            }

            // sanity check
            if (_tokens.Current.Type != TokenType.Assign &&
                _tokens.Current.Type != TokenType.StartOfObject &&
                _tokens.Current.Type != TokenType.PlusEqualAssign)
            {
                throw HoconParserException.Create(_tokens.Current, Path,
                                                  $"Failed to parse Hocon field. Expected {TokenType.Assign}, {TokenType.StartOfObject} " +
                                                  $"or {TokenType.PlusEqualAssign}, found {{_tokens.Current.Type}} instead.");
            }

            // sanity check
            if (pathDelta == null || pathDelta.Count == 0)
            {
                throw HoconParserException.Create(_tokens.Current, Path,
                                                  "Failed to parse Hocon field. ParseField() was called with null or empty path");
            }

            List <HoconField> childInPath = owner.TraversePath(pathDelta);

            Path.AddRange(pathDelta);
            HoconField currentField = childInPath[childInPath.Count - 1];

            var parsedValue = ParseValue(currentField);

            foreach (var removedSub in currentField.SetValue(parsedValue))
            {
                _substitutions.Remove(removedSub);
            }

            Path.RemoveRange(Path.Count - pathDelta.Count, pathDelta.Count);
            return(childInPath[0]);
        }
コード例 #2
0
ファイル: HoconParser.cs プロジェクト: nthanhcong0/HOCON
        private void ParseField(HoconObject owner)
        {
            // sanity check
            if (_tokens.Current.IsNonSignificant() || _tokens.Current.Type != TokenType.LiteralValue)
            {
                throw HoconParserException.Create(_tokens.Current, Path,
                                                  $"Failed to parse Hocon field. Expected start of field {TokenType.LiteralValue}, " +
                                                  $"found {_tokens.Current.Type} instead.");
            }

            var relativePath = ParseKey();

            if (_tokens.Current.Type == TokenType.EndOfLine)
            {
                _tokens.ToNextSignificantLine();
            }

            // sanity check
            if (_tokens.Current.Type != TokenType.Assign &&
                _tokens.Current.Type != TokenType.StartOfObject &&
                _tokens.Current.Type != TokenType.PlusEqualAssign)
            {
                throw HoconParserException.Create(_tokens.Current, Path,
                                                  $"Failed to parse Hocon field. Expected {TokenType.Assign}, {TokenType.StartOfObject} " +
                                                  $"or {TokenType.PlusEqualAssign}, found {_tokens.Current.Type} instead.");
            }

            // sanity check
            if (relativePath == null || relativePath.Count == 0)
            {
                throw HoconParserException.Create(_tokens.Current, Path,
                                                  "Failed to parse Hocon field. Null or empty path");
            }

            Path.AddRange(relativePath);

            var currentField = owner.TraversePath(relativePath);

            currentField.SetValue(ParseValue(currentField));

            Path.RemoveRange(Path.Count - relativePath.Count, relativePath.Count);
        }