public string PrepareMessage(string errorType, IFragment sourceFragment, string errorDescription)
        {
            OriginPosition pos = sourceFragment.GetBeginOriginPosition();

            return(String.Format(messageFormat, errorType, pos.LineNumber, pos.CharNumber,
                                 sourceFragment.GetOriginText(), errorDescription));
        }
示例#2
0
        public void FewLinesFragmentPositionsTest()
        {
            string source = "1\n22\n\n4";

            iOrigin = CreateOriginTest(source);
            iReader = iOrigin.GetReader();

            iReader.MoveNext();
            ILocation loc1 = iReader.CurrentLocation;

            iReader.MoveNext();
            iReader.MoveNext();
            ILocation loc2 = iReader.CurrentLocation;

            iReader.MoveNext();

            IFragment fr = iOrigin.MakeFragment(loc1, loc2);

            Assert.AreEqual(fr.GetBeginOriginPosition(), loc1.GetOriginPosition());
            Assert.AreEqual(fr.GetEndOriginPosition(), loc2.GetOriginPosition());

            iReader.MoveNext();
            iReader.MoveNext();
            ILocation loc3 = iReader.CurrentLocation;

            IFragment fr2 = iOrigin.MakeFragment(loc2, loc3);

            Assert.AreEqual(fr2.GetBeginOriginPosition(), loc2.GetOriginPosition());
            Assert.AreEqual(fr2.GetEndOriginPosition(), loc3.GetOriginPosition());
        }
        public void PrintFragmentInLine(IFragment fragment)
        {
            IOrigin origin = fragment.Origin;

            System.Console.WriteLine(origin.GetLine(fragment.GetBeginOriginPosition().LineNumber));
            System.Console.WriteLine(GetFragmentInLine(fragment));
        }
示例#4
0
 private static IFragment GetFragmentRange(IFragment begin, IFragment end)
 {
     if (begin == null || end == null)              // TODO handle it better
     {
         return(new OriginFragment(null, new OriginPosition(), new OriginPosition()));
     }
     return(new OriginFragment(begin.Origin, begin.GetBeginOriginPosition(), end.GetEndOriginPosition()));
 }
示例#5
0
 public string GetText(IFragment fragment)
 {
     if (fragment.Origin == this)
     {
         return(this.GetText(fragment.GetBeginOriginPosition(), fragment.GetEndOriginPosition()));
     }
     else
     {
         throw new ArgumentException("Invalid origin");
     }
 }
        public string GetFragmentInLine(IFragment fragment)
        {
            IOrigin        origin = fragment.Origin;
            OriginPosition begPos = fragment.GetBeginOriginPosition();
            OriginPosition endPos = fragment.GetEndOriginPosition();
            int            start  = begPos.CharNumber;
            int            end    = endPos.CharNumber;
            StringBuilder  sb     = new StringBuilder();

            for (int i = 0; i < start; i++)
            {
                sb.Append(' ');
            }
            for (int i = start; i < end; i++)
            {
                sb.Append((i + 1 == end) ? '^' : '~');
            }
            return(sb.ToString());
        }
示例#7
0
 private static IFragment GetFragmentRange(IFragment begin, IFragment end)
 {
     return(new OriginFragment(begin.Origin, begin.GetBeginOriginPosition(), end.GetEndOriginPosition()));
 }