-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCloseWhite.java
51 lines (44 loc) · 940 Bytes
/
CloseWhite.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package edu.lsu.cct.piraha;
//import edu.lsu.cct.util.Here;
public class CloseWhite extends Pattern {
@Override
public boolean match(Matcher m) {
int pos = m.getTextPos();
if(pos==0 || m.text.charAt(pos-1)=='\n') {
int thresh = 0;
int nt = m.whiteThresholds.size();
if(nt > 0) {
thresh = m.whiteThresholds.get(nt-1);
}
int newPos = pos;
for(;newPos<m.text.length();newPos++) {
char c = m.text.charAt(newPos);
if(c == ' '||c == '\t') {
;
} else {
break;
}
}
if(newPos-pos <= thresh) {
int n = m.whiteThresholds.remove(nt-1);
if(nt == 1)
m.white.setLength(0);
else
m.white.setLength(m.whiteThresholds.get(nt-2));
return true;
} else {
return false;
}
} else {
return false;
}
}
@Override
public String decompile() {
return "{CloseWhite}";
}
@Override
public boolean eq(Object obj) {
return obj instanceof CloseWhite;
}
}