projects
/
sbp.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
checkpoint
[sbp.git]
/
src
/
edu
/
berkeley
/
sbp
/
misc
/
MetaGrammar.java
diff --git
a/src/edu/berkeley/sbp/misc/MetaGrammar.java
b/src/edu/berkeley/sbp/misc/MetaGrammar.java
index
bc171da
..
13da0ca
100644
(file)
--- a/
src/edu/berkeley/sbp/misc/MetaGrammar.java
+++ b/
src/edu/berkeley/sbp/misc/MetaGrammar.java
@@
-152,16
+152,25
@@
public class MetaGrammar extends ReflectiveWalker {
public PreSequence sparse(Object e) {
Object[] ret;
public PreSequence sparse(Object e) {
Object[] ret;
- if (o.length <= 1) ret = o;
- else {
+ boolean[] drops;
+ if (o.length <= 1) {
+ ret = o;
+ drops = new boolean[this.drops.length];
+ System.arraycopy(this.drops, 0, drops, 0, this.drops.length);
+ } else {
ret = new Object[o.length * 2 - 1];
ret = new Object[o.length * 2 - 1];
+ drops = new boolean[o.length * 2 - 1];
for(int i=0; i<o.length; i++) {
Object oi = o[i];
ret[i*2] = oi;
for(int i=0; i<o.length; i++) {
Object oi = o[i];
ret[i*2] = oi;
- if (i*2+1<ret.length) ret[i*2+1] = new MyDrop(e);
+ drops[i*2] = this.drops[i];
+ if (i*2+1<ret.length) {
+ ret[i*2+1] = new MyDrop(e);
+ drops[i*2+1] = true;
+ }
}
}
}
}
- PreSequence p = new PreSequence(ret, tag);
+ PreSequence p = new PreSequence(ret, tag, drops);
p.not.addAll(not);
p.and.addAll(and);
return p;
p.not.addAll(not);
p.and.addAll(and);
return p;
@@
-170,9
+179,15
@@
public class MetaGrammar extends ReflectiveWalker {
public PreSequence not(Sequence s) { not.add(s); return this; }
public PreSequence and(Sequence s) { and.add(s); return this; }
public PreSequence not(Sequence s) { not.add(s); return this; }
public PreSequence and(Sequence s) { and.add(s); return this; }
+ boolean[] drops = null;
public PreSequence(Object o) { this(new Object[] { o }, null); }
public PreSequence(Object[] o) { this(o, null); }
public PreSequence(Object o) { this(new Object[] { o }, null); }
public PreSequence(Object[] o) { this(o, null); }
- public PreSequence(Object[] o, String tag) { this.o = o; this.tag = tag; }
+ public PreSequence(Object[] o, String tag) { this(o, tag, null); }
+ public PreSequence(Object[] o, String tag, boolean[] drops) {
+ this.o = o;
+ this.tag = tag;
+ this.drops = drops==null ? new boolean[o.length] : drops;
+ }
public Union buildUnion() {
Union u = new Union("???");
public Union buildUnion() {
Union u = new Union("???");
@@
-186,9
+201,7
@@
public class MetaGrammar extends ReflectiveWalker {
HashSet<Sequence> set = new HashSet<Sequence>();
Element[] o2 = o==null ? new Element[0] : new Element[o.length];
int nonDrop = 0;
HashSet<Sequence> set = new HashSet<Sequence>();
Element[] o2 = o==null ? new Element[0] : new Element[o.length];
int nonDrop = 0;
- boolean[] drops = null;
if (o != null) {
if (o != null) {
- drops = new boolean[o.length];
int j = 0;
for(int i=0; i<o.length; i++) {
Object oi = o[i];
int j = 0;
for(int i=0; i<o.length; i++) {
Object oi = o[i];