public OriginPosition GetOriginPosition()
        {
            OriginPosition res = pos;

            ++res.LineNumber;
            return(res);
        }
        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));
        }
Esempio n. 3
0
 internal string GetText(OriginPosition beg, OriginPosition end)
 {
     --beg.LineNumber;
     --end.LineNumber;
     if (beg.LineNumber == end.LineNumber)
     {
         if (beg.CharNumber == end.CharNumber)
         {
             return("");
         }
         return(sourceLines[beg.LineNumber].Substring(beg.CharNumber, end.CharNumber - beg.CharNumber));
     }
     else
     {
         StringBuilder sb = new StringBuilder();
         System.Console.WriteLine("!=");
         sb.Append(sourceLines[beg.LineNumber].Substring(beg.CharNumber));
         sb.Append('\n');
         for (int line = beg.LineNumber + 1; line < end.LineNumber; ++line)
         {
             sb.Append(sourceLines[line]);
             sb.Append('\n');
         }
         sb.Append(sourceLines[end.LineNumber].Substring(0, end.CharNumber));
         return(sb.ToString());
     }
 }
        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());
        }
 internal OriginLocation(IOrigin origin, OriginPosition pos)
 {
     this.origin = origin;
     this.pos    = pos;
 }
 public OriginFragment(IOrigin origin, OriginPosition beg, OriginPosition end)
 {
     this.origin = origin;
     this.beg    = beg;
     this.end    = end;
 }