-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSeq.java
93 lines (84 loc) · 1.97 KB
/
Seq.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package edu.lsu.cct.piraha;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class Seq extends Pattern {
List<Pattern> patternList;
boolean ignCase, igcShow;
public Seq(List<Pattern> pattern,boolean ignCase,boolean igcShow) {
this.patternList = pattern;
this.ignCase = ignCase;
this.igcShow = igcShow;
}
public Seq(Pattern...patterns) {
this(false,false,patterns);
}
public Seq(boolean ignCase,boolean igcShow,Pattern...patterns) {
patternList = new ArrayList<Pattern>(patterns.length);
for(Pattern p : patterns)
patternList.add(p);
}
@Override
public boolean match(Matcher m) {
//for(Pattern x = pattern;x != null;x = x.next) {
for(int i=0;i<patternList.size();i++) {
Pattern x = patternList.get(i);
boolean b = x.match(m);
if(!b) {
m.expected(new Expected(this,i));
return false;
}
}
return true;
}
@Override
public void visit(Visitor v) {
Visitor vv = v.startVisit(this);
for(Pattern x : patternList) {
x.visit(vv);
}
v.finishVisit(this);
}
@Override
public String decompile() {
StringBuffer sb = new StringBuffer();
if(igcShow) {
sb.append("(");
if(ignCase)
sb.append("?i:");
else
sb.append("?-i:");
}
for(Pattern x : patternList)
sb.append(x.decompile());
if(igcShow)
sb.append(")");
return sb.toString();
}
@Override
public boolean eq(Object obj) {
Seq or = (Seq)obj;
if(or.patternList.size() != patternList.size())
return false;
for(int i=0;i<patternList.size();i++) {
if(!or.patternList.get(i).equals(patternList.get(i)))
return false;
}
return true;
}
@Override
public List<String> expected(int n) {
List<String> ex = new ArrayList<String>();
for(int i=n;i<patternList.size();i++) {
List<String> nex = new ArrayList<String>();
List<String> li = patternList.get(i).expected(0);
for(int j=0;j<li.size();j++) {
for(int k=0;k<ex.size();k++) {
nex.add(ex.get(k)+li.get(j));
}
}
ex = nex;
}
return ex;
}
}