I use the following.
Basically we build a block from our source and trap any exceptions that result.
The only small issue is the need to access framework non public API.
Regards
Jonathan Mitchell
Mugginsoft LLP
================================================
KosmicTask - the Integrated Scripting Environment for OS X.
http://www.mugginsoft.com/KosmicTask
================================================
#import <FScript/FScript.h>
#import "BlockStackElem.h" // on user search path
- (BOOL)build {
NSString *resultString = @"";
// get script source
NSString *source = [self scriptSourceWithError:YES];
if (!source) return NO;
@try {
// make a block. raises on compilation or syntax error
//
// http://www.fscript.org/documentation/EmbeddingFScriptIntoCocoa/index.htm
//
FSBlock *block = [source asBlock];
(void)block;
}
@catch (NSException* e) {
NSDictionary *userInfo = [e userInfo];
// the exception reason has the error string but no line number info
// (this could perhaps be calculated from the character indicies in
// BlockStackElem)
NSArray *blockStack = [userInfo objectForKey:@"FScriptBlockStack"];
// block stack elem is not part of the public API
// hence we import it separately.
// FSInterpreterResult does supply all error info
// but it is returned only as result of execution
BlockStackElem *blockStackElem = [blockStack objectAtIndex:0];
// report error
self.error = [NSString stringWithFormat:@"%@", [blockStackElem errorStr]];
// get error range
NSUInteger firstCharIndex = [blockStackElem firstCharIndex];
NSUInteger lastCharIndex = [blockStackElem lastCharIndex];
NSRange range = NSMakeRange(firstCharIndex, lastCharIndex - firstCharIndex);
self.errorInfo = [NSMutableDictionary dictionaryWithCapacity:2];
[self.errorInfo setObject:NSStringFromRange(range) forKey:MGSRangeErrorKey];
[self.errorInfo setObject:self.error forKey:NSLocalizedFailureReasonErrorKey]; // required
}
return [self processBuildResult:resultString];
}
--
You received this message because you are subscribed to the Google Groups "F-Script" group.
To post to this group, send email to f-sc...@googlegroups.com.
To unsubscribe from this group, send email to f-script+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/f-script?hl=en.