Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge from SVN. All new Static features included
- Loading branch information
Showing
441 changed files
with
30,684 additions
and
8,548 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// PGDocument.h | ||
// ParserGenApp | ||
// | ||
// Created by Todd Ditchendorf on 4/15/13. | ||
// | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
@interface PGDocument : NSDocument | ||
|
||
- (IBAction)generate:(id)sender; | ||
- (IBAction)browse:(id)sender; | ||
- (IBAction)reveal:(id)sender; | ||
|
||
@property (nonatomic, copy) NSString *destinationPath; | ||
@property (nonatomic, copy) NSString *parserName; | ||
@property (nonatomic, copy) NSString *grammar; | ||
@property (nonatomic, assign) BOOL busy; | ||
|
||
@property (nonatomic, assign) BOOL enableARC; | ||
@property (nonatomic, assign) BOOL enableHybridDFA; | ||
@property (nonatomic, assign) BOOL enableMemoization; | ||
@property (nonatomic, assign) BOOL enableAutomaticErrorRecovery; | ||
@property (nonatomic, assign) NSInteger preassemblerSettingBehavior; | ||
@property (nonatomic, assign) NSInteger assemblerSettingBehavior; | ||
|
||
@property (nonatomic, retain) IBOutlet NSTextView *textView; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,251 @@ | ||
// | ||
// PGDocument.m | ||
// ParserGenApp | ||
// | ||
// Created by Todd Ditchendorf on 4/15/13. | ||
// | ||
// | ||
|
||
#import "PGDocument.h" | ||
#import <ParseKit/ParseKit.h> | ||
#import "PKSParserGenVisitor.h" | ||
|
||
@interface PGDocument () | ||
@property (nonatomic, retain) PKParserFactory *factory; | ||
@property (nonatomic, retain) PKRootNode *root; | ||
@property (nonatomic, retain) PKSParserGenVisitor *visitor; | ||
@end | ||
|
||
@implementation PGDocument | ||
|
||
- (id)init { | ||
self = [super init]; | ||
if (self) { | ||
self.factory = [PKParserFactory factory]; | ||
_factory.collectTokenKinds = YES; | ||
|
||
self.enableARC = YES; | ||
self.enableHybridDFA = YES; | ||
self.enableMemoization = YES; | ||
self.enableAutomaticErrorRecovery = NO; | ||
|
||
self.destinationPath = [@"~/Desktop" stringByExpandingTildeInPath]; | ||
self.parserName = @"ExpressionParser"; | ||
|
||
self.preassemblerSettingBehavior = PKParserFactoryAssemblerSettingBehaviorNone; | ||
self.assemblerSettingBehavior = PKParserFactoryAssemblerSettingBehaviorAll; | ||
|
||
NSString *path = [[NSBundle mainBundle] pathForResource:@"expression" ofType:@"grammar"]; | ||
self.grammar = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)dealloc { | ||
self.destinationPath = nil; | ||
self.parserName = nil; | ||
self.grammar = nil; | ||
|
||
self.textView = nil; | ||
|
||
self.factory = nil; | ||
self.root = nil; | ||
self.visitor = nil; | ||
[super dealloc]; | ||
} | ||
|
||
|
||
- (void)awakeFromNib { | ||
} | ||
|
||
|
||
#pragma mark - | ||
#pragma mark NSDocument | ||
|
||
- (NSString *)windowNibName { | ||
return @"PGDocument"; | ||
} | ||
|
||
|
||
- (void)windowControllerDidLoadNib:(NSWindowController *)wc { | ||
[super windowControllerDidLoadNib:wc]; | ||
|
||
[_textView setFont:[NSFont fontWithName:@"Monaco" size:12.0]]; | ||
} | ||
|
||
|
||
+ (BOOL)autosavesInPlace { | ||
return YES; | ||
} | ||
|
||
|
||
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError { | ||
NSAssert([[NSThread currentThread] isMainThread], @""); | ||
NSMutableDictionary *tab = [NSMutableDictionary dictionaryWithCapacity:9]; | ||
|
||
if (_destinationPath) tab[@"destinationPath"] = _destinationPath; | ||
if (_grammar) tab[@"grammar"] = _grammar; | ||
if (_parserName) tab[@"parserName"] = _parserName; | ||
tab[@"enableARC"] = @(_enableARC); | ||
tab[@"enableHybridDFA"] = @(_enableHybridDFA); | ||
tab[@"enableMemoization"] = @(_enableMemoization); | ||
tab[@"enableAutomaticErrorRecovery"] = @(_enableAutomaticErrorRecovery); | ||
tab[@"preassemblerSettingBehavior"] = @(_preassemblerSettingBehavior); | ||
tab[@"assemblerSettingBehavior"] = @(_assemblerSettingBehavior); | ||
|
||
//NSLog(@"%@", tab); | ||
|
||
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:tab]; | ||
return data; | ||
} | ||
|
||
|
||
- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError { | ||
NSAssert([[NSThread currentThread] isMainThread], @""); | ||
NSDictionary *tab = [NSKeyedUnarchiver unarchiveObjectWithData:data]; | ||
|
||
//NSLog(@"%@", tab); | ||
|
||
self.destinationPath = tab[@"destinationPath"]; | ||
self.grammar = tab[@"grammar"]; | ||
self.parserName = tab[@"parserName"]; | ||
self.enableARC = [tab[@"enableARC"] boolValue]; | ||
self.enableHybridDFA = [tab[@"enableHybridDFA"] boolValue]; | ||
self.enableMemoization = [tab[@"enableMemoization"] boolValue]; | ||
self.enableAutomaticErrorRecovery = [tab[@"enableAutomaticErrorRecovery"] boolValue]; | ||
self.preassemblerSettingBehavior = [tab[@"preassemblerSettingBehavior"] integerValue]; | ||
self.assemblerSettingBehavior = [tab[@"assemblerSettingBehavior"] integerValue]; | ||
|
||
return YES; | ||
} | ||
|
||
|
||
#pragma mark - | ||
#pragma mark Actions | ||
|
||
- (IBAction)generate:(id)sender { | ||
NSString *destPath = [[_destinationPath copy] autorelease]; | ||
NSString *parserName = [[_parserName copy] autorelease]; | ||
NSString *grammar = [[_grammar copy] autorelease]; | ||
|
||
if (![destPath length] || ![parserName length] || ![grammar length]) { | ||
NSBeep(); | ||
return; | ||
} | ||
|
||
self.busy = YES; | ||
|
||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | ||
[self generateWithDestinationPath:destPath parserName:parserName grammar:grammar]; | ||
}); | ||
} | ||
|
||
|
||
- (IBAction)browse:(id)sender { | ||
NSOpenPanel *panel = [NSOpenPanel openPanel]; | ||
NSWindow *win = [[[self windowControllers] lastObject] window]; | ||
|
||
NSString *path = nil; | ||
|
||
if (_destinationPath) { | ||
path = _destinationPath; | ||
|
||
BOOL isDir; | ||
if (![[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDir] || !isDir) { | ||
path = nil; | ||
} | ||
} | ||
|
||
if (path) { | ||
NSURL *pathURL = [NSURL fileURLWithPath:path]; | ||
[panel setDirectoryURL:pathURL]; | ||
} | ||
|
||
[panel setAllowsMultipleSelection:NO]; | ||
[panel setCanChooseDirectories:YES]; | ||
[panel setCanCreateDirectories:YES]; | ||
[panel setCanChooseFiles:NO]; | ||
|
||
[panel beginSheetModalForWindow:win completionHandler:^(NSInteger result) { | ||
if (NSOKButton == result) { | ||
NSString *path = [[panel URL] relativePath]; | ||
self.destinationPath = path; | ||
|
||
[self updateChangeCount:NSChangeDone]; | ||
} | ||
}]; | ||
} | ||
|
||
|
||
- (IBAction)reveal:(id)sender { | ||
NSString *path = _destinationPath; | ||
|
||
BOOL isDir; | ||
NSFileManager *mgr = [NSFileManager defaultManager]; | ||
while ([path length] && ![mgr fileExistsAtPath:path isDirectory:&isDir]) { | ||
path = [path stringByDeletingLastPathComponent]; | ||
} | ||
|
||
NSString *filename = self.parserName; | ||
if (![filename hasSuffix:@"Parser"]) { | ||
filename = [NSString stringWithFormat:@"%@Parser.m", filename]; | ||
} | ||
|
||
path = [path stringByAppendingPathComponent:filename]; | ||
|
||
if ([path length]) { | ||
[[NSWorkspace sharedWorkspace] selectFile:path inFileViewerRootedAtPath:nil]; | ||
} | ||
} | ||
|
||
|
||
#pragma mark - | ||
#pragma mark Private | ||
|
||
|
||
- (void)generateWithDestinationPath:(NSString *)destPath parserName:(NSString *)parserName grammar:(NSString *)grammar { | ||
NSError *err = nil; | ||
self.root = (id)[_factory ASTFromGrammar:_grammar error:&err]; | ||
|
||
NSString *className = self.parserName; | ||
if (![className hasSuffix:@"Parser"]) { | ||
className = [NSString stringWithFormat:@"%@Parser", className]; | ||
} | ||
|
||
_root.grammarName = className; | ||
|
||
self.visitor = [[[PKSParserGenVisitor alloc] init] autorelease]; | ||
_visitor.enableARC = _enableARC; | ||
_visitor.enableHybridDFA = _enableHybridDFA; NSAssert(_enableHybridDFA, @""); | ||
_visitor.enableMemoization = _enableMemoization; | ||
_visitor.enableAutomaticErrorRecovery = _enableAutomaticErrorRecovery; | ||
_visitor.preassemblerSettingBehavior = _preassemblerSettingBehavior; | ||
_visitor.assemblerSettingBehavior = _assemblerSettingBehavior; | ||
|
||
[_root visit:_visitor]; | ||
|
||
NSString *path = [[NSString stringWithFormat:@"%@/%@.h", destPath, className] stringByExpandingTildeInPath]; | ||
err = nil; | ||
if (![_visitor.interfaceOutputString writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:&err]) { | ||
NSLog(@"%@", err); | ||
} | ||
|
||
path = [[NSString stringWithFormat:@"%@/%@.m", destPath, className] stringByExpandingTildeInPath]; | ||
err = nil; | ||
if (![_visitor.implementationOutputString writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:&err]) { | ||
NSLog(@"%@", err); | ||
} | ||
|
||
dispatch_async(dispatch_get_main_queue(), ^(void){ | ||
[self done]; | ||
}); | ||
} | ||
|
||
|
||
- (void)done { | ||
[[NSSound soundNamed:@"Hero"] play]; | ||
|
||
self.busy = NO; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>en</string> | ||
<key>CFBundleDocumentTypes</key> | ||
<array> | ||
<dict> | ||
<key>CFBundleTypeExtensions</key> | ||
<array> | ||
<string>parsergen</string> | ||
</array> | ||
<key>CFBundleTypeIconFile</key> | ||
<string></string> | ||
<key>CFBundleTypeName</key> | ||
<string>DocumentType</string> | ||
<key>CFBundleTypeOSTypes</key> | ||
<array> | ||
<string>????</string> | ||
</array> | ||
<key>CFBundleTypeRole</key> | ||
<string>Editor</string> | ||
<key>NSDocumentClass</key> | ||
<string>PGDocument</string> | ||
</dict> | ||
</array> | ||
<key>CFBundleExecutable</key> | ||
<string>${EXECUTABLE_NAME}</string> | ||
<key>CFBundleIconFile</key> | ||
<string></string> | ||
<key>CFBundleIdentifier</key> | ||
<string>com.parsekit.${PRODUCT_NAME:rfc1034identifier}</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>${PRODUCT_NAME}</string> | ||
<key>CFBundlePackageType</key> | ||
<string>APPL</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleSignature</key> | ||
<string>????</string> | ||
<key>CFBundleVersion</key> | ||
<string>1</string> | ||
<key>LSMinimumSystemVersion</key> | ||
<string>${MACOSX_DEPLOYMENT_TARGET}</string> | ||
<key>NSMainNibFile</key> | ||
<string>MainMenu</string> | ||
<key>NSPrincipalClass</key> | ||
<string>NSApplication</string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// | ||
// Prefix header for all source files of the 'ParserGenApp' target in the 'ParserGenApp' project | ||
// | ||
|
||
#ifdef __OBJC__ | ||
#import <Cocoa/Cocoa.h> | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;} | ||
{\colortbl;\red255\green255\blue255;} | ||
\paperw9840\paperh8400 | ||
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural | ||
|
||
\f0\b\fs24 \cf0 Engineering: | ||
\b0 \ | ||
Some people\ | ||
\ | ||
|
||
\b Human Interface Design: | ||
\b0 \ | ||
Some other people\ | ||
\ | ||
|
||
\b Testing: | ||
\b0 \ | ||
Hopefully not nobody\ | ||
\ | ||
|
||
\b Documentation: | ||
\b0 \ | ||
Whoever\ | ||
\ | ||
|
||
\b With special thanks to: | ||
\b0 \ | ||
Mom\ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/* Localized versions of Info.plist keys */ | ||
|
Oops, something went wrong.