Exemple #1
0
 bool HandleError(JsonErrorCode code, Location location)
 {
     return
         (errorHandler(code, location)
                         ? false
                         : throw new JsonParseException(code, location));
 }
Exemple #2
0
 void HandleError(JsonErrorCode code)
 {
     if (!this.errorHandler(code, tokenizer.Location))
     {
         throw new JsonParseException(code, tokenizer.Location);
     }
 }
 void HandleError(JsonErrorCode code, Location location)
 {
     if (!errorHandler(code, location))
     {
         throw new JsonParseException(code, location);
     }
 }
Exemple #4
0
 void HandleError(JsonErrorCode error, Location location)
 {
     if (!this.errorHandler(error, location))
     {
         throw new JsonParseException(error, location);
     }
 }
        public void UnchangedParametersInError(JsonErrorCode errorCode, JsonErrorLevel errorLevel, int start, int length, string[] parameters)
        {
            JsonErrorInfoParameter[] errorInfoParameters = parameters?.Select(x => new JsonErrorInfoParameter <string>(x))?.ToArrayEx();

            var errorInfo = new JsonErrorInfo(errorCode, errorLevel, start, length, errorInfoParameters);

            Assert.Equal(errorCode, errorInfo.ErrorCode);
            Assert.Equal(errorLevel, errorInfo.ErrorLevel);
            Assert.Equal(start, errorInfo.Start);
            Assert.Equal(length, errorInfo.Length);

            AssertErrorInfoParameters(errorInfo, errorInfoParameters);
        }
Exemple #6
0
        private GreenJsonMultiValueSyntax ParseMultiValue(JsonErrorCode multipleValuesErrorCode)
        {
            CurrentDepth++;
            if (CurrentDepth >= MaximumDepth)
            {
                throw new MaximumDepthExceededException();
            }

            var valueNodesBuilder = new List <GreenJsonValueWithBackgroundSyntax>();

            ParseValues(valueNodesBuilder, multipleValuesErrorCode);

            CurrentDepth--;
            return(CreateMultiValueNode(valueNodesBuilder));
        }
        /// <summary>
        /// Initializes a new instance of <see cref="JsonErrorInfo"/>.
        /// </summary>
        /// <param name="errorCode">
        /// The error code.
        /// </param>
        /// <param name="errorLevel">
        /// The severity level of the error.
        /// </param>
        /// <param name="start">
        /// The start position of the text span where the error occurred.
        /// </param>
        /// <param name="length">
        /// The length of the text span where the error occurred.
        /// </param>
        /// <param name="parameters">
        /// Parameters of the error.
        /// </param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Either <paramref name="start"/> or <paramref name="length"/>, or both are negative.
        /// </exception>
        public JsonErrorInfo(JsonErrorCode errorCode, JsonErrorLevel errorLevel, int start, int length, params JsonErrorInfoParameter[] parameters)
        {
            if (start < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(start));
            }
            if (length < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(length));
            }

            ErrorCode  = errorCode;
            ErrorLevel = errorLevel;
            Start      = start;
            Length     = length;
            Parameters = parameters != null
                ? ReadOnlyList <JsonErrorInfoParameter> .Create(parameters)
                : ReadOnlyList <JsonErrorInfoParameter> .Empty;
        }
Exemple #8
0
        private void ParseValues(List <GreenJsonValueWithBackgroundSyntax> valueNodesBuilder, JsonErrorCode multipleValuesErrorCode)
        {
            JsonSymbolType symbolType = ShiftToNextForegroundToken();

            if (symbolType >= ValueDelimiterThreshold)
            {
                return;
            }

            // Invariant: discriminated != null && !discriminated.IsOption1().
            for (; ;)
            {
                // Have to clear the BackgroundBuilder before entering a recursive call.
                var backgroundBefore = CaptureBackground();

                GreenJsonValueSyntax valueNode;
                if (symbolType == JsonSymbolType.CurlyOpen)
                {
                    (valueNode, symbolType) = ParseMap();
                }
                else if (symbolType == JsonSymbolType.BracketOpen)
                {
                    (valueNode, symbolType) = ParseList();
                }
                else
                {
                    // All other IGreenJsonSymbols derive from GreenJsonValueSyntax.
                    valueNode  = (GreenJsonValueSyntax)CurrentToken;
                    symbolType = ShiftToNextForegroundToken();
                }

                // Always add the value node, also if it contains an undefined value.
                valueNodesBuilder.Add(new GreenJsonValueWithBackgroundSyntax(backgroundBefore, valueNode));

                // If SymbolType >= JsonSymbolType.ValueDelimiterThreshold in the first iteration,
                // it means that exactly one value was parsed, as desired.
                if (symbolType >= ValueDelimiterThreshold)
                {
                    return;
                }

                // Two or more consecutive values not allowed.
                Report(new JsonErrorInfo(
                           multipleValuesErrorCode,
                           CurrentLength - CurrentToken.Length,
                           CurrentToken.Length));
            }
        }
 internal JsonParseException(JsonErrorCode error, Location location)
 {
     this.Error    = error;
     this.Location = location;
 }
Exemple #10
0
 bool HandleError(JsonErrorCode code)
 {
     return(HandleError(code, Location));
 }
 public bool JsonError(JsonErrorCode error, Location loc)
 {
     task.hasError = true;
     task.Log.LogError(null, "JP" + ((int)error).ToString(), null, file, loc.Line, loc.Column, loc.Line, loc.Column, error.ToString(), null);
     return(true);
 }
 public static LocalizedStringKey GetLocalizedStringKey(JsonErrorCode jsonErrorCode)
 => new LocalizedStringKey($"JsonError{jsonErrorCode}");
 void HandleError(JsonErrorCode code)
 {
     HandleError(code, Location);
 }
 /// <summary>
 /// Initializes a new instance of <see cref="JsonErrorInfo"/>.
 /// </summary>
 /// <param name="errorCode">
 /// The error code.
 /// </param>
 /// <param name="start">
 /// The start position of the text span where the error occurred.
 /// </param>
 /// <param name="length">
 /// The length of the text span where the error occurred.
 /// </param>
 /// <param name="parameters">
 /// Parameters of the error.
 /// </param>
 /// <exception cref="ArgumentOutOfRangeException">
 /// Either <paramref name="start"/> or <paramref name="length"/>, or both are negative.
 /// </exception>
 public JsonErrorInfo(JsonErrorCode errorCode, int start, int length, params JsonErrorInfoParameter[] parameters)
     : this(errorCode, JsonErrorLevel.Error, start, length, parameters)
 {
 }