From 3370e9d5dd08835b250b7743505354bd15d9c977 Mon Sep 17 00:00:00 2001 From: August Mueller Date: Thu, 20 Oct 2011 21:04:17 -0700 Subject: [PATCH] Experimental preprocessor tests now pass. --- experimental/src/JSTPreprocessor.h | 2 +- experimental/src/JSTPreprocessor.m | 44 ++++++++++++++----- experimental/src/jstalkmain.m | 1 + .../tests/preprocess/testPreprocess01.jstpc | 2 +- 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/experimental/src/JSTPreprocessor.h b/experimental/src/JSTPreprocessor.h index 71cb96e..549d153 100644 --- a/experimental/src/JSTPreprocessor.h +++ b/experimental/src/JSTPreprocessor.h @@ -25,7 +25,6 @@ NSMutableArray *_args; JSTPSymbolGroup *_parent; BOOL _isBaseGroup; - BOOL _msgSend; } @property (retain) NSMutableArray *args; @@ -35,6 +34,7 @@ - (void)addSymbol:(id)aSymbol; +- (void)printTree:(int)depth; @end diff --git a/experimental/src/JSTPreprocessor.m b/experimental/src/JSTPreprocessor.m index 492221b..319694f 100644 --- a/experimental/src/JSTPreprocessor.m +++ b/experimental/src/JSTPreprocessor.m @@ -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]; @@ -149,6 +148,9 @@ + (NSString*)preprocessForObjCMessagesToJS:(NSString*)sourceString { } } + //debug(@"printing tree"); + //[baseGroup printTree:0]; + return [baseGroup description]; } @@ -169,6 +171,7 @@ @implementation JSTPSymbolGroup @synthesize args=_args; @synthesize parent=_parent; @synthesize isBaseGroup=_isBaseGroup; +@synthesize functionHead=_functionHead; - (id)init { self = [super init]; @@ -183,6 +186,7 @@ - (id)init { - (void)dealloc { [_args release]; [_parent release]; + [_functionHead release]; [super dealloc]; } @@ -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 == '{') { @@ -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:@""]; } diff --git a/experimental/src/jstalkmain.m b/experimental/src/jstalkmain.m index e5d0a36..0608bac 100644 --- a/experimental/src/jstalkmain.m +++ b/experimental/src/jstalkmain.m @@ -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); } } diff --git a/experimental/tests/preprocess/testPreprocess01.jstpc b/experimental/tests/preprocess/testPreprocess01.jstpc index 6d46242..d326264 100644 --- a/experimental/tests/preprocess/testPreprocess01.jstpc +++ b/experimental/tests/preprocess/testPreprocess01.jstpc @@ -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); \ No newline at end of file +jst_msgSend(fo, "doSomething:in:", " a "+jst_msgSend(b, "fun")+" c ", null);