diff --git a/ParserGenApp/PGDocument.h b/ParserGenApp/PGDocument.h index 02cfbfc..4103e08 100644 --- a/ParserGenApp/PGDocument.h +++ b/ParserGenApp/PGDocument.h @@ -30,8 +30,6 @@ @property (nonatomic, copy) NSString *destinationPath; @property (nonatomic, copy) NSString *parserName; -@property (nonatomic, copy) NSString *grammar; -@property (nonatomic, assign) BOOL busy; @property (nonatomic, retain) NSError *error; @property (nonatomic, assign) BOOL enableARC; @@ -41,5 +39,10 @@ @property (nonatomic, assign) NSInteger delegatePreMatchCallbacksOn; @property (nonatomic, assign) NSInteger delegatePostMatchCallbacksOn; +// These two are here for backwards compatibiltly with old saved files +@property (nonatomic, copy) NSString *grammar; +@property (nonatomic, assign) BOOL busy; + + @property (nonatomic, retain) IBOutlet NSTextView *textView; @end diff --git a/ParserGenApp/PGDocument.m b/ParserGenApp/PGDocument.m index 3f5b2b6..31cc37a 100644 --- a/ParserGenApp/PGDocument.m +++ b/ParserGenApp/PGDocument.m @@ -28,6 +28,8 @@ @interface PGDocument () @property (nonatomic, retain) PGParserFactory *factory; @property (nonatomic, retain) PGRootNode *root; @property (nonatomic, retain) PGParserGenVisitor *visitor; + +@property (nonatomic, retain) NSString* loadGrammar; @end @implementation PGDocument @@ -48,9 +50,6 @@ - (instancetype)init { self.delegatePreMatchCallbacksOn = PGParserFactoryDelegateCallbacksOnNone; self.delegatePostMatchCallbacksOn = PGParserFactoryDelegateCallbacksOnAll; - - NSString *path = [[NSBundle mainBundle] pathForResource:@"expression" ofType:@"grammar"]; - self.grammar = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; } return self; } @@ -59,7 +58,6 @@ - (instancetype)init { - (void)dealloc { self.destinationPath = nil; self.parserName = nil; - self.grammar = nil; self.textView = nil; @@ -86,6 +84,13 @@ - (NSString *)windowNibName { - (void)windowControllerDidLoadNib:(NSWindowController *)wc { [super windowControllerDidLoadNib:wc]; + NSString *path = [[NSBundle mainBundle] pathForResource:@"expression" ofType:@"grammar"]; + NSString *grammarVal = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; + if (grammarVal) { + [self.textView setString:grammarVal]; + } + + // Since maverics the check boxes in interface builder do not work to // turn off smart substitution on dashes and quotes [_textView setAutomaticDashSubstitutionEnabled:NO]; @@ -93,6 +98,12 @@ - (void)windowControllerDidLoadNib:(NSWindowController *)wc { [_textView setFont:[NSFont fontWithName:@"Monaco" size:12.0]]; [self focusTextView]; + + if (self.loadGrammar != nil) { + [self.textView setString: self.loadGrammar]; + self.loadGrammar = nil; + } + } @@ -106,7 +117,8 @@ - (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError { NSMutableDictionary *tab = [NSMutableDictionary dictionaryWithCapacity:9]; if (_destinationPath) tab[@"destinationPath"] = _destinationPath; - if (_grammar) tab[@"grammar"] = _grammar; + NSString* grammarVal = [self.textView string]; + if (grammarVal) tab[@"grammar"] = grammarVal; if (_parserName) tab[@"parserName"] = _parserName; tab[@"enableARC"] = @(_enableARC); tab[@"enableHybridDFA"] = @(_enableHybridDFA); @@ -129,7 +141,11 @@ - (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError * //NSLog(@"%@", tab); self.destinationPath = tab[@"destinationPath"]; - self.grammar = tab[@"grammar"]; + if (self.textView != nil) { + [self.textView setString:tab[@"grammar"]]; + } else { + self.loadGrammar = tab[@"grammar"]; + } self.parserName = tab[@"parserName"]; self.enableARC = [tab[@"enableARC"] boolValue]; self.enableHybridDFA = [tab[@"enableHybridDFA"] boolValue]; @@ -148,14 +164,13 @@ - (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError * - (IBAction)generate:(id)sender { NSString *destPath = [[_destinationPath copy] autorelease]; NSString *parserName = [[_parserName copy] autorelease]; - NSString *grammar = [[_grammar copy] autorelease]; + NSString *grammar = [self.textView string]; if (![destPath length] || ![parserName length] || ![grammar length]) { NSBeep(); return; } - self.busy = YES; self.error = nil; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ @@ -230,7 +245,7 @@ - (IBAction)reveal:(id)sender { - (void)generateWithDestinationPath:(NSString *)destPath parserName:(NSString *)parserName grammar:(NSString *)grammar { NSError *err = nil; - self.root = (id)[_factory ASTFromGrammar:_grammar error:&err]; + self.root = (id)[_factory ASTFromGrammar:grammar error:&err]; if (err) { self.error = err; goto done; @@ -300,7 +315,6 @@ - (void)done { [[NSSound soundNamed:@"Hero"] play]; } - self.busy = NO; [self focusTextView]; } diff --git a/ParserGenApp/en.lproj/PGDocument.xib b/ParserGenApp/en.lproj/PGDocument.xib index 59a5bee..b3ee1dc 100644 --- a/ParserGenApp/en.lproj/PGDocument.xib +++ b/ParserGenApp/en.lproj/PGDocument.xib @@ -1,8 +1,9 @@ - + - + + @@ -57,29 +58,17 @@ - + - + - + - - - - - NSNegateBoolean - - - - - - - @@ -91,7 +80,7 @@ - +