Permalink
Browse files

More goodness

  • Loading branch information...
1 parent 403ea4f commit 48664c407347642417825809600538825a52016c @ccgus committed Jul 22, 2012
Showing with 47 additions and 46 deletions.
  1. +29 −43 src/JSTDocument.m
  2. +4 −1 src/JSTPreprocessor.m
  3. +4 −0 src/JSTalk.h
  4. +10 −2 src/JSTalk.m
View
@@ -141,10 +141,7 @@ - (void)print:(NSString*)s {
}
-/*
-- (void)JSCocoa:(JSCocoaController*)controller hadError:(NSString*)error onLineNumber:(NSInteger)lineNumber atSourceURL:(id)url {
-
- lineNumber -= 1;
+- (void)JSTalk:(JSTalk*)jstalk hadError:(NSString*)error onLineNumber:(NSInteger)lineNumber atSourceURL:(id)url {
if (!error) {
return;
@@ -170,53 +167,42 @@ - (void)JSCocoa:(JSCocoaController*)controller hadError:(NSString*)error onLineN
}
}
}
- */
-
- (void)runScript:(NSString*)s {
- @try {
-
- JSTalk *jstalk = [[JSTalk alloc] init];
-
- [[[NSThread currentThread] threadDictionary] setObject:jstalk forKey:@"org.jstalk.currentJSTalkContext"];
-
- #pragma message "FIXME: the error delegate stuff needs to be added back in"
- //jsController.delegate = self;
-
- jstalk.printController = self;
-
- [errorLabel setStringValue:@""];
-
- if ([self fileURL]) {
- [jstalk.env setObject:[self fileURL] forKey:@"scriptURL"];
- }
-
- if ([JSTPrefs boolForKey:@"clearConsoleOnRun"]) {
- [self clearConsole:nil];
- }
-
- id result = [jstalk executeString:s];
-
- if (result) {
- [self print:[result description]];
- }
-
- [[[NSThread currentThread] threadDictionary] removeObjectForKey:@"org.jstalk.currentJSTalkContext"];
-
- [jstalk release];
-
+ JSTalk *jstalk = [[JSTalk alloc] init];
+
+ [[[NSThread currentThread] threadDictionary] setObject:jstalk forKey:@"org.jstalk.currentJSTalkContext"];
+
+#pragma message "FIXME: the error delegate stuff needs to be added back in"
+ //jsController.delegate = self;
+
+ [jstalk setPrintController:self];
+ [jstalk setErrorController:self];
+
+ [errorLabel setStringValue:@""];
+
+ if ([self fileURL]) {
+ [jstalk.env setObject:[self fileURL] forKey:@"scriptURL"];
}
- @catch (NSException * e) {
- [self print:[e reason]];
+
+ if ([JSTPrefs boolForKey:@"clearConsoleOnRun"]) {
+ [self clearConsole:nil];
}
- @finally {
- // um.?
+
+ id result = [jstalk executeString:s];
+
+ if (result) {
+ [self print:[result description]];
}
-
+
+ [[[NSThread currentThread] threadDictionary] removeObjectForKey:@"org.jstalk.currentJSTalkContext"];
+
+ [jstalk release];
+
}
-- (void)executeScript:(id)sender {
+- (void)executeScript:(id)sender {
[self runScript:[[jsTextView textStorage] string]];
}
View
@@ -19,6 +19,10 @@ + (NSString*)processMultilineStrings:(NSString*)sourceString {
NSString *tok = @"\"\"\"";
NSScanner *scanner = [NSScanner scannerWithString:sourceString];
+
+ // we don't want to skip any whitespace at the front, so we give it an empty character set.
+ [scanner setCharactersToBeSkipped:[NSCharacterSet characterSetWithCharactersInString:@""]];
+
NSMutableString *ret = [NSMutableString string];
while (![scanner isAtEnd]) {
@@ -30,7 +34,6 @@ + (NSString*)processMultilineStrings:(NSString*)sourceString {
[ret appendString:into];
}
-
if ([scanner scanString:tok intoString:nil]) {
if ([scanner scanString:tok intoString: nil]) {
continue;
View
@@ -39,3 +39,7 @@
+ (JSTalk*)currentJSTalk;
@end
+
+@interface NSObject (JSTalkErrorControllerMethods)
+- (void)JSTalk:(JSTalk*)jstalk hadError:(NSString*)error onLineNumber:(NSInteger)lineNumber atSourceURL:(id)url;
+@end
View
@@ -268,8 +268,16 @@ - (id)executeString:(NSString*)str {
resultObj = nil;
}
}
- @catch (NSException * e) {
- NSLog(@"Exception: %@", e);
+ @catch (NSException *e) {
+
+ NSDictionary *d = [e userInfo];
+ if ([d objectForKey:@"line"]) {
+ if ([_errorController respondsToSelector:@selector(JSTalk:hadError:onLineNumber:atSourceURL:)]) {
+ [_errorController JSTalk:self hadError:[e reason] onLineNumber:[[d objectForKey:@"line"] integerValue] atSourceURL:nil];
+ }
+ }
+
+ NSLog(@"Exception: %@", [e userInfo]);
[self print:[e description]];
}
@finally {

0 comments on commit 48664c4

Please sign in to comment.