using System.Text; using gppg; namespace NewLanguage { public class SourceLocation : IMerge { public int sLin; // start line public int sCol; // start column public int eLin; // end line public int eCol; // end column public string Text; public SourceLocation() { } public SourceLocation(int sl, int sc, int el, int ec, string line) { sLin = sl; sCol = sc; eLin = el; eCol = ec; Text = line; } public SourceLocation Merge(SourceLocation last) { return new SourceLocation(this.sLin, this.sCol, last.eLin, last.eCol, this.Text); } public override string ToString() { StringBuilder locstr = new StringBuilder(); if (sLin == eLin) { // all on one line, which will be the line // in Text locstr.Append("in \""); locstr.Append(Text.Substring(0, sCol)); locstr.Append(" HERE-->"); locstr.Append(Text.Substring(sCol, eCol - sCol)); if (Text.Length > eCol) { locstr.Append("<-- "); locstr.Append(Text.Substring(eCol, Text.Length)); } locstr.Append("\""); } else { // not all on one line, so we only have the end locstr.Append("before \""); locstr.Append(Text.Substring(0, eCol)); locstr.Append("<--HERE "); if (Text.Length > eCol) { locstr.Append(Text.Substring(eCol, Text.Length)); } locstr.Append("\""); } locstr.AppendFormat(" (at {0},{1} - {2},{3})", sLin, sCol, eLin, eCol); return locstr.ToString(); } } }