/// <summary>
        /// Initializes a new instance of <see cref="GreenJsonListSyntax"/>.
        /// </summary>
        /// <param name="listItemNodes">
        /// The non-empty enumeration of list item nodes.
        /// </param>
        /// <param name="missingSquareBracketClose">
        /// False if the list is terminated by a closing square bracket, otherwise true.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="listItemNodes"/> is null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="listItemNodes"/> is an empty enumeration.
        /// </exception>
        public GreenJsonListSyntax(IEnumerable <GreenJsonMultiValueSyntax> listItemNodes, bool missingSquareBracketClose)
        {
            ListItemNodes = ReadOnlySeparatedSpanList <GreenJsonMultiValueSyntax, GreenJsonCommaSyntax> .Create(listItemNodes, GreenJsonCommaSyntax.Value);

            if (ListItemNodes.Count == 0)
            {
                throw new ArgumentException($"{nameof(listItemNodes)} cannot be empty", nameof(listItemNodes));
            }

            MissingSquareBracketClose = missingSquareBracketClose;

            Length = JsonSpecialCharacter.SpecialCharacterLength
                     + ListItemNodes.Length
                     + (missingSquareBracketClose ? 0 : JsonSpecialCharacter.SpecialCharacterLength);
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of <see cref="GreenJsonMapSyntax"/>.
        /// </summary>
        /// <param name="keyValueNodes">
        /// The non-empty enumeration of key-value nodes.
        /// </param>
        /// <param name="missingCurlyClose">
        /// False if the list is terminated by a closing curly brace, otherwise true.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="keyValueNodes"/> is null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="keyValueNodes"/> is an empty enumeration.
        /// </exception>
        public GreenJsonMapSyntax(IEnumerable <GreenJsonKeyValueSyntax> keyValueNodes, bool missingCurlyClose)
        {
            KeyValueNodes = ReadOnlySeparatedSpanList <GreenJsonKeyValueSyntax, GreenJsonCommaSyntax> .Create(keyValueNodes, GreenJsonCommaSyntax.Value);

            if (KeyValueNodes.Count == 0)
            {
                throw new ArgumentException($"{nameof(keyValueNodes)} cannot be empty", nameof(keyValueNodes));
            }

            MissingCurlyClose = missingCurlyClose;

            Length = JsonSpecialCharacter.SpecialCharacterLength
                     + KeyValueNodes.Length
                     + (missingCurlyClose ? 0 : JsonSpecialCharacter.SpecialCharacterLength);
        }
        /// <summary>
        /// Initializes a new instance of <see cref="GreenJsonKeyValueSyntax"/>.
        /// </summary>
        /// <param name="validKey">
        /// Nothing if no valid key was found, just the valid key otherwise.
        /// The string literal is expected to be the same as the first value node's content node in <paramref name="valueSectionNodes"/>.
        /// </param>
        /// <param name="valueSectionNodes">
        /// The enumeration of syntax nodes containing the key and values.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="validKey"/> and/or <paramref name="valueSectionNodes"/> are null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="validKey"/> is not the expected syntax node -or- <paramref name="valueSectionNodes"/> is an empty enumeration.
        /// </exception>
        public GreenJsonKeyValueSyntax(Maybe <GreenJsonStringLiteralSyntax> validKey, IEnumerable <GreenJsonMultiValueSyntax> valueSectionNodes)
        {
            ValidKey          = validKey ?? throw new ArgumentNullException(nameof(validKey));
            ValueSectionNodes = ReadOnlySeparatedSpanList <GreenJsonMultiValueSyntax, GreenJsonColonSyntax> .Create(valueSectionNodes, GreenJsonColonSyntax.Value);

            if (ValueSectionNodes.Count == 0)
            {
                throw new ArgumentException($"{nameof(valueSectionNodes)} cannot be empty", nameof(valueSectionNodes));
            }

            // If a valid key node is given, the node must always be equal to keyNode.ValueNode.Node.
            if (validKey.IsJust(out GreenJsonStringLiteralSyntax validKeyNode) &&
                validKeyNode != ValueSectionNodes[0].ValueNode.ContentNode)
            {
                throw new ArgumentException("validKey and ValueSectionNodes[0].ValueNode.ContentNode should be the same", nameof(validKey));
            }
        }