projects
/
sbp.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
99a413e
)
checkpoint
author
adam
<adam@megacz.com>
Wed, 14 Dec 2005 02:33:59 +0000
(21:33 -0500)
committer
adam
<adam@megacz.com>
Wed, 14 Dec 2005 02:33:59 +0000
(21:33 -0500)
darcs-hash:
20051214023359
-5007d-
4e0ae12e81f64a0b9abb7dd423b62823cf48ec22
.gz
src/edu/berkeley/sbp/misc/MetaGrammar.java
patch
|
blob
|
history
diff --git
a/src/edu/berkeley/sbp/misc/MetaGrammar.java
b/src/edu/berkeley/sbp/misc/MetaGrammar.java
index
f532009
..
c513655
100644
(file)
--- a/
src/edu/berkeley/sbp/misc/MetaGrammar.java
+++ b/
src/edu/berkeley/sbp/misc/MetaGrammar.java
@@
-201,7
+201,7
@@
public class MetaGrammar extends ReflectiveWalker {
HashSet<Sequence> temp = new HashSet<Sequence>();
for(PreSequence pre : s[i]) {
pre.hatess.addAll(seqs);
HashSet<Sequence> temp = new HashSet<Sequence>();
for(PreSequence pre : s[i]) {
pre.hatess.addAll(seqs);
- Sequence seq = pre.buildSequence(null, n, false, dropAll);
+ Sequence seq = pre.buildSequence(n, false, dropAll);
temp.add(seq);
//for(Sequence dom : seqs) seq.hates.add(dom);
n.add(seq);
temp.add(seq);
//for(Sequence dom : seqs) seq.hates.add(dom);
n.add(seq);
@@
-238,15
+238,8
@@
public class MetaGrammar extends ReflectiveWalker {
private final boolean maximal;
private final boolean zero;
public Rep(Element e, Element s, boolean maximal, boolean zero) { this.e = e; this.s = s; this.zero = zero; this.maximal = maximal;}
private final boolean maximal;
private final boolean zero;
public Rep(Element e, Element s, boolean maximal, boolean zero) { this.e = e; this.s = s; this.zero = zero; this.maximal = maximal;}
- public Element build(Element ws) {
- Element sep = null;
- if (ws==null) sep = s;
- else if (s==null) sep = ws;
- else {
- Union ws2 = new Union(e + "/" + s + "/" + ws, true);
- ws2.add(Sequence.singleton(new Element[] { ws, s, ws }, 0, null, null));
- sep = ws2;
- }
+ public Element build() {
+ Element sep = s;
Element ret = zero ? Repeat.many0(e, sep) : Repeat.many1(e, sep);
return maximal ? Repeat.maximal(ret) : ret;
}
Element ret = zero ? Repeat.many0(e, sep) : Repeat.many1(e, sep);
return maximal ? Repeat.maximal(ret) : ret;
}
@@
-263,7
+256,7
@@
public class MetaGrammar extends ReflectiveWalker {
public PreSequence(Object[] o, String tag) { this(o, tag, false); }
public PreSequence(Object[] o, String tag, boolean keeper) { this.o = o; this.tag = tag; this.keeper = keeper; }
boolean[] drops = null;
public PreSequence(Object[] o, String tag) { this(o, tag, false); }
public PreSequence(Object[] o, String tag, boolean keeper) { this.o = o; this.tag = tag; this.keeper = keeper; }
boolean[] drops = null;
- public Element[] expand(Element ws, Union u, HashSet<Sequence> set) {
+ public Element[] expand(Union u, HashSet<Sequence> set) {
if (o==null) return new Element[0];
Element[] o2 = new Element[o.length];
drops = new boolean[o.length];
if (o==null) return new Element[0];
Element[] o2 = new Element[o.length];
drops = new boolean[o.length];
@@
-271,11
+264,11
@@
public class MetaGrammar extends ReflectiveWalker {
for(int i=0; i<o.length; i++) {
Object oi = o[i];
if (oi instanceof MyDrop) { oi = ((MyDrop)oi).o; drops[j] = true; }
for(int i=0; i<o.length; i++) {
Object oi = o[i];
if (oi instanceof MyDrop) { oi = ((MyDrop)oi).o; drops[j] = true; }
- if (oi instanceof PreSequence) o2[j] = ((PreSequence)oi).buildUnion(ws);
+ if (oi instanceof PreSequence) o2[j] = ((PreSequence)oi).buildUnion();
else if (oi==SELF) o2[j] = u.new Subset("(("+u+"))", set);
else if (oi instanceof MyLift) { o2[j] = CharToken.string(tag = ((MyLift)oi).s); drops[j] = true; }
else if (oi instanceof String) { o2[j] = CharToken.string( ((String)oi) ); drops[j] = true; }
else if (oi==SELF) o2[j] = u.new Subset("(("+u+"))", set);
else if (oi instanceof MyLift) { o2[j] = CharToken.string(tag = ((MyLift)oi).s); drops[j] = true; }
else if (oi instanceof String) { o2[j] = CharToken.string( ((String)oi) ); drops[j] = true; }
- else if (oi instanceof Rep) o2[j] = ((Rep)oi).build(ws);
+ else if (oi instanceof Rep) o2[j] = ((Rep)oi).build();
//else if (oi instanceof PreBrace) o2[j]
else o2[j] = (Element)oi;
//else if (oi instanceof PreBrace) o2[j]
else o2[j] = (Element)oi;
@@
-284,6
+277,8
@@
public class MetaGrammar extends ReflectiveWalker {
o2[j] = o2[j];
j++;
}
o2[j] = o2[j];
j++;
}
+ return o2;
+ /*
if (ws == null || o2.length <= 1) return o2;
Element[] ret = new Element[o2.length*2-1];
boolean[] drops2 = new boolean[ret.length];
if (ws == null || o2.length <= 1) return o2;
Element[] ret = new Element[o2.length*2-1];
boolean[] drops2 = new boolean[ret.length];
@@
-294,31
+289,32
@@
public class MetaGrammar extends ReflectiveWalker {
}
drops = drops2;
return ret;
}
drops = drops2;
return ret;
+ */
}
}
- public Union buildUnion(Element ws) {
+ public Union buildUnion() {
Union u = new Union("???");
Union u = new Union("???");
- u.add(buildSequence(ws, u));
+ u.add(buildSequence(u));
return u;
}
return u;
}
- public Sequence buildSequence(Element ws, Union u) { return buildSequence(ws, u, false, false); }
- public Sequence buildSequence(Element ws, Union u, boolean lame, boolean dropAll) {
+ public Sequence buildSequence(Union u) { return buildSequence(u, false, false); }
+ public Sequence buildSequence(Union u, boolean lame, boolean dropAll) {
HashSet<Sequence> and = new HashSet<Sequence>();
HashSet<Sequence> not = new HashSet<Sequence>();
for(PreSequence p : needs) {
HashSet<Sequence> and = new HashSet<Sequence>();
HashSet<Sequence> not = new HashSet<Sequence>();
for(PreSequence p : needs) {
- Sequence ps = p.buildSequence(ws, u, true, dropAll);
+ Sequence ps = p.buildSequence(u, true, dropAll);
u.add(ps);
and.add(ps);
}
for(Sequence p : hatess) not.add(p);
for(PreSequence p : hates) {
u.add(ps);
and.add(ps);
}
for(Sequence p : hatess) not.add(p);
for(PreSequence p : hates) {
- Sequence ps = p.buildSequence(ws, u, true, dropAll);
+ Sequence ps = p.buildSequence(u, true, dropAll);
u.add(ps);
not.add(ps);
}
HashSet<Sequence> set = new HashSet<Sequence>();
u.add(ps);
not.add(ps);
}
HashSet<Sequence> set = new HashSet<Sequence>();
- Element[] expansion = expand(ws, u, set);
+ Element[] expansion = expand(u, set);
boolean keeper = this.keeper;
Sequence ret = dropAll || lame || keeper ? Sequence.drop(expansion, and, not, lame) : null;
if (ret==null && tag!=null) {
boolean keeper = this.keeper;
Sequence ret = dropAll || lame || keeper ? Sequence.drop(expansion, and, not, lame) : null;
if (ret==null && tag!=null) {