예제 #1
0
 public static HoconImmutableLiteral ToHoconImmutable(this HoconLiteral literal)
 {
     return(literal.LiteralType == HoconLiteralType.Null
         ? null
         : new HoconImmutableLiteralBuilder()
            .Append(literal)
            .Build());
 }
예제 #2
0
        private void ParseTrailingWhitespace(HoconValue owner)
        {
            Token ws = _reader.PullSpaceOrTab();

            if (ws.Value.Length > 0)
            {
                var wsLit = new HoconLiteral(ws.Value);
                owner.AppendValue(wsLit);
            }
        }
        public static JValue ToJValue(this HoconLiteral hoconLiteral, Func <JValue, JValue>?jValueHandler = null)
        {
            if (hoconLiteral == null)
            {
                throw new ArgumentNullException(nameof(hoconLiteral));
            }

            var hoconValue = new HoconValue(null)
            {
                hoconLiteral,
            };

            JValue jValue;

            switch (hoconLiteral.LiteralType)
            {
            case HoconLiteralType.Null:
                jValue = JValue.CreateNull();
                break;

            case HoconLiteralType.Whitespace:
            case HoconLiteralType.UnquotedString:
            case HoconLiteralType.QuotedString:
            case HoconLiteralType.TripleQuotedString:
                jValue = JValue.CreateString(hoconValue.GetString());
                break;

            case HoconLiteralType.Bool:
                jValue = new JValue(hoconValue.GetBoolean());
                break;

            case HoconLiteralType.Long:
            case HoconLiteralType.Hex:
            case HoconLiteralType.Octal:
                jValue = new JValue(hoconValue.GetLong());
                break;

            case HoconLiteralType.Double:
                jValue = new JValue(hoconValue.GetDouble());
                break;

            default:
                throw new InvalidOperationException($"Unknown LiteralType: {hoconLiteral.LiteralType}");
            }

            if (jValueHandler != null)
            {
                return(jValueHandler(jValue));
            }
            else
            {
                return(jValue);
            }
        }
예제 #4
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();
        }
        private static void ParseValue(
            string value,
            HoconValue owner)
        {
            if (owner.IsObject())
            {
                owner.Clear();
            }
            HoconLiteral hoconLiteral = new HoconLiteral()
            {
                Value = value
            };

            owner.AppendValue(hoconLiteral);
        }