1 Prewrite : FilterPattern {
2 var <>dict, <>levels=1;
3 *new { arg pattern, dict, levels;
4 ^super.new(pattern).dict_(dict).levels_(levels)
6 storeArgs { ^[ pattern, dict, levels ] }
7 rewriteList { arg list, inval, level;
10 // if at bottom level, then embed all items in the stream
11 if (list.isSequenceableCollection, {
12 // isKindOf is necessary because Integer.do would do the wrong thing..
14 inval = item.embedInStream(inval);
17 inval = list.embedInStream(inval);
20 if (list.isSequenceableCollection, {
21 // isKindOf is necessary because Integer.do would do the wrong thing..
23 // lookup item in rewrite dictionary
24 newlist = dict.at(item);
28 // do another level of rewriting
29 inval = this.rewriteList( newlist, inval, level - 1 );
31 // has no dictionary entry, so embed in stream
32 inval = item.embedInStream(inval);
36 // lookup item in rewrite dictionary
37 newlist = dict.at(list);
41 // do another level of rewriting
42 inval = this.rewriteList( newlist, inval, level - 1 );
44 // has no dictionary entry, so embed in stream
45 inval = list.embedInStream(inval);
51 embedInStream { arg inval;
55 stream = pattern.asStream;
57 outval = stream.next(inval);
60 inval = this.rewriteList(outval, inval, levels);