コード例 #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;
 }
コード例 #3
0
 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();
            }
        }
コード例 #5
0
            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;
            }
コード例 #6
0
            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;
            }
コード例 #7
0
        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);
        }
コード例 #9
0
        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);
 }
コード例 #15
0
            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>();
 }