comparison core/src/luan/LuanSource.java @ 190:04b86428dc50

minor git-svn-id: https://luan-java.googlecode.com/svn/trunk@191 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Thu, 26 Jun 2014 18:20:54 +0000
parents 3dcb0f9bee82
children b48cfa14ba60
comparison
equal deleted inserted replaced
189:fb3993431f76 190:04b86428dc50
26 26
27 public static final class Element extends LuanElement { 27 public static final class Element extends LuanElement {
28 public final LuanSource source; 28 public final LuanSource source;
29 public final int start; 29 public final int start;
30 public final int end; 30 public final int end;
31 private final String text;
31 32
32 public Element(LuanSource source,int start,int end) { 33 public Element(LuanSource source,int start,int end) {
34 this(source,start,end,null);
35 }
36
37 public Element(LuanSource source,int start,int end,String text) {
33 if( source==null ) 38 if( source==null )
34 throw new NullPointerException("source is null"); 39 throw new NullPointerException("source is null");
35 this.source = source; 40 this.source = source;
36 this.start = start; 41 this.start = start;
37 while( end > 0 && Character.isWhitespace(source.text.charAt(end-1)) ) { 42 while( end > 0 && Character.isWhitespace(source.text.charAt(end-1)) ) {
38 end--; 43 end--;
39 } 44 }
40 this.end = end; 45 this.end = end;
46 this.text = text;
41 } 47 }
42 48
43 public String text() { 49 public String text() {
44 return source.text.substring(start,end); 50 return text!=null ? text : source.text.substring(start,end);
45 } 51 }
46 52
47 @Override String location() { 53 @Override String location() {
48 return source.name + ':' + lineNumber(); 54 return source.name + ':' + lineNumber();
49 } 55 }