37 lines
776 B
Plaintext
37 lines
776 B
Plaintext
package slangc.parser;
|
|
|
|
public final class SourceSnippet {
|
|
private SourcePosition start;
|
|
private int length;
|
|
private String cacheValue = null;
|
|
|
|
public SourceSnippet(SourcePosition start, int length) {
|
|
reset(start, length);
|
|
}
|
|
|
|
public void reset(SourcePosition start, int length) {
|
|
this.start = start;
|
|
this.length = length;
|
|
}
|
|
|
|
public SourcePosition getStart() {
|
|
return start;
|
|
}
|
|
|
|
public int getLength() {
|
|
return length;
|
|
}
|
|
|
|
public String getSource() {
|
|
if (cacheValue == null) {
|
|
cacheValue = start.getSource().getString(start.getIndex(), length);
|
|
}
|
|
return cacheValue;
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return "SourceSnippet(" + start.toString() + ", " + length + "): \"" + getSource() + "\"";
|
|
}
|
|
}
|