Mercurial Hosting > luan
comparison src/luan/LuanSource.java @ 48:64ecb7a3aad7
rename Lua to Luan
git-svn-id: https://luan-java.googlecode.com/svn/trunk@49 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 28 Dec 2012 03:29:12 +0000 |
parents | src/luan/LuaSource.java@c53dc854e6cc |
children | 28dfd91a816c |
comparison
equal
deleted
inserted
replaced
47:659c7139e903 | 48:64ecb7a3aad7 |
---|---|
1 package luan; | |
2 | |
3 | |
4 public final class LuanSource { | |
5 public final String name; | |
6 public final String text; | |
7 | |
8 public LuanSource(String name,String text) { | |
9 this.name = name; | |
10 this.text = text; | |
11 } | |
12 | |
13 public static final class Element extends LuanElement { | |
14 public final LuanSource source; | |
15 public final int start; | |
16 public final int end; | |
17 | |
18 public Element(LuanSource source,int start,int end) { | |
19 if( source==null ) | |
20 throw new NullPointerException("source is null"); | |
21 this.source = source; | |
22 this.start = start; | |
23 this.end = end; | |
24 } | |
25 | |
26 public String text() { | |
27 return source.text.substring(start,end); | |
28 } | |
29 | |
30 @Override String location() { | |
31 return source.name + ':' + lineNumber(); | |
32 } | |
33 | |
34 private int lineNumber() { | |
35 int line = 0; | |
36 int i = -1; | |
37 do { | |
38 line++; | |
39 i = source.text.indexOf('\n',i+1); | |
40 } while( i != -1 && i < start ); | |
41 return line; | |
42 } | |
43 | |
44 } | |
45 } |