/// <summary>
        /// Parses a string representation of the script error location to produce an array of
        /// <see cref="ErrorLocationItem"/> instances
        /// </summary>
        /// <param name="errorLocation">String representation of the script error location</param>
        /// <returns>An array of <see cref="ErrorLocationItem"/> instances</returns>
        public static ErrorLocationItem[] ParseErrorLocation(string errorLocation)
        {
            if (string.IsNullOrWhiteSpace(errorLocation))
            {
                return(new ErrorLocationItem[0]);
            }

            var errorLocationItems = new List <ErrorLocationItem>();

            string[] lines     = errorLocation.SplitToLines();
            int      lineCount = lines.Length;

            for (int lineIndex = 0; lineIndex < lineCount; lineIndex++)
            {
                string line      = lines[lineIndex];
                Match  lineMatch = _errorLocationLineRegex.Match(line);

                if (lineMatch.Success)
                {
                    GroupCollection lineGroups = lineMatch.Groups;

                    var errorLocationItem = new ErrorLocationItem
                    {
                        FunctionName = lineGroups["functionName"].Value,
                        DocumentName = lineGroups["documentName"].Value,
                        LineNumber   = int.Parse(lineGroups["lineNumber"].Value),
                        ColumnNumber = lineGroups["columnNumber"].Success ?
                                       int.Parse(lineGroups["columnNumber"].Value) : 0,
                        SourceFragment = lineGroups["sourceFragment"].Value
                    };
                    errorLocationItems.Add(errorLocationItem);
                }
                else
                {
                    Debug.WriteLine(string.Format(Strings.Runtime_InvalidErrorLocationLineFormat, line));
                    return(new ErrorLocationItem[0]);
                }
            }

            return(errorLocationItems.ToArray());
        }
        /// <summary>
        /// Produces a string representation of the script error location from array of
        /// <see cref="ErrorLocationItem"/> instances
        /// </summary>
        /// <param name="errorLocationItems">An array of <see cref="ErrorLocationItem"/> instances</param>
        /// <param name="omitSourceFragment">Flag for whether to omit source fragment</param>
        /// <returns>String representation of the script error location</returns>
        public static string StringifyErrorLocationItems(ErrorLocationItem[] errorLocationItems,
                                                         bool omitSourceFragment = false)
        {
            if (errorLocationItems == null)
            {
                throw new ArgumentException(nameof(errorLocationItems));
            }

            int locationItemCount = errorLocationItems.Length;

            if (locationItemCount == 0)
            {
                return(string.Empty);
            }

            var           stringBuilderPool = StringBuilderPool.Shared;
            StringBuilder locationBuilder   = stringBuilderPool.Rent();

            for (int locationItemIndex = 0; locationItemIndex < locationItemCount; locationItemIndex++)
            {
                ErrorLocationItem locationItem = errorLocationItems[locationItemIndex];

                if (locationItemIndex > 0)
                {
                    locationBuilder.AppendLine();
                }
                WriteErrorLocationLine(locationBuilder, locationItem.FunctionName, locationItem.DocumentName,
                                       locationItem.LineNumber, locationItem.ColumnNumber,
                                       !omitSourceFragment ? locationItem.SourceFragment : string.Empty);
            }

            string errorLocation = locationBuilder.ToString();

            stringBuilderPool.Return(locationBuilder);

            return(errorLocation);
        }