-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathILiteral.java
41 lines (38 loc) · 868 Bytes
/
ILiteral.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
package edu.lsu.cct.piraha;
import java.util.ArrayList;
import java.util.List;
public class ILiteral extends Pattern {
char lch,uch;
public ILiteral(int val) {
char ch = (char)val;
this.lch = Character.toLowerCase(ch);
this.uch = Character.toUpperCase(ch);
}
@Override
public boolean match(Matcher m) {
if(m.getTextPos() < m.text.length()) {
char ch = m.text.charAt(m.getTextPos());
if(lch == ch || uch == ch) {
m.incrTextPos(1);
return true;
}
}
m.expected(new Expected(this));
return false;
}
@Override
public String decompile() {
return Literal.outc(lch);
}
@Override
public boolean eq(Object obj) {
ILiteral ilit = (ILiteral)obj;
return ilit.lch == lch && ilit.uch == uch;
}
@Override
public List<String> expected(int n) {
List<String> ex = new ArrayList<String>();
ex.add(decompile());
return ex;
}
}