Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 163 lines (127 sloc) 3.225 kb
98b7f3c Beginnings of porting the Obj-C code to Obj-J.
Ross Boucher authored
1
2 @import <Foundation/Foundation.j>
3
4 TDAssemblyDefaultDelimiter = @"/";
5
94e84d9 Fix the build errors.
Ross Boucher authored
6 @implementation TDAssembly : CPObject
98b7f3c Beginnings of porting the Obj-C code to Obj-J.
Ross Boucher authored
7 {
8 CPArray stack;
9 id target;
10 unsigned index;
11 CPString string;
12 CPString defaultDelimiter;
13 }
14
15 + (id)assemblyWithString:(CPString)s
16 {
17 return [[self alloc] initWithString:s];
18 }
19
20 - (id)init
21 {
22 return [self initWithString:nil];
23 }
24
25 - (id)initWithString:(CPString)s
26 {
94e84d9 Fix the build errors.
Ross Boucher authored
27 if (self = [super init]) {
98b7f3c Beginnings of porting the Obj-C code to Obj-J.
Ross Boucher authored
28 stack = [];
29 string = s;
30 }
31
32 return self;
33 }
34
35 // this private intializer exists simply to improve the performance of the -copyWithZone: method.
36 // note flow *does not* go thru the designated initializer above. however, that ugliness is worth it cuz
37 // the perf of -copyWithZone: in this class is *vital* to the framework's performance
38 - (id)_init
39 {
40 return [super init];
41 }
42
43 // this method diverges from coding standards cuz it is vital to the entire framework's performance
44 - (id)copy
45 {
46 var a = [[[self class] alloc] _init];
47
48 a.stack = [stack copy];
49 a.string = string;
50 a.index = index;
51
52 if (defaultDelimiter)
53 a.defaultDelimiter = defaultDelimiter;
54
55 if (target)
56 a.target = [target copy]
57
58 return a;
59 }
60
61 - (id)next {
62 //NSAssert1(0, @"-[TDAssembly %s] must be overriden", _cmd);
63 return nil;
64 }
65
66 - (BOOL)hasMore {
67 //NSAssert1(0, @"-[TDAssembly %s] must be overriden", _cmd);
68 return NO;
69 }
70
71 - (CPString)consumedObjectsJoinedByString:(CPString)delimiter {
72 //NSAssert1(0, @"-[TDAssembly %s] must be overriden", _cmd);
73 return nil;
74 }
75
76 - (CPString)remainingObjectsJoinedByString:(CPString)delimiter {
77 //NSAssert1(0, @"-[TDAssembly %s] must be overriden", _cmd);
78 return nil;
79 }
80
81 - (unsigned)length {
82 //NSAssert1(0, @"-[TDAssembly %s] must be overriden", _cmd);
83 return 0;
84 }
85
86 - (unsigned)objectsConsumed {
87 //NSAssert1(0, @"-[TDAssembly %s] must be overriden", _cmd);
88 return 0;
89 }
90
91 - (unsigned)objectsRemaining {
92 //NSAssert1(0, @"-[TDAssembly %s] must be overriden", _cmd);
93 return 0;
94 }
95
96 - (id)peek {
97 //NSAssert1(0, @"-[TDAssembly %s] must be overriden", _cmd);
98 return nil;
99 }
100
101 - (id)pop
102 {
103 var result = nil;
94e84d9 Fix the build errors.
Ross Boucher authored
104 if (stack.length) {
98b7f3c Beginnings of porting the Obj-C code to Obj-J.
Ross Boucher authored
105 result = [stack lastObject];
106 [stack removeLastObject];
107 }
108 return result;
109 }
110
111 - (void)push:(id)object
112 {
113 if (object) {
114 [stack addObject:object];
115 }
116 }
117
118 - (BOOL)isStackEmpty {
94e84d9 Fix the build errors.
Ross Boucher authored
119 return 0 === stack.length;
98b7f3c Beginnings of porting the Obj-C code to Obj-J.
Ross Boucher authored
120 }
121
122 - (CPArray)objectsAbove:(id)fence
123 {
124 var result = [];
125
126 while (stack.count) {
127 var obj = [self pop];
128
129 if ([obj isEqual:fence]) {
130 [self push:obj];
131 break;
132 } else {
133 [result addObject:obj];
134 }
135 }
136
137 return result;
138 }
139
140 - (CPString)description
141 {
142 var s = "[",
143 i = 0,
144 length = stack.count;
145
146 for (;i<length;i++) {
147 s = s + [obj description];
148 if (len - 1 !== i++) {
149 s = s + ", ";
150 }
151 }
152
153 s = s + "]";
154
155 var d = defaultDelimiter ? defaultDelimiter : TDAssemblyDefaultDelimiter;
156
157 s = s + [self consumedObjectsJoinedByString:d] + "^" + [self remainingObjectsJoinedByString:d];
158
159 return s;
160 }
161
162 @end
Something went wrong with that request. Please try again.