Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions ParserGenApp/PGDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
34 changes: 24 additions & 10 deletions ParserGenApp/PGDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand All @@ -59,7 +58,6 @@ - (instancetype)init {
- (void)dealloc {
self.destinationPath = nil;
self.parserName = nil;
self.grammar = nil;

self.textView = nil;

Expand All @@ -86,13 +84,26 @@ - (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];
[_textView setAutomaticQuoteSubstitutionEnabled:NO];

[_textView setFont:[NSFont fontWithName:@"Monaco" size:12.0]];
[self focusTextView];

if (self.loadGrammar != nil) {
[self.textView setString: self.loadGrammar];
self.loadGrammar = nil;
}

}


Expand All @@ -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);
Expand All @@ -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];
Expand All @@ -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), ^{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -300,7 +315,6 @@ - (void)done {
[[NSSound soundNamed:@"Hero"] play];
}

self.busy = NO;
[self focusTextView];
}

Expand Down
25 changes: 7 additions & 18 deletions ParserGenApp/en.lproj/PGDocument.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9059" systemVersion="14F1021" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11542" systemVersion="15G1108" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9059"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11542"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="PGDocument">
Expand Down Expand Up @@ -57,29 +58,17 @@
<rect key="frame" x="20" y="20" width="554" height="227"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<clipView key="contentView" id="xnX-md-NJo">
<rect key="frame" x="1" y="1" width="552" height="225"/>
<rect key="frame" x="1" y="1" width="537" height="225"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView importsGraphics="NO" richText="NO" findStyle="panel" allowsUndo="YES" verticallyResizable="YES" allowsNonContiguousLayout="YES" spellingCorrection="YES" smartInsertDelete="YES" id="100032">
<textView importsGraphics="NO" richText="NO" findStyle="panel" allowsUndo="YES" allowsNonContiguousLayout="YES" spellingCorrection="YES" smartInsertDelete="YES" id="100032">
<rect key="frame" x="0.0" y="0.0" width="552" height="225"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<size key="minSize" width="552" height="225"/>
<size key="minSize" width="537" height="225"/>
<size key="maxSize" width="554" height="10000000"/>
<color key="insertionPointColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
<size key="minSize" width="552" height="225"/>
<size key="maxSize" width="554" height="10000000"/>
<connections>
<binding destination="-2" name="editable" keyPath="busy" id="100072">
<dictionary key="options">
<string key="NSValueTransformerName">NSNegateBoolean</string>
</dictionary>
</binding>
<binding destination="-2" name="value" keyPath="grammar" id="100056">
<dictionary key="options">
<bool key="NSContinuouslyUpdatesValue" value="YES"/>
</dictionary>
</binding>
<outlet property="nextKeyView" destination="100041" id="100060"/>
</connections>
</textView>
Expand All @@ -91,7 +80,7 @@
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" verticalHuggingPriority="750" doubleValue="1" horizontal="NO" id="100034">
<rect key="frame" x="537" y="1" width="16" height="225"/>
<rect key="frame" x="538" y="1" width="15" height="225"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
Expand Down