-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPackRat.java
53 lines (48 loc) · 1.13 KB
/
PackRat.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
52
53
package edu.lsu.cct.piraha;
import java.util.LinkedList;
/*
public static void main(String[] args) {
Grammar g = new Grammar();
g.compile("test","short");
Matcher m = g.matcher("test", "short short short");
m.startReplacement();
while(m.find()) {
m.appendReplacement("long");
}
String result = m.appendTail();
System.out.println(result);
System.out.println(m.mappings);
for(int i=0;i<m.text.length();i++) {
System.out.println(m.text.charAt(i)+" :> "+result.charAt(m.mapping(i)));
}
}
*/
public class PackRat {
final String name;
final int pos;
final int hc;
public boolean matched;
public int after;
public boolean filled;
public LinkedList<Group> subMatches;
PackRat(String name,int pos) {
this.name = name;
this.pos = pos;
this.hc = pos ^ name.hashCode();
}
@Override
public int hashCode() { return hc; }
@Override
public boolean equals(Object o) {
PackRat pr = (PackRat)o;
return pr.pos == pos && pr.name.equals(name);
}
public String toString() {
int n = -1;
String m = "";
if(subMatches != null) {
n = subMatches.size();
}
return "PackRat("+name+","+pos+","+matched+","+after+","+n+")";
}
}