Skip to content

Commit

Permalink
Experimental preprocessor tests now pass.
Browse files Browse the repository at this point in the history
  • Loading branch information
ccgus committed Oct 21, 2011
1 parent 786a245 commit 3370e9d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
2 changes: 1 addition & 1 deletion experimental/src/JSTPreprocessor.h
Expand Up @@ -25,7 +25,6 @@
NSMutableArray *_args;
JSTPSymbolGroup *_parent;
BOOL _isBaseGroup;
BOOL _msgSend;
}

@property (retain) NSMutableArray *args;
Expand All @@ -35,6 +34,7 @@

- (void)addSymbol:(id)aSymbol;

- (void)printTree:(int)depth;
@end


44 changes: 32 additions & 12 deletions experimental/src/JSTPreprocessor.m
Expand Up @@ -120,7 +120,6 @@ + (NSString*)preprocessForObjCMessagesToJS:(NSString*)sourceString {

while ((tok = [tokenizer nextToken]) != eof) {


if ([tok isSymbol] && [self isOpenGroupSymbol:[tok stringValue]]) {

JSTPSymbolGroup *nextGroup = [[[JSTPSymbolGroup alloc] init] autorelease];
Expand Down Expand Up @@ -149,6 +148,9 @@ + (NSString*)preprocessForObjCMessagesToJS:(NSString*)sourceString {
}
}

//debug(@"printing tree");
//[baseGroup printTree:0];

return [baseGroup description];
}

Expand All @@ -169,6 +171,7 @@ @implementation JSTPSymbolGroup
@synthesize args=_args;
@synthesize parent=_parent;
@synthesize isBaseGroup=_isBaseGroup;
@synthesize functionHead=_functionHead;

- (id)init {
self = [super init];
Expand All @@ -183,6 +186,7 @@ - (id)init {
- (void)dealloc {
[_args release];
[_parent release];
[_functionHead release];

[super dealloc];
}
Expand Down Expand Up @@ -233,12 +237,16 @@ - (void)addSymbol:(id)aSymbol {
}
else if (_openSymbol == '[') {
// whoa- are we array access, or something else?

/*
id foo = [[self parent] lastNonWhitespaceOrCommentSymbol];
debug(@"foo: %@", foo);
debug(@"[foo isKindOfClass:[TDToken class]]: %d", [foo isKindOfClass:[TDToken class]]);
if (!foo || ([foo isKindOfClass:[TDToken class]] && [foo isSymbol])) {
_msgSend = YES;
}
*/
}
else if (_openSymbol == '{') {

Expand Down Expand Up @@ -289,21 +297,33 @@ - (id)firstNonWhitespaceObjectInArray:(NSArray*)ar startIndex:(NSUInteger)idx {

}

- (NSString*)description {
- (void)printDept:(int)depth {
for (int i = 0; i < depth; i++) {
printf("--");
}
}

- (void)printTree:(int)depth {

if (_openSymbol != '[') {

NSMutableString *ret = [NSMutableString string];
for (id arg in _args) {

for (id arg in _args) {
[ret appendString:[arg description]];
if ([arg isKindOfClass:[JSTPSymbolGroup class]]) {
[arg printTree:depth+1];
}

return ret;

else {
[self printDept:depth];
printf("%s\n", [[arg description] UTF8String]);
}
}
}

- (NSString*)description {

if (_openSymbol != '[') {
return [_args componentsJoinedByString:@""];
}

if (!_msgSend || ![[[_args lastObject] description] isEqualToString:@"]"] || ([_args count] < 4)) {
if (![[[_args lastObject] description] isEqualToString:@"]"] || ([_args count] < 4)) {
return [_args componentsJoinedByString:@""];
}

Expand Down
1 change: 1 addition & 0 deletions experimental/src/jstalkmain.m
Expand Up @@ -123,6 +123,7 @@ void testPreprocessAtPath(NSString *pathToScript) {
NSString *cmd = [NSString stringWithFormat:@"/usr/bin/diff %@ /private/tmp/jstb.jstalk", bp];
NSLog(@"%@", cmd);
system([cmd UTF8String]);
exit(123);
}
}

Expand Down
2 changes: 1 addition & 1 deletion experimental/tests/preprocess/testPreprocess01.jstpc
Expand Up @@ -6,4 +6,4 @@ jst_msgSend(NSFullUserName(), "lowercaseString");

print(jst_msgSend(NSString, "stringWithString:", JSTNSString("a")+"b"))

jst_msgSend(fo, "doSomething:in:", " a "+jst_msgSend(b, "fun")+" c ", null);
jst_msgSend(fo, "doSomething:in:", " a "+jst_msgSend(b, "fun")+" c ", null);

0 comments on commit 3370e9d

Please sign in to comment.