Skip to content
Browse files

New tests and fixes for broken ones.

  • Loading branch information...
1 parent 4199d45 commit 11c49eba61d9bc4d5d6727728ede7a3acf7d810b @ccgus committed Oct 24, 2011
View
10 experimental/README.md
@@ -5,9 +5,9 @@ This is not being done on a branch because Gus started doing that and kept on sc
Notes from Gus, for Gus:
-Oct 2, 2011:
-The current plan for the new parser is to preprocess jstalk/objc messages into jstobjc_msgSend, since that's reasonably unique and we can special case things in there for calls that return floats or structs or whatever. So '[NSString string]' would become 'jstobjc_msgSend(NSString, "string")', '[Foo isEqualTo:"foo"]' objc_msgSend(Foo, "isEqualToString:", "foo")
+Oct 24, 2011:
+There's a ton of unfinished code laying around, and since I tend to be scatterbrained it should probably be ignored. It'll be rewritten, as this is currently a playground for my ideas.
-What's the best way to setup tests for this though? I want them written in JSTalk itself, but that gets a bit tricky. So currently that's what I'm working on exploring.
-
-There's a ton of unfinished code laying around, and since I tend to be scatterbrained it should probably be ignored. It'll be rewritten, as this is currently a playground for my ideas.
+## Random Things for Gus to Fix:
+Oct 23, 2011:
+Hey, mixing TDTokens and JSTPSymbolGroup(s) together in JSTPSymbolGroup's _args array is a really bad idea. What you need to do is make a common subclass for those two, so you don't have to keep on checking if you're working with a TDToken first in description.
View
64 experimental/src/JSTPreprocessor.m
@@ -149,7 +149,7 @@ + (NSString*)preprocessForObjCMessagesToJS:(NSString*)sourceString {
}
//debug(@"printing tree");
- //[baseGroup printTree:0];
+ [baseGroup printTree:0];
return [baseGroup description];
}
@@ -303,6 +303,38 @@ - (void)printDept:(int)depth {
}
}
+- (NSString*)typeOfToken:(TDToken*)tok {
+ if (![tok isKindOfClass:[TDToken class]]) {
+ return @"not a token";
+ }
+
+ if ([tok isNumber]) {
+ return @"number";
+ }
+
+ if ([tok isQuotedString]) {
+ return @"quoted string";
+ }
+
+ if ([tok isSymbol]) {
+ return @"symbol";
+ }
+
+ if ([tok isWord]) {
+ return @"word";
+ }
+
+ if ([tok isWhitespace]) {
+ return @"whitespace";
+ }
+
+ if ([tok isComment]) {
+ return @"comment";
+ }
+
+ return [NSString stringWithFormat:@"unknown token type (%d)", [tok tokenType]];
+}
+
- (void)printTree:(int)depth {
for (id arg in _args) {
@@ -312,7 +344,7 @@ - (void)printTree:(int)depth {
}
else {
[self printDept:depth];
- printf("%s\n", [[arg description] UTF8String]);
+ printf("%s (%s)\n", [[arg description] UTF8String], [[self typeOfToken:arg] UTF8String]);
}
}
}
@@ -327,6 +359,34 @@ - (NSString*)description {
return [_args componentsJoinedByString:@""];
}
+ TDToken *secondArg = [_args objectAtIndex:1];
+ if ([secondArg isKindOfClass:[TDToken class]] && ![secondArg isWord]) {
+ return [_args componentsJoinedByString:@""];
+ }
+
+ TDToken *thirdArgSkippingWhitespace = 0x00;
+ int idx = 2;
+ while (idx < [_args count]) {
+ TDToken *foundTok = [_args objectAtIndex:idx];
+ idx++;
+
+ if (![foundTok isKindOfClass:[TDToken class]]) {
+ continue;
+ }
+
+ if ([foundTok isComment] || [foundTok isWhitespace]) {
+ continue;
+ }
+
+ thirdArgSkippingWhitespace = foundTok;
+ break;
+
+ }
+
+ if (![thirdArgSkippingWhitespace isWord]) {
+ return [_args componentsJoinedByString:@""];
+ }
+
NSMutableArray *argsCopy = [[_args mutableCopy] autorelease];
[argsCopy removeObjectAtIndex:0];
View
6 experimental/tests/preprocess/testPreprocess01.jstalk
@@ -9,3 +9,9 @@ print([NSString stringWithString:@"a"+"b"])
[fo doSomething:" a " + [b fun] + " c " in:nil];
[varName messageSel:foo[12 + [arg getNumb:12]]];
+
+[varName messageSel:foo[1 + 2]];
+
+foo[a + 2];
+
+foo[[arg getNumb:1] + 2];
View
8 experimental/tests/preprocess/testPreprocess01.jstpc
@@ -8,4 +8,10 @@ print(jst_msgSend(NSString, "stringWithString:", JSTNSString("a")+"b"))
jst_msgSend(fo, "doSomething:in:", " a " + jst_msgSend(b, "fun") + " c " , null);
-jst_msgSend(varName, "messageSel:", foo[12 + jst_msgSend(arg, "getNumb:", 12)]);
+jst_msgSend(varName, "messageSel:", foo[12 + jst_msgSend(arg, "getNumb:", 12)]);
+
+jst_msgSend(varName, "messageSel:", foo[1 + 2]);
+
+foo[a + 2];
+
+foo[jst_msgSend(arg, "getNumb:", 1) + 2];

0 comments on commit 11c49eb

Please sign in to comment.
Something went wrong with that request. Please try again.