コード例 #1
0
ファイル: Parser.cs プロジェクト: mbrezu/JsonMasher
            public Exception Error(string message)
            {
                var startPos         = AtEnd ? _tokens[_index - 1].EndPos : _tokens[_index].StartPos;
                var endPos           = AtEnd ? _tokens[_index - 1].EndPos : _tokens[_index].EndPos;
                var programWithLines = new ProgramWithLines(_program);

                return(new JsonMasherException(
                           message,
                           programWithLines.GetLineNumber(startPos) + 1,
                           programWithLines.GetColumnNumber(startPos) + 1,
                           PositionHighlighter.Highlight(programWithLines, startPos, endPos)));
            }
コード例 #2
0
ファイル: Lexer.cs プロジェクト: mbrezu/JsonMasher
 internal Exception Error(
     string message,
     int? positionNullable = null,
     int? lengthNullable = null,
     Exception ex = null)
 {
     var position = positionNullable == null ? _index : positionNullable.Value;
     var length = lengthNullable == null ? 1 : lengthNullable.Value;
     var programWithLines = new ProgramWithLines(_program);
     return new JsonMasherException(
         message, 
         programWithLines.GetLineNumber(position) + 1,
         programWithLines.GetColumnNumber(position) + 1,
         PositionHighlighter.Highlight(programWithLines, position, position + length),
         ex);
 }
コード例 #3
0
        public void ProgramHighlighterTests()
        {
            // Arrange

            // Act
            var result = PositionHighlighter.Highlight(@"line1
line2

line4
line5".CleanCR(), 2, 20);

            // Assert
            result.CleanCR().Should().Be(@"Line 1: line1
Line 1:   ^^^
Line 2: line2
Line 2: ^^^^^
Line 4: line4
Line 4: ^^^^^
Line 5: line5
Line 5: ^
".CleanCR());
        }