Beispiel #1
0
        public TextSpan GetTextSpan(LineColumnTextSpan textSpan)
        {
            int start = GetLinearFromLineColumn(textSpan.BeginLine, textSpan.BeginColumn);
            int end   = GetLinearFromLineColumn(textSpan.EndLine, textSpan.EndColumn);

            var result = TextSpan.FromBounds(start, end, textSpan.CodeFile);

            return(result);
        }
Beispiel #2
0
        public static TextSpan ParseAnyTextSpan(string textSpanString, out bool isLineColumn, TextFile currentSourceFile, HashSet <IFile> sourceFiles)
        {
            TextSpan result;

            isLineColumn = textSpanString.Contains(",");
            if (!isLineColumn)
            {
                result = ParseTextSpan(textSpanString, currentSourceFile, sourceFiles);
            }
            else
            {
                LineColumnTextSpan lineColumnTextSpan = ParseLineColumnTextSpan(textSpanString, currentSourceFile, sourceFiles);
                result = lineColumnTextSpan.File.GetTextSpan(lineColumnTextSpan);
            }

            return(result);
        }
Beispiel #3
0
        public static LineColumnTextSpan ParseLineColumnTextSpan(string text, TextFile currentSourceFile = null, HashSet <IFile> sourceFiles = null)
        {
            ReadOnlySpan <char> textSpan = text.AsSpan();
            int semicolonIndex           = textSpan.IndexOf(';');

            ReadOnlySpan <char> location;
            ReadOnlySpan <char> fileName;

            if (semicolonIndex >= 0)
            {
                location = textSpan.Slice(0, semicolonIndex).Trim();
                fileName = textSpan.Slice(semicolonIndex + 1).Trim();
            }
            else
            {
                location = textSpan.Trim();
                fileName = ReadOnlySpan <char> .Empty;
            }

            TextFile sourceFile = (TextFile)GetSourceFile(fileName, currentSourceFile, sourceFiles);

            LineColumnTextSpan  result;
            ReadOnlySpan <char> firstPart = location.Slice(1, location.Length - 2);

            try
            {
                int beginLine, beginColumn, endLine, endColumn;

                var index = firstPart.IndexOf("..".AsSpan());
                if (index != -1)
                {
                    ReadOnlySpan <char> begin = firstPart.Slice(0, index);
                    ReadOnlySpan <char> end   = firstPart.Slice(index + 2);

                    if (end.IndexOf(',') == -1)
                    {
                        ParseLineColumn(begin, out beginLine, out beginColumn);
                        endLine = beginLine;
                        string endStr = end.ToString();
                        if (!int.TryParse(endStr, out endColumn)) // TODO: It will be replaced with Span when netstandard2.1 comes out
                        {
                            throw new FormatException($"Invalid or too big column value {endStr} while {nameof(LineColumnTextSpan)} parsing.");
                        }
                    }
                    else if (begin.IndexOf(',') == -1)
                    {
                        ParseLineColumn(end, out endLine, out endColumn);
                        beginColumn = endColumn;
                        string beginStr = begin.ToString();
                        if (!int.TryParse(beginStr, out beginLine)) // TODO: It will be replaced with Span when netstandard2.1 comes out
                        {
                            throw new FormatException($"Invalid or too big line value {beginStr} while {nameof(LineColumnTextSpan)} parsing.");
                        }
                    }
                    else
                    {
                        ParseLineColumn(begin, out beginLine, out beginColumn);
                        ParseLineColumn(end, out endLine, out endColumn);
                    }
                }
                else
                {
                    ParseLineColumn(firstPart, out beginLine, out beginColumn);
                    endLine   = beginLine;
                    endColumn = beginColumn;
                }

                result = new LineColumnTextSpan(beginLine, beginColumn, endLine, endColumn, sourceFile);
            }
            catch (Exception ex) when(!(ex is FormatException))
            {
                throw new FormatException($"{nameof(LineColumnTextSpan)} should be written in [start-line,start-column..end-line,end-column) format.");
            }

            return(result);
        }
Beispiel #4
0
        public static LineColumnTextSpan ParseLineColumnTextSpan(string text, CodeFile currentCodeFile = null, HashSet <CodeFile> codeFiles = null)
        {
            string[] parts = text.Split(semicolon, 2);

            string fileName = parts.Length == 2
                ? parts[1].Trim()
                : null;

            CodeFile codeFile = GetCodeFile(fileName, currentCodeFile, codeFiles);

            LineColumnTextSpan result;
            string             firstPart = parts[0].Trim().Substring(1, parts[0].Length - 2);

            try
            {
                int beginLine, beginColumn, endLine, endColumn;

                var index = firstPart.IndexOf("..");
                if (index != -1)
                {
                    string begin = firstPart.Remove(index);
                    string end   = firstPart.Substring(index + 2);
                    if (end.IndexOf(',') == -1)
                    {
                        ParseLineColumn(begin, out beginLine, out beginColumn);
                        endLine = beginLine;
                        if (!int.TryParse(end, out endColumn))
                        {
                            throw new FormatException($"Invalid or too big column value {end} while {nameof(LineColumnTextSpan)} parsing.");
                        }
                    }
                    else if (begin.IndexOf(',') == -1)
                    {
                        ParseLineColumn(end, out endLine, out endColumn);
                        beginColumn = endColumn;
                        if (!int.TryParse(begin, out beginLine))
                        {
                            throw new FormatException($"Invalid or too big line value {begin} while {nameof(LineColumnTextSpan)} parsing.");
                        }
                    }
                    else
                    {
                        ParseLineColumn(begin, out beginLine, out beginColumn);
                        ParseLineColumn(end, out endLine, out endColumn);
                    }
                }
                else
                {
                    ParseLineColumn(firstPart, out beginLine, out beginColumn);
                    endLine   = beginLine;
                    endColumn = beginColumn;
                }

                result = new LineColumnTextSpan(beginLine, beginColumn, endLine, endColumn, codeFile);
            }
            catch (Exception ex) when(!(ex is FormatException))
            {
                throw new FormatException($"{nameof(LineColumnTextSpan)} should be written in [start-line,start-column..end-line,end-column) format.");
            }

            return(result);
        }