示例#1
0
        public void UnchangedStringLiteralValueParameter(string value, int length)
        {
            // Length includes quotes for json strings.
            var jsonString = new GreenJsonStringLiteralSyntax(value, length + 2);

            Assert.Equal(value, jsonString.Value);
            Assert.Equal(length + 2, jsonString.Length);
        }
        /// <summary>
        /// Gets the display string for a property key.
        /// </summary>
        /// <param name="keyNode">
        /// The key node that contains the property key for which the error is generated.
        /// </param>
        /// <param name="json">
        /// The source json on which the <paramref name="keyNode"/> is based.
        /// </param>
        /// <param name="keyNodeStart">
        /// The start position of the key node in the source json.
        /// </param>
        /// <returns>
        /// The display string.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="keyNode"/> and/or <paramref name="json"/> are null.
        /// </exception>
        public static string GetPropertyKeyDisplayString(GreenJsonStringLiteralSyntax keyNode, string json, int keyNodeStart)
        {
            if (keyNode == null)
            {
                throw new ArgumentNullException(nameof(keyNode));
            }
            if (json == null)
            {
                throw new ArgumentNullException(nameof(json));
            }

            // Do a Substring rather than keyNode.Value because the property key may contain escaped characters.
            return(json.Substring(keyNodeStart, keyNode.Length));
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of <see cref="ValueTypeErrorAtPropertyKey"/>.
        /// </summary>
        /// <param name="typeErrorBuilder">
        /// The context insensitive information for this error message.
        /// </param>
        /// <param name="keyNode">
        /// The property key for which the error is generated.
        /// </param>
        /// <param name="valueNode">
        /// The value node corresponding to the value that was typechecked.
        /// </param>
        /// <param name="json">
        /// The source json which contains the type error.
        /// </param>
        /// <param name="keyNodeStart">
        /// The start position of the key node in the source json.
        /// </param>
        /// <param name="valueNodeStart">
        /// The start position of the value node in the source json.
        /// </param>
        /// <returns>
        /// A <see cref="ValueTypeErrorAtPropertyKey"/> instance which generates a localized error message.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="typeErrorBuilder"/> and/or <paramref name="keyNode"/> and/or <paramref name="valueNode"/> and/or <paramref name="json"/> are null.
        /// </exception>
        public static ValueTypeErrorAtPropertyKey Create(
            ITypeErrorBuilder typeErrorBuilder,
            GreenJsonStringLiteralSyntax keyNode,
            GreenJsonValueSyntax valueNode,
            string json,
            int keyNodeStart,
            int valueNodeStart)
        {
            if (typeErrorBuilder == null)
            {
                throw new ArgumentNullException(nameof(typeErrorBuilder));
            }

            return(new ValueTypeErrorAtPropertyKey(
                       typeErrorBuilder,
                       PTypeErrorBuilder.GetPropertyKeyDisplayString(keyNode, json, keyNodeStart),
                       PTypeErrorBuilder.GetValueDisplayString(valueNode, json, valueNodeStart),
                       valueNodeStart,
                       valueNode.Length));
        }
示例#4
0
 /// <summary>
 /// Initializes a new instance of <see cref="UnrecognizedPropertyKeyTypeError"/>.
 /// </summary>
 /// <param name="keyNode">
 /// The property key for which the error is generated.
 /// </param>
 /// <param name="json">
 /// The source json which contains the type error.
 /// </param>
 /// <param name="keyNodeStart">
 /// The start position of the key node in the source json.
 /// </param>
 /// <returns>
 /// A <see cref="UnrecognizedPropertyKeyTypeError"/> instance which generates a localized error message.
 /// </returns>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="keyNode"/> and/or <paramref name="json"/> are null.
 /// </exception>
 public static UnrecognizedPropertyKeyTypeError Create(GreenJsonStringLiteralSyntax keyNode, string json, int keyNodeStart)
 => new UnrecognizedPropertyKeyTypeError(
     PTypeErrorBuilder.GetPropertyKeyDisplayString(keyNode, json, keyNodeStart),
     keyNodeStart,
     keyNode.Length);
示例#5
0
 public override Maybe <PString> VisitStringLiteralSyntax(GreenJsonStringLiteralSyntax value, _void arg) => new PString(value.Value);