Пример #1
0
 public TextNode([NotNull] ISnapshot snapshot, [NotNull] string key, [NotNull] string value, TextSpan textSpan)
 {
     Snapshot = snapshot;
     Key = key;
     Value = value;
     TextSpan = textSpan;
 }
Пример #2
0
 public Diagnostic(int msg, [NotNull] string fileName, TextSpan span, Severity severity, [NotNull] string text)
 {
     Msg = msg;
     FileName = fileName;
     Span = span;
     Severity = severity;
     Text = text;
 }
 public Token([NotNull] string key, TextSpan keyTextSpan, [NotNull] string value, TextSpan valueTextSpan, int indent, bool isNested)
 {
     Key = key;
     KeyTextSpan = keyTextSpan;
     Value = value;
     ValueTextSpan = valueTextSpan;
     Indent = indent;
     IsNested = isNested;
 }
Пример #4
0
        public void TraceError(int msg, string text, string fileName, TextSpan span, string details = "")
        {
            Write(msg, text, Severity.Error, fileName, span, details);

            if (Configuration.GetBool(Constants.Configuration.Debug))
            {
                Debugger.Launch();
            }
        }
            public Token([NotNull] string key, TextSpan keyTextSpan, int indent, bool isNested)
            {
                Key = key;
                KeyTextSpan = keyTextSpan;
                Indent = indent;
                IsNested = isNested;

                Value = string.Empty;
                ValueTextSpan = TextSpan.Empty;
            }
            protected Token NextToken()
            {
                while (_lineNumber < _lines.Length && string.IsNullOrWhiteSpace(_lines[_lineNumber]))
                {
                    _lineNumber++;
                }

                if (_lineNumber >= _lines.Length)
                {
                    return null;
                }

                Token token;
                var line = _lines[_lineNumber];
                var indent = line.IndexOfNotWhitespace();
                var isNested = line[indent] == '-';

                var keyStartIndex = isNested ? line.IndexOfNotWhitespace(indent + 1) : indent;

                var n = line.IndexOf(':');
                if (n < 0)
                {
                    var key = line.Mid(keyStartIndex).Trim();
                    var keyTextSpan = new TextSpan(_lineNumber, keyStartIndex, key.Length);
                    token = new Token(key, keyTextSpan, indent, isNested);
                }
                else
                {
                    var key = line.Mid(keyStartIndex, n - keyStartIndex).Trim();
                    var keyTextSpan = new TextSpan(_lineNumber, keyStartIndex, key.Length);
                    var value = line.Mid(n + 1).Trim();
                    TextSpan valueTextSpan;

                    if (value == ">")
                    {
                        ParseValue(out value, out valueTextSpan, " ");
                    }
                    else if (value == "|")
                    {
                        ParseValue(out value, out valueTextSpan, "\r\n");
                    }
                    else
                    {
                        valueTextSpan = new TextSpan(_lineNumber, n + 1, line.Length - n);
                    }

                    token = new Token(key, keyTextSpan, value, valueTextSpan, indent, isNested);
                }

                _lineNumber++;

                return token;
            }
        protected override void Write(int msg, string text, Severity severity, string fileName, TextSpan span, string details)
        {
            if (IgnoredMessages.Contains(msg))
            {
                return;
            }

            if (!string.IsNullOrEmpty(details))
            {
                text += ": " + details;
            }

            var diagnostic = Factory.Diagnostic(msg, fileName, span, severity, text);

            Project.Diagnostics.Add(diagnostic);
        }
Пример #8
0
        public void ConstructorTest()
        {
            var position = new TextSpan(1, 2, 3);
            Assert.AreEqual(1, position.LineNumber);
            Assert.AreEqual(2, position.LinePosition);
            Assert.AreEqual(3, position.Length);
            Assert.AreEqual(472428, position.GetHashCode());
            Assert.IsFalse(position.Equals(null));

            var position2 = new TextSpan(1, 2, 3);
            Assert.AreEqual(position, position2);
            Assert.IsTrue(position == position2);
            Assert.IsTrue(position == position2);

            var position3 = new TextSpan(1, 2, 1);
            Assert.IsTrue(position != position3);
        }
        private Rendering FindRendering([NotNull] BuildContext context, [NotNull] string renderingName, [NotNull] string renderingId, TextSpan textSpan)
        {
            var renderings = context.Project.ProjectItems.OfType<Rendering>().Where(r => r.ItemName == renderingName).ToList();

            if (renderings.Count != 1)
            {
                if (!string.IsNullOrEmpty(renderingId))
                {
                    Guid guid;
                    if (Guid.TryParse(renderingId, out guid))
                    {
                        renderings = context.Project.ProjectItems.OfType<Rendering>().Where(r => r.Uri.Guid == guid).ToList();
                    }
                    else
                    {
                        renderings = context.Project.ProjectItems.OfType<Rendering>().Where(r => string.Equals(r.QualifiedName, renderingId, StringComparison.OrdinalIgnoreCase)).ToList();
                    }
                }
            }

            if (!renderings.Any())
            {
                context.CompileContext.Trace.TraceError(0, "Rendering not found", context.SourceFile.AbsoluteFileName, textSpan, renderingName);
                return null;
            }

            if (renderings.Count > 1)
            {
                context.CompileContext.Trace.TraceError(0, "Ambigeous rendering", context.SourceFile.AbsoluteFileName, textSpan, renderingName);
                return null;
            }

            return renderings.First();
        }
Пример #10
0
 public TextNode([NotNull] ISnapshot snapshot, [NotNull] string key, [NotNull] string value, TextSpan textSpan, [ItemNotNull, NotNull] IEnumerable <ITextNode> attributes, [ItemNotNull, NotNull] IEnumerable <ITextNode> childNodes)
 {
     Snapshot   = snapshot;
     Key        = key;
     Value      = value;
     TextSpan   = textSpan;
     Attributes = attributes;
     ChildNodes = childNodes;
 }
Пример #11
0
 public void TraceInformation(string text, string fileName, TextSpan span, string details = "")
 {
     TraceInformation(0, text, fileName, span, details);
 }
Пример #12
0
 public void TraceError(string text, string fileName, TextSpan span, string details = "")
 {
     TraceError(0, text, fileName, span, details);
 }
Пример #13
0
 public void TraceWarning(int msg, string text, string fileName, TextSpan span, string details = "")
 {
     Write(msg, text, Severity.Warning, fileName, span, details);
 }
Пример #14
0
 public virtual TextNode TextNode(ISnapshot snapshot, TextSpan span, string name, string value)
 {
     return new TextNode(snapshot, name, value, span);
 }
            private void ParseValue([NotNull] out string value, out TextSpan valueTextSpan, [NotNull] string delimiter)
            {
                _lineNumber++;
                if (_lineNumber >= _lines.Length)
                {
                    value = string.Empty;
                    valueTextSpan = new TextSpan(0, 0, 0);
                    return;
                }

                var startLineNumber = _lineNumber;
                var startIndent = _lines[_lineNumber].IndexOfNotWhitespace();
                var length = 0;
                var sb = new StringBuilder();

                do
                {
                    var line = _lines[_lineNumber];
                    length += line.Length + 2;

                    if (string.IsNullOrWhiteSpace(line))
                    {
                        _lineNumber++;
                        continue;
                    }

                    var indent = line.IndexOfNotWhitespace();
                    if (indent < startIndent)
                    {
                        _lineNumber--;
                        break;
                    }

                    sb.Append(line.Trim());
                    sb.Append(delimiter);

                    _lineNumber++;
                }
                while (_lineNumber < _lines.Length);

                value = sb.ToString().Trim();
                valueTextSpan = new TextSpan(startLineNumber, startLineNumber, length);
            }
Пример #16
0
 public void TraceInformation(int msg, string text, string fileName, TextSpan span, string details = "")
 {
     Write(msg, text, Severity.Information, fileName, span, details);
 }
Пример #17
0
 public virtual Diagnostic Diagnostic(int msg, string fileName, TextSpan span, Severity severity, string text)
 {
     return new Diagnostic(msg, fileName, span, severity, text);
 }
Пример #18
0
        protected virtual void Write(int msg, [NotNull] string text, Severity severity, [NotNull] string fileName, TextSpan textSpan, [NotNull] string details)
        {
            if (IgnoredMessages.Contains(msg))
            {
                return;
            }

            if (!string.IsNullOrEmpty(details))
            {
                text += ": " + details;
            }

            var fileInfo = !string.IsNullOrEmpty(fileName) ? fileName : "scc.cmd";

            var projectDirectory = Configuration.Get(Constants.Configuration.ProjectDirectory);
            if (!string.IsNullOrEmpty(projectDirectory))
            {
                if (fileInfo.StartsWith(projectDirectory, StringComparison.OrdinalIgnoreCase))
                {
                    fileInfo = fileInfo.Mid(projectDirectory.Length + 1);
                }
            }

            var lineInfo = textSpan.Length == 0 ? $"({textSpan.LineNumber},{textSpan.LinePosition})" : $"({textSpan.LineNumber},{textSpan.LinePosition},{textSpan.LineNumber},{textSpan.LinePosition + textSpan.Length})";

            Console.ForegroundColor = ConsoleColor.DarkGray;
            Console.Write($"{fileInfo}{lineInfo}: ");

            switch (severity)
            {
                case Severity.Warning:
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    break;
                case Severity.Error:
                    Console.ForegroundColor = ConsoleColor.Red;
                    break;
                default:
                    Console.ForegroundColor = ConsoleColor.DarkGray;
                    break;
            }

            Console.Write(severity.ToString().ToLowerInvariant());

            Console.ForegroundColor = ConsoleColor.DarkGray;
            Console.Write(" SCC{0}: ", msg.ToString("0000"));

            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine(text);
        }
Пример #19
0
 public YamlTextNode([NotNull] ISnapshot snapshot, TextSpan textSpan, [NotNull] string key, [NotNull] string value) : base(snapshot, key, value, textSpan)
 {
 }
Пример #20
0
 public void TraceError(int msg, string text, string fileName, TextSpan span, string details = "")
 {
     Write(msg, text, Severity.Error, fileName, span, details);
 }
Пример #21
0
 public bool Equals(TextSpan other)
 {
     return Length == other.Length && LineNumber == other.LineNumber && LinePosition == other.LinePosition;
 }
Пример #22
0
        public virtual XmlTextSnapshot With([NotNull] SnapshotParseContext parseContext, [NotNull] ISourceFile sourceFile, [NotNull] string contents, [NotNull] string schemaNamespace, [NotNull] string schemaFileName)
        {
            base.With(sourceFile);

            SchemaNamespace = schemaNamespace;
            SchemaFileName = schemaFileName;
            ParseContext = parseContext;

            try
            {
                var doc = XDocument.Parse(contents, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
                RootElement = doc.Root;
            }
            catch (XmlException ex)
            {
                ParseError = ex.Message;
                ParseErrorTextSpan = new TextSpan(ex.LineNumber, ex.LinePosition, 0);
                RootElement = null;
            }
            catch (Exception ex)
            {
                ParseError = ex.Message;
                RootElement = null;
            }

            return this;
        }
Пример #23
0
 public TextNode([NotNull] ISnapshot snapshot, [NotNull] string key, [NotNull] string value, TextSpan textSpan)
 {
     Snapshot   = snapshot;
     Key        = key;
     Value      = value;
     TextSpan   = textSpan;
     Attributes = Enumerable.Empty <ITextNode>();
     ChildNodes = Enumerable.Empty <ITextNode>();
 }