Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 107 lines (82 sloc) 2.093 kb
98b7f3c Beginnings of porting the Obj-C code to Obj-J.
Ross Boucher authored
1
2 @import <Foundation/Foundation.j>
3 @import "TDAssembly.j"
4
94e84d9 Fix the build errors.
Ross Boucher authored
5 @implementation TDParser : CPObject
98b7f3c Beginnings of porting the Obj-C code to Obj-J.
Ross Boucher authored
6 {
7 id assembler;
8 SEL selector;
9 CPString name;
10 }
11
12 + (id)parser
13 {
14 return [[self alloc] init];
15 }
16
17 - (id)init
18 {
19 return self = [super init];
20 }
21
22 - (void)setAssembler:(id)a selector:(SEL)sel
23 {
24 [self setAssembler:a];
25 [self setSelector:sel];
26 }
27
28 - (TDParser)parserNamed:(CPString)s
29 {
30 if (name === s)
31 return self;
32
33 return nil;
34 }
35
36 - (CPSet)allMatchesFor:(CPSet)inAssemblies
37 {
38 //NSAssert1(0, @"-[TDParser %s] must be overriden", _cmd);
39 return nil;
40 }
41
42 - (TDAssembly)bestMatchFor:(TDAssembly)a
43 {
44 var initialState = [CPSet setWithObject:a],
45 finalState = [self matchAndAssemble:initialState];
46
47 return [self best:finalState];
48 }
49
50 - (TDAssembly)completeMatchFor:(TDAssembly)a
51 {
52 var best = [self bestMatchFor:a];
53
54 if (best && ![best hasMore])
55 return best;
56
57 return nil;
58 }
59
60 - (CPSet)matchAndAssemble:(CPSet)inAssemblies
61 {
62 var outAssemblies = [self allMatchesFor:inAssemblies];
63
64 if (assembler) {
65 //NSAssert2([assembler respondsToSelector:selector], @"provided assembler %@ should respond to %s", assembler, selector);
66 var values = [outAssemblies allValues],
67 length = [values count];
68
69 for (var i=0; i<length; i++) {
70 [assembler performSelector:selector withObject:values[i]];
71 }
72 }
73
74 return outAssemblies;
75 }
76
77 - (TDAssembly)best:(CPSet)inAssemblies
78 {
79 var best = nil,
80 values = [inAssemblies allValues],
81 length = [values count];
82
83 for (var i=0; i<length; i++) {
84 var a = values[i];
85
86 if (![a hasMore]) {
87 best = a;
88 break;
89 }
90
91 if (!best || a.objectsConsumed > best.objectsConsumed)
92 best = a;
93 }
94
95 return best;
96 }
97
98 - (CPString)description
99 {
100 if (name.length)
101 return [CPString stringWithFormat:@"%@ (%@)", [self className], name];
102 else
103 return [CPString stringWithFormat:@"%@", [self className]];
104 }
105
106 @end
Something went wrong with that request. Please try again.