├── .gitignore ├── Cocoa Script.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ ├── cocoascript.xccheckout │ │ └── jstalk.xccheckout │ └── xcuserdata │ │ └── gus.xcuserdatad │ │ └── WorkspaceSettings.xcsettings ├── xcshareddata │ └── xcschemes │ │ └── Cocoa Script Framework.xcscheme └── xcuserdata │ └── gus.xcuserdatad │ └── xcschemes │ ├── Cocoa Script Editor.xcscheme │ ├── CocoaScript Framework.xcscheme │ ├── coscript tool.xcscheme │ └── xcschememanagement.plist ├── CocoaScriptTests ├── CSPropertyTests.m ├── Info.plist └── Model.xcdatamodeld │ └── Model.xcdatamodel │ └── contents ├── LICENSE ├── README.md ├── bin ├── cosbuild.sh └── cosmakebridgesupport.sh ├── examples ├── Automator and Acorn Action.jstalk ├── CIImage Color Wheel.jstalk ├── CIImage Masking.jstalk ├── COSAlertWindow Examples.coscript ├── COSGifAnimator.coscript ├── COSInterval.coscript ├── COSTarget - Copy Lorem Ipsum.coscript ├── Code Sketch - Newtime.jstalk ├── Code Sketcher Bezier.coscript ├── Code Sketcher Draw And Fade.coscript ├── Code Sketcher Draw.coscript ├── CommandLineArgs.coscript ├── Custom CIKernel.coscript ├── Help Me Write Code.coscript ├── Import Example.coscript ├── Messages set Status.coscript ├── NSImage Draw Buttons.jstalk ├── New Image In Acorn.coscript ├── OpenCL Desaturate.jstalk ├── OpenCL Simple Kernel.jstalk └── Routines.coscript ├── lib ├── bridgesupport │ ├── AppKit.bridgesupport │ ├── CocoaScript.bridgesupport │ ├── CoreGraphics.bridgesupport │ ├── CoreImage.bridgesupport │ ├── Foundation.bridgesupport │ └── QuartzCore.bridgesupport ├── libMultiMarkdown.a └── libMultiMarkdown.h ├── res ├── English.lproj │ ├── Credits.rtf │ ├── InfoPlist.strings │ ├── JSTDocument.xib │ └── MainMenu.xib ├── Info.plist ├── JSTalkFramework-Info.plist ├── JSTalkRunner-Info.plist ├── images │ ├── Clear.tiff │ ├── JSTalk.icns │ ├── JSTalk.png │ ├── JSTalk32.png │ ├── JSTalkDocument.icns │ ├── JSTalkStatusIcon.png │ ├── JSTalkStatusIconAlt.png │ ├── Play.tiff │ └── scriptimages │ │ ├── ccgus.jpg │ │ ├── clouds.jpg │ │ ├── duck.jpg │ │ ├── llama.jpg │ │ ├── mask1.jpg │ │ ├── mask2.jpg │ │ ├── mask3.jpg │ │ ├── mask4.png │ │ └── rail.jpg ├── jstalk_product_definition.plist ├── main.jstalk └── sample.jstalk └── src ├── cocoascript_tool.m ├── editor ├── JSTAppDelegate.h ├── JSTAppDelegate.m ├── JSTDocument.h ├── JSTDocument.m ├── JSTDocumentController.h ├── JSTDocumentController.m ├── JSTFileWatcher.h ├── JSTFileWatcher.m ├── JSTPluginMover.h ├── JSTPluginMover.m ├── JSTTextView.h ├── JSTTextView.m └── main.m └── framework ├── COSAlertWindow.h ├── COSAlertWindow.m ├── COSExtras.h ├── COSExtras.m ├── COSFiber.h ├── COSFiber.m ├── COSGifAnimator.h ├── COSGifAnimator.m ├── COSInterval.h ├── COSInterval.m ├── COSListener.h ├── COSListener.m ├── COSMarkdown.h ├── COSMarkdown.m ├── COSPreprocessor.h ├── COSPreprocessor.m ├── COSR.h ├── COSR.m ├── COSScript+Spelunking.h ├── COSScript+Spelunking.m ├── COSTarget.h ├── COSTarget.m ├── COScript+Fiber.h ├── COScript+Fiber.m ├── COScript+Interval.h ├── COScript+Interval.m ├── COScript.h ├── COScript.m ├── CocoaScript_Prefix.pch ├── MarkerLineNumberView.h ├── MarkerLineNumberView.m ├── NoodleLineNumberMarker.h ├── NoodleLineNumberMarker.m ├── NoodleLineNumberView.h ├── NoodleLineNumberView.m ├── TETextUtils.h ├── TETextUtils.m ├── fmdb ├── COSDatabase.h ├── COSDatabase.m ├── COSDatabaseAdditions.h ├── COSDatabaseAdditions.m ├── COSDatabaseQueue.h ├── COSDatabaseQueue.m ├── COSResultSet.h ├── COSResultSet.m ├── FMDB.bridgesupport └── makebs.sh ├── imagetools ├── COSCIImageAdditions.h ├── COSCIImageAdditions.m ├── COSCodeSketcher.h ├── COSCodeSketcher.m ├── COSImageTools.h ├── COSImageTools.m ├── COSOpenCLContext.h ├── COSOpenCLContext.m ├── COSOpenCLProgram.h ├── COSOpenCLProgram.m ├── COSQuickCIFilter.h └── COSQuickCIFilter.m ├── mocha ├── BridgeSupport │ ├── MOBridgeSupportController.h │ ├── MOBridgeSupportController.m │ ├── MOBridgeSupportLibrary.h │ ├── MOBridgeSupportLibrary.m │ ├── MOBridgeSupportParser.h │ ├── MOBridgeSupportParser.m │ ├── MOBridgeSupportSymbol.h │ └── MOBridgeSupportSymbol.m ├── Categories │ ├── NSArray+MochaAdditions.h │ ├── NSArray+MochaAdditions.m │ ├── NSDictionary+MochaAdditions.h │ ├── NSDictionary+MochaAdditions.m │ ├── NSObject+MochaAdditions.h │ ├── NSObject+MochaAdditions.m │ ├── NSOrderedSet+MochaAdditions.h │ └── NSOrderedSet+MochaAdditions.m ├── Mocha.h ├── Mocha.m ├── MochaDefines.h ├── MochaRuntime.h ├── MochaRuntime.m ├── MochaRuntime_Private.h ├── Objects │ ├── MOAllocator.h │ ├── MOAllocator.m │ ├── MOBox.h │ ├── MOBox.m │ ├── MOClassDescription.h │ ├── MOClassDescription.m │ ├── MOClosure.h │ ├── MOClosure.m │ ├── MOClosure_Private.h │ ├── MOInstanceVariableDescription.h │ ├── MOInstanceVariableDescription.m │ ├── MOInstanceVariableDescription_Private.h │ ├── MOJavaScriptObject.h │ ├── MOJavaScriptObject.m │ ├── MOMethod.h │ ├── MOMethod.m │ ├── MOMethodDescription.h │ ├── MOMethodDescription.m │ ├── MOMethodDescription_Private.h │ ├── MOMethod_Private.h │ ├── MOObjCRuntime.h │ ├── MOObjCRuntime.m │ ├── MOPointer.h │ ├── MOPointer.m │ ├── MOPointerValue.h │ ├── MOPointerValue.m │ ├── MOPointer_Private.h │ ├── MOPropertyDescription.h │ ├── MOPropertyDescription.m │ ├── MOProtocolDescription.h │ ├── MOProtocolDescription.m │ ├── MOProtocolDescription_Private.h │ ├── MOStruct.h │ ├── MOStruct.m │ ├── MOUndefined.h │ └── MOUndefined.m ├── Utilities │ ├── MOFunctionArgument.h │ ├── MOFunctionArgument.m │ ├── MOMapTable.h │ ├── MOMapTable.m │ ├── MOUtilities.h │ └── MOUtilities.m └── en.lproj │ └── InfoPlist.strings └── todparsekit ├── TDAlternation.h ├── TDAlternation.m ├── TDAny.h ├── TDAny.m ├── TDAssembly.h ├── TDAssembly.m ├── TDCaseInsensitiveLiteral.h ├── TDCaseInsensitiveLiteral.m ├── TDChar.h ├── TDChar.m ├── TDCharacterAssembly.h ├── TDCharacterAssembly.m ├── TDCollectionParser.h ├── TDCollectionParser.m ├── TDComment.h ├── TDComment.m ├── TDCommentState.h ├── TDCommentState.m ├── TDDigit.h ├── TDDigit.m ├── TDEmpty.h ├── TDEmpty.m ├── TDLetter.h ├── TDLetter.m ├── TDLiteral.h ├── TDLiteral.m ├── TDLowercaseWord.h ├── TDLowercaseWord.m ├── TDMultiLineCommentState.h ├── TDMultiLineCommentState.m ├── TDNonReservedWord.h ├── TDNonReservedWord.m ├── TDNum.h ├── TDNum.m ├── TDNumberState.h ├── TDNumberState.m ├── TDParseKit.h ├── TDParser.h ├── TDParser.m ├── TDQuoteState.h ├── TDQuoteState.m ├── TDQuotedString.h ├── TDQuotedString.m ├── TDReader.h ├── TDReader.m ├── TDRepetition.h ├── TDRepetition.m ├── TDReservedWord.h ├── TDReservedWord.m ├── TDScientificNumberState.h ├── TDScientificNumberState.m ├── TDSequence.h ├── TDSequence.m ├── TDSignificantWhitespaceState.h ├── TDSignificantWhitespaceState.m ├── TDSingleLineCommentState.h ├── TDSingleLineCommentState.m ├── TDSpecificChar.h ├── TDSpecificChar.m ├── TDSymbol.h ├── TDSymbol.m ├── TDSymbolNode.h ├── TDSymbolNode.m ├── TDSymbolRootNode.h ├── TDSymbolRootNode.m ├── TDSymbolState.h ├── TDSymbolState.m ├── TDTerminal.h ├── TDTerminal.m ├── TDToken.h ├── TDToken.m ├── TDTokenArraySource.h ├── TDTokenArraySource.m ├── TDTokenAssembly.h ├── TDTokenAssembly.m ├── TDTokenizer.h ├── TDTokenizer.m ├── TDTokenizerState.h ├── TDTokenizerState.m ├── TDTrack.h ├── TDTrack.m ├── TDTrackException.h ├── TDTrackException.m ├── TDUppercaseWord.h ├── TDUppercaseWord.m ├── TDWhitespaceState.h ├── TDWhitespaceState.m ├── TDWord.h ├── TDWord.m ├── TDWordOrReservedState.h ├── TDWordOrReservedState.m ├── TDWordState.h └── TDWordState.m /.gitignore: -------------------------------------------------------------------------------- 1 | # OS X 2 | .DS_Store 3 | 4 | # Xcode 5 | build/ 6 | *.pbxuser 7 | !default.pbxuser 8 | *.mode1v3 9 | !default.mode1v3 10 | *.mode2v3 11 | !default.mode2v3 12 | *.perspectivev3 13 | !default.perspectivev3 14 | xcuserdata 15 | *.xccheckout 16 | profile 17 | *.moved-aside 18 | DerivedData 19 | .idea/ 20 | *.hmap 21 | *.xccheckout 22 | *.xcuserstate 23 | Cocoa Script.xcodeproj/xcuserdata/* 24 | 25 | # CocoaPods 26 | Pods 27 | 28 | -------------------------------------------------------------------------------- /Cocoa Script.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Cocoa Script.xcodeproj/project.xcworkspace/xcshareddata/cocoascript.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | C613F324-5535-492E-A25A-C0B5A378ACC5 9 | IDESourceControlProjectName 10 | cocoascript 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | 3786B96F-E5DE-46A9-A7EC-F0690B31C8FF 14 | https://github.com/ccgus/CocoaScript 15 | 16 | IDESourceControlProjectPath 17 | cocoascript.xcodeproj/project.xcworkspace 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | 3786B96F-E5DE-46A9-A7EC-F0690B31C8FF 21 | ../.. 22 | 23 | IDESourceControlProjectURL 24 | https://github.com/ccgus/CocoaScript 25 | IDESourceControlProjectVersion 26 | 110 27 | IDESourceControlProjectWCCIdentifier 28 | 3786B96F-E5DE-46A9-A7EC-F0690B31C8FF 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | 3786B96F-E5DE-46A9-A7EC-F0690B31C8FF 36 | IDESourceControlWCCName 37 | cocoascript 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Cocoa Script.xcodeproj/project.xcworkspace/xcshareddata/jstalk.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectIdentifier 6 | 7C6852B7-5A62-4F33-8D95-6F14E6D9F6DA 7 | IDESourceControlProjectName 8 | jstalk 9 | IDESourceControlProjectOriginsDictionary 10 | 11 | 37FFC68B-82A3-4625-916D-B7C15D293305 12 | https://github.com/ccgus/jstalk 13 | 14 | IDESourceControlProjectPath 15 | jstalk.xcodeproj/project.xcworkspace 16 | IDESourceControlProjectRelativeInstallPathDictionary 17 | 18 | 37FFC68B-82A3-4625-916D-B7C15D293305 19 | ../.. 20 | 21 | IDESourceControlProjectURL 22 | https://github.com/ccgus/jstalk 23 | IDESourceControlProjectVersion 24 | 110 25 | IDESourceControlProjectWCCIdentifier 26 | 37FFC68B-82A3-4625-916D-B7C15D293305 27 | IDESourceControlProjectWCConfigurations 28 | 29 | 30 | IDESourceControlRepositoryExtensionIdentifierKey 31 | public.vcs.git 32 | IDESourceControlWCCIdentifierKey 33 | 37FFC68B-82A3-4625-916D-B7C15D293305 34 | IDESourceControlWCCName 35 | jstalk 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /Cocoa Script.xcodeproj/project.xcworkspace/xcuserdata/gus.xcuserdatad/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildLocationStyle 6 | UseAppPreferences 7 | CustomBuildLocationType 8 | RelativeToDerivedData 9 | DerivedDataLocationStyle 10 | Default 11 | HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges 12 | 13 | IssueFilterStyle 14 | ShowActiveSchemeOnly 15 | LiveSourceIssuesEnabled 16 | 17 | SnapshotAutomaticallyBeforeSignificantChanges 18 | 19 | SnapshotLocationStyle 20 | Default 21 | 22 | 23 | -------------------------------------------------------------------------------- /Cocoa Script.xcodeproj/xcuserdata/gus.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | Cocoa Script Editor.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | CocoaScript Framework.xcscheme 13 | 14 | orderHint 15 | 2 16 | 17 | coscript tool.xcscheme 18 | 19 | orderHint 20 | 1 21 | 22 | 23 | SuppressBuildableAutocreation 24 | 25 | 8D15AC270486D014006FF6A4 26 | 27 | primary 28 | 29 | 30 | CC4143190F25254200E46669 31 | 32 | primary 33 | 34 | 35 | CC5FB7C10F1FDCCC00F4ECC2 36 | 37 | primary 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /CocoaScriptTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.cocoascript.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /CocoaScriptTests/Model.xcdatamodeld/Model.xcdatamodel/contents: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Cocoa Script icon Copyright (c) 2013 Flying Meat Inc. 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2013 Flying Meat Inc. 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | this software and associated documentation files (the "Software"), to deal in 9 | the Software without restriction, including without limitation the rights to 10 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | the Software, and to permit persons to whom the Software is furnished to do so, 12 | subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Cocoa Script 2 | ============ 3 | 4 | JavaScript + the Cocoa frameworks, and then ObjC brackets show up to party as well. 5 | -------------------------------------------------------------------------------- /bin/cosmakebridgesupport.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | SRC_DIR=`cd ${0%/*}/..; pwd` 4 | # cd $SRC_DIR/src/framework/imagetools 5 | 6 | gen_bridge_metadata -c '-I. -I/Volumes/mp/Applications/Xcode6-Beta7.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/System/Library/Frameworks/Foundation.framework/Headers/ -I /Volumes/mp/Applications/Xcode6-Beta7.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include' src/framework/imagetools/COSImageTools.h -o CocoaScript.bridgesupport 7 | 8 | SDK='/Volumes/mp/Applications/Xcode6-Beta7.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk' 9 | 10 | #gen_bridge_metadata -c '-I. --framework Foundation -I /Volumes/mp/Applications/Xcode6-Beta7.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include' --framework /builds/Cocoa_Script-ffvatjthjqgjsfailwkikjdzqpdl/Build/Products/Debug/CocoaScript.framework -o CocoaScript.bridgesupport 11 | 12 | # gen_bridge_metadata -f /builds/Cocoa_Script-ffvatjthjqgjsfailwkikjdzqpdl/Build/Products/Debug/CocoaScript.framework -o CocoaScript.bridgesupport 13 | 14 | # gen_bridge_metadata -c -------------------------------------------------------------------------------- /examples/Automator and Acorn Action.jstalk: -------------------------------------------------------------------------------- 1 | // This goes in the JSTalk Automator Action 2 | 3 | function run(input, parameters) { 4 | var acorn = [JSTalk application:"Acorn"]; 5 | 6 | var idx = 0; 7 | 8 | while (idx < input.length()) { 9 | var filePath = input[idx]; 10 | var doc = [acorn open: filePath]; 11 | [doc scaleImageToHeight:200]; 12 | [[doc dataRepresentationOfType:"public.png"] writeToFile: filePath + ".png"]; 13 | [doc close]; 14 | idx++; 15 | } 16 | 17 | return input; 18 | } -------------------------------------------------------------------------------- /examples/CIImage Color Wheel.jstalk: -------------------------------------------------------------------------------- 1 | var filter = [COSQuickCIFilter quickFilterWithKernel:""" 2 | bool isOdd(int v) { 3 | float dividend = float(v) / 2.0; 4 | return dividend != floor(dividend); 5 | } 6 | 7 | vec4 hsvToRgb(vec4 hsv) { 8 | float h = hsv.r; 9 | float s = hsv.g; 10 | float v = hsv.b; 11 | int i = int(floor(h)); 12 | float f = isOdd(i) ? h - float(i) : 1.0 - (h - float(i)); 13 | float m = v * (1.0 - s); 14 | float n = v * (1.0 - s * f); 15 | vec4 result = (i == 0) ? vec4(v, n, m, hsv.a) : ((i == 1) ? 16 | vec4(n, v, m, hsv.a) : ((i == 2) ? vec4(m, v, n, hsv.a) : ((i == 3) ? 17 | vec4(m, n, v, hsv.a) : ((i == 4) ? vec4(n, m, v, hsv.a) : ((i == 5) ? 18 | vec4(v, m, n, hsv.a) : vec4(v, n, m, hsv.a)))))); 19 | 20 | return (h == -1.0) ? vec4(v, v, v, hsv.a) : result; 21 | } 22 | 23 | kernel vec4 colorWheel(float radius) { 24 | 25 | vec2 center = vec2(radius, radius); 26 | vec2 v0 = destCoord(); 27 | vec2 v1 = vec2(v0.x, radius); 28 | float a = distance(v0, v1); 29 | float b = distance(v1, center); 30 | 31 | float angle = atan(a,b); 32 | 33 | float pi = 3.14159265; 34 | angle = (v0.x>radius)?((v0.y>radius)? 35 | (atan(b,a)+pi/2.0):atan(a,b)+pi): 36 | (v0.y 5) { 18 | print("Canceling"); 19 | [cinterval cancel]; 20 | } 21 | 22 | }]; 23 | -------------------------------------------------------------------------------- /examples/Code Sketcher Draw And Fade.coscript: -------------------------------------------------------------------------------- 1 | /* 2 | This a sample on how to use the COSCodeSketcher class, which add experimental processing.org like functionality to Cocoa Script. 3 | */ 4 | 5 | coscript.shouldKeepAround = true; 6 | 7 | var sketcher = [COSCodeSketcher codeSketcherWithName:"Draw"]; 8 | 9 | sketcher.setup = function() { 10 | [sketcher setSize:NSMakeSize(600, 300)]; 11 | [sketcher clear]; 12 | }; 13 | 14 | sketcher.drawRect = function() { 15 | [sketcher fillWithColor:[NSColor colorWithCalibratedWhite:1 alpha:.01]]; 16 | } 17 | 18 | sketcher.mouseDown = function() { 19 | // reset our points 20 | m1 = m2 = m3 = m4 = null; 21 | }; 22 | 23 | sketcher.mouseDragged = function() { 24 | 25 | var m0 = [sketcher mouseLocation]; 26 | 27 | if (m4) { 28 | [[NSColor colorWithCalibratedWhite:0 alpha:.1] set]; 29 | 30 | [NSBezierPath strokeLineFromPoint:m0 toPoint:m4] 31 | [NSBezierPath strokeLineFromPoint:m1 toPoint:m4] 32 | [NSBezierPath strokeLineFromPoint:m2 toPoint:m4] 33 | [NSBezierPath strokeLineFromPoint:m3 toPoint:m4] 34 | } 35 | 36 | m4 = m3; 37 | m3 = m2; 38 | m2 = m1; 39 | m1 = m0; 40 | }; 41 | 42 | 43 | [sketcher setFrameRate:30] 44 | [sketcher start]; 45 | -------------------------------------------------------------------------------- /examples/Code Sketcher Draw.coscript: -------------------------------------------------------------------------------- 1 | /* 2 | This a sample on how to use the COSCodeSketcher class, which add experimental processing.org like functionality to Cocoa Script. 3 | */ 4 | 5 | coscript.env()['document'].setShouldCleanupAfterRun(false); 6 | 7 | var sketcher = [COSCodeSketcher codeSketcherWithName:"Draw"]; 8 | 9 | sketcher.setup = function() { 10 | [sketcher setSize:NSMakeSize(600, 300)]; 11 | [sketcher clear]; 12 | }; 13 | 14 | sketcher.mouseDown = function() { 15 | // reset our points 16 | m1 = m2 = m3 = m4 = null; 17 | }; 18 | 19 | sketcher.mouseDragged = function() { 20 | 21 | var m0 = [sketcher mouseLocation]; 22 | 23 | if (m4) { 24 | [[NSColor colorWithCalibratedWhite:0 alpha:.1] set]; 25 | 26 | [NSBezierPath strokeLineFromPoint:m0 toPoint:m4] 27 | [NSBezierPath strokeLineFromPoint:m1 toPoint:m4] 28 | [NSBezierPath strokeLineFromPoint:m2 toPoint:m4] 29 | [NSBezierPath strokeLineFromPoint:m3 toPoint:m4] 30 | } 31 | 32 | m4 = m3; 33 | m3 = m2; 34 | m2 = m1; 35 | m1 = m0; 36 | }; 37 | 38 | -------------------------------------------------------------------------------- /examples/CommandLineArgs.coscript: -------------------------------------------------------------------------------- 1 | var pi = [NSProcessInfo processInfo]; 2 | var argCount = [[pi arguments] count]; 3 | 4 | print("There are " + argCount + " args"); 5 | 6 | var idx = 0; 7 | while (idx < argCount) { 8 | 9 | print("argument " + idx + ": " + [pi arguments][idx]); 10 | 11 | idx++; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /examples/Custom CIKernel.coscript: -------------------------------------------------------------------------------- 1 | var filter = [COSQuickCIFilter quickFilterWithKernel:""" 2 | kernel vec4 mykernel(vec4 colorA, vec4 colorB) { 3 | vec2 dest = destCoord(); 4 | vec4 ret = dest.x < 100.0 ? colorA : colorB; 5 | return premultiply(ret); 6 | }"""]; 7 | 8 | [filter addKernelArgument:[CIColor colorWithString:"0.0 0.0 1.0 1.0"]]; 9 | [filter addKernelArgument:[CIColor colorWithString:"0.0 1.0 1.0 0.5"]]; 10 | 11 | var img = [filter outputImage]; 12 | 13 | [COSImageTools viewCIImage:img inWindowNamed:"test" extent:CGRectMake(0, 0, 400, 200)]; 14 | 15 | -------------------------------------------------------------------------------- /examples/Help Me Write Code.coscript: -------------------------------------------------------------------------------- 1 | var s = "break case catch continue default delete do else finally for function if in instanceof new return switch this throw try typeof var void while with abstract boolean byte char class const debugger double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile null true false nil"; 2 | 3 | words = s.split(" "); 4 | var i = 0; 5 | list = ""; 6 | words.forEach(function(element, index, array) { 7 | list = list + '@"' + element + '", '; 8 | }); 9 | 10 | print("NSArray *blueWords = [NSArray arrayWithObjects:" + list + " nil];"); 11 | 12 | -------------------------------------------------------------------------------- /examples/Import Example.coscript: -------------------------------------------------------------------------------- 1 | @import "Routines.coscript"; 2 | 3 | callAlert("Hello World"); 4 | -------------------------------------------------------------------------------- /examples/Messages set Status.coscript: -------------------------------------------------------------------------------- 1 | 2 | [[SBApplication application:"Messages"] setStatusMessage:"Happy (funball)"]; 3 | -------------------------------------------------------------------------------- /examples/New Image In Acorn.coscript: -------------------------------------------------------------------------------- 1 | var imageURL = [NSURL URLWithString:"http://flyingmeat.com/images/fmlogo.pdf"]; 2 | 3 | var image = [[NSImage alloc] initWithContentsOfURL:imageURL]; 4 | 5 | var acorn = [COScript application:"Acorn"]; 6 | 7 | [[acorn sharedDocumentController] newDocumentWithImageData:[image TIFFRepresentation]]; 8 | 9 | 10 | -------------------------------------------------------------------------------- /examples/OpenCL Desaturate.jstalk: -------------------------------------------------------------------------------- 1 | var src = """ 2 | 3 | __kernel void clDesaturate(read_write image2d_t src, read_write image2d_t dst, int width, int height) { 4 | 5 | int2 coord = (int2)(get_global_id(0), get_global_id(1)); 6 | 7 | if (coord.x >= width || coord.y >= height) { 8 | return; 9 | } 10 | 11 | float4 color = read_imagef(src, CLK_FILTER_NEAREST, coord); 12 | float lum = (0.30f * color.x + 0.59f * color.y + 0.11f * color.z); 13 | float4 val = (float4)(lum, lum, lum, color.w); 14 | 15 | write_imagef(dst, coord, val); 16 | } 17 | """; 18 | 19 | var context = [COSOpenCLContext new]; 20 | var program = [context programWithSource:src]; 21 | [program build]; 22 | 23 | var imagePath = [COSImageTools pathOfImageNamed:"llama"]; 24 | var kernel = [program createKernel:"clDesaturate"]; 25 | var inBuffer = [COSOpenCLImageBuffer instanceWithContext:context usingImageAtPath:imagePath]; 26 | var outBuffer = [COSOpenCLImageBuffer instanceWithContext:context width:[inBuffer width] height:[inBuffer height]]; 27 | 28 | [kernel setArgument:0 buffer:inBuffer]; 29 | [kernel setArgument:1 buffer:outBuffer]; 30 | [kernel setIntArgumentAtIndex:2 value:[inBuffer width]]; 31 | [kernel setIntArgumentAtIndex:3 value:[inBuffer height]]; 32 | 33 | [kernel enqueueCallWithGlobalSizeX:[inBuffer width] Y:[inBuffer height]]; 34 | [context finish]; 35 | 36 | [COSImageTools viewImageBuffer:outBuffer inWindowNamed:"OpenCL"]; 37 | -------------------------------------------------------------------------------- /examples/OpenCL Simple Kernel.jstalk: -------------------------------------------------------------------------------- 1 | var src = """ 2 | __kernel void test2(write_only image2d_t img) { 3 | int2 coord = (int2)(get_global_id(0), get_global_id(1)); 4 | float4 val = (float4)(1, 0, 0, 1); 5 | 6 | if (coord.x < 100) { 7 | val = (float4)(0, 0, 0, 1); 8 | } 9 | 10 | write_imagef(img, coord, val); 11 | }"""; 12 | 13 | var w = 400; 14 | var h = 400; 15 | 16 | var context = [COSOpenCLContext new]; 17 | var program = [context programWithSource:src]; 18 | [program build]; 19 | 20 | var kernel = [program createKernel:"test2"]; 21 | 22 | var buffer = [COSOpenCLImageBuffer instanceWithContext:context width:w height:h]; 23 | 24 | [kernel setArgument:0 buffer:buffer]; 25 | 26 | [kernel enqueueCallWithGlobalSizeX:w Y:h]; 27 | [context finish]; 28 | 29 | [COSImageTools viewImageBuffer:buffer inWindowNamed:"foo"]; 30 | -------------------------------------------------------------------------------- /examples/Routines.coscript: -------------------------------------------------------------------------------- 1 | 2 | function callAlert(v) { 3 | [NSApp displayDialog:v]; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /lib/bridgesupport/CocoaScript.bridgesupport: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /lib/libMultiMarkdown.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ccgus/CocoaScript/4541af546bf676fdec0805be8d2178474d4c9f87/lib/libMultiMarkdown.a -------------------------------------------------------------------------------- /res/English.lproj/Credits.rtf: -------------------------------------------------------------------------------- 1 | {\rtf1\ansi\ansicpg1252\cocoartf1038 2 | {\fonttbl\f0\fswiss\fcharset0 Helvetica;} 3 | {\colortbl;\red255\green255\blue255;} 4 | \vieww9000\viewh8400\viewkind0 5 | \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\qc 6 | 7 | \f0\b\fs24 \cf0 Special thanks to: 8 | \b0 \ 9 | Mom\ 10 | } -------------------------------------------------------------------------------- /res/English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ccgus/CocoaScript/4541af546bf676fdec0805be8d2178474d4c9f87/res/English.lproj/InfoPlist.strings -------------------------------------------------------------------------------- /res/JSTalkFramework-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.cocoascript.${PRODUCT_NAME:identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | FMWK 15 | CFBundleSignature 16 | ???? 17 | CFBundleVersion 18 | 1.0 19 | 20 | 21 | -------------------------------------------------------------------------------- /res/JSTalkRunner-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | org.jstalk.jstalkrunner.${PRODUCT_NAME:identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | APPL 15 | CFBundleSignature 16 | ???? 17 | CFBundleVersion 18 | 1.0 19 | NSPrincipalClass 20 | JSTRunnerApplication 21 | LSUIElement 22 | 23 | LSMinimumSystemVersion 24 | 10.5 25 | 26 | 27 | -------------------------------------------------------------------------------- /res/images/Clear.tiff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ccgus/CocoaScript/4541af546bf676fdec0805be8d2178474d4c9f87/res/images/Clear.tiff -------------------------------------------------------------------------------- /res/images/JSTalk.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ccgus/CocoaScript/4541af546bf676fdec0805be8d2178474d4c9f87/res/images/JSTalk.icns -------------------------------------------------------------------------------- /res/images/JSTalk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ccgus/CocoaScript/4541af546bf676fdec0805be8d2178474d4c9f87/res/images/JSTalk.png -------------------------------------------------------------------------------- /res/images/JSTalk32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ccgus/CocoaScript/4541af546bf676fdec0805be8d2178474d4c9f87/res/images/JSTalk32.png -------------------------------------------------------------------------------- /res/images/JSTalkDocument.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ccgus/CocoaScript/4541af546bf676fdec0805be8d2178474d4c9f87/res/images/JSTalkDocument.icns -------------------------------------------------------------------------------- /res/images/JSTalkStatusIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ccgus/CocoaScript/4541af546bf676fdec0805be8d2178474d4c9f87/res/images/JSTalkStatusIcon.png -------------------------------------------------------------------------------- /res/images/JSTalkStatusIconAlt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ccgus/CocoaScript/4541af546bf676fdec0805be8d2178474d4c9f87/res/images/JSTalkStatusIconAlt.png -------------------------------------------------------------------------------- /res/images/Play.tiff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ccgus/CocoaScript/4541af546bf676fdec0805be8d2178474d4c9f87/res/images/Play.tiff -------------------------------------------------------------------------------- /res/images/scriptimages/ccgus.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ccgus/CocoaScript/4541af546bf676fdec0805be8d2178474d4c9f87/res/images/scriptimages/ccgus.jpg -------------------------------------------------------------------------------- /res/images/scriptimages/clouds.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ccgus/CocoaScript/4541af546bf676fdec0805be8d2178474d4c9f87/res/images/scriptimages/clouds.jpg -------------------------------------------------------------------------------- /res/images/scriptimages/duck.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ccgus/CocoaScript/4541af546bf676fdec0805be8d2178474d4c9f87/res/images/scriptimages/duck.jpg -------------------------------------------------------------------------------- /res/images/scriptimages/llama.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ccgus/CocoaScript/4541af546bf676fdec0805be8d2178474d4c9f87/res/images/scriptimages/llama.jpg -------------------------------------------------------------------------------- /res/images/scriptimages/mask1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ccgus/CocoaScript/4541af546bf676fdec0805be8d2178474d4c9f87/res/images/scriptimages/mask1.jpg -------------------------------------------------------------------------------- /res/images/scriptimages/mask2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ccgus/CocoaScript/4541af546bf676fdec0805be8d2178474d4c9f87/res/images/scriptimages/mask2.jpg -------------------------------------------------------------------------------- /res/images/scriptimages/mask3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ccgus/CocoaScript/4541af546bf676fdec0805be8d2178474d4c9f87/res/images/scriptimages/mask3.jpg -------------------------------------------------------------------------------- /res/images/scriptimages/mask4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ccgus/CocoaScript/4541af546bf676fdec0805be8d2178474d4c9f87/res/images/scriptimages/mask4.png -------------------------------------------------------------------------------- /res/images/scriptimages/rail.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ccgus/CocoaScript/4541af546bf676fdec0805be8d2178474d4c9f87/res/images/scriptimages/rail.jpg -------------------------------------------------------------------------------- /res/jstalk_product_definition.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | arch 6 | 7 | i386 8 | x86_64 9 | 10 | home 11 | 12 | os 13 | 14 | 10.6.6 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /res/main.jstalk: -------------------------------------------------------------------------------- 1 | 2 | var alert = [NSAlert alertWithMessageText:"Hello World!" 3 | defaultButton:nil 4 | alternateButton:nil 5 | otherButton:nil 6 | informativeTextWithFormat:""]; 7 | 8 | [alert runModal]; 9 | -------------------------------------------------------------------------------- /res/sample.jstalk: -------------------------------------------------------------------------------- 1 | // "T" is a global dictionary, which is used to pass (serialized) values back and forth between apps. 2 | // We can pretend it stands for "transport" or something like that. Idealy, we could get rid of it. 3 | T.pngPath = "/tmp/bob.png"; 4 | 5 | // The code block for JTalk is sent to Acorn over a CFMessagePort, and it runs it in 6 | // it's own JavaScript instance, using the cocoa bridge. 7 | x = JSTalk("Acorn") { 8 | 9 | App.activate() 10 | 11 | // changing the variable, just to test that it gets sent back. 12 | T.pngPath = "/tmp/sam.png" 13 | 14 | doc = App.open("/Volumes/srv/Users/gus/Desktop/sortme/ridge.acorn"); 15 | 16 | doc.windowController().callFilterWithName("CIGaussianBlur") 17 | 18 | doc.dataOfType("public.png").writeToFile(T.pngPath); 19 | 20 | doc.undoManager().undo() 21 | 22 | //doc.close(); 23 | 24 | return true; 25 | } 26 | 27 | if (x) { 28 | // JSApp uses the scripting bridge, so all those apple events you have exposed can 29 | // be put to good use. 30 | QT = JSApp("QuickTime Player"); 31 | QT.open(T.pngPath) 32 | QT.activate() 33 | print("All done.") 34 | } 35 | else { 36 | print("Not a good response from Acorn..."); 37 | } 38 | 39 | // get rid of the image. 40 | jsc.system("rm " + T.pngPath); 41 | 42 | /* 43 | This would control iTunes... neat huh? 44 | iTunes = JSApp("iTunes"); 45 | iTunes.playpause(); 46 | */ -------------------------------------------------------------------------------- /src/cocoascript_tool.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import "COSListener.h" 3 | #import "COScript.h" 4 | 5 | BOOL JSCErrorHandlerExitOnError = YES; 6 | 7 | @interface JSCErrorHandler : NSObject { 8 | 9 | } 10 | @end 11 | 12 | @implementation JSCErrorHandler 13 | 14 | - (void)JSTalk:(COScript*)jstalk hadError:(NSString*)error onLineNumber:(NSInteger)lineNumber atSourceURL:(id)url { 15 | 16 | printf("Error line %d, %s\n", (int)lineNumber, [[error description] UTF8String]); 17 | 18 | if (JSCErrorHandlerExitOnError) { 19 | exit(1); 20 | } 21 | } 22 | 23 | 24 | @end 25 | 26 | 27 | void runREPL(COScript *t) { 28 | 29 | // thanks http://tlrobinson.net/blog/2008/10/10/command-line-interpreter-and-repl-for-jscocoa/ ! 30 | 31 | JSCErrorHandlerExitOnError = NO; 32 | 33 | while (1) { 34 | char buffer[1024]; 35 | 36 | printf("js> "); 37 | 38 | if (fgets(buffer, 1024, stdin) == NULL) { 39 | exit(0); 40 | } 41 | 42 | NSString *s = [[NSString alloc] initWithUTF8String:buffer]; 43 | 44 | id o = [t executeString:s]; 45 | 46 | if (o) { 47 | printf("%s\n", [[o description] UTF8String]); 48 | } 49 | 50 | } 51 | 52 | 53 | } 54 | 55 | 56 | int main(int argc, char *argv[]) { 57 | 58 | COScript *t = [[COScript alloc] init]; 59 | 60 | [t setErrorController:[[JSCErrorHandler alloc] init]]; 61 | 62 | if (argc < 2) { 63 | runREPL(t); 64 | exit(0); 65 | } 66 | 67 | 68 | NSString *source = nil; 69 | NSString *arg = [NSString stringWithUTF8String:argv[1]]; 70 | 71 | if ([arg isEqualToString:@"-e"] && argc == 3) { 72 | source = [NSString stringWithUTF8String:argv[2]]; 73 | } 74 | else { 75 | source = [NSString stringWithContentsOfFile:arg encoding:NSUTF8StringEncoding error:nil]; 76 | } 77 | 78 | 79 | if (!source) { 80 | printf("usage: %s \n", argv[0]); 81 | exit(0); 82 | } 83 | 84 | [t.env setObject:[NSURL fileURLWithPath:arg] forKey:@"scriptURL"]; 85 | 86 | if ([source hasPrefix:@"#!"]) { 87 | 88 | NSRange r = [source rangeOfString:@"\n"]; 89 | 90 | if (r.location != NSNotFound) { 91 | source = [source substringFromIndex:r.location]; 92 | } 93 | } 94 | 95 | id o = [t executeString:source]; 96 | 97 | if (o) { 98 | printf("%s\n", [[o description] UTF8String]); 99 | } 100 | 101 | return 0; 102 | } 103 | -------------------------------------------------------------------------------- /src/editor/JSTAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // JSTAppDelegate.h 3 | // jstalk 4 | // 5 | // Created by August Mueller on 1/14/09. 6 | // Copyright 2009 Flying Meat Inc. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface JSTAppDelegate : NSObject { 13 | IBOutlet NSPanel *prefsWindow; 14 | IBOutlet NSTextField *externalEditorField; 15 | IBOutlet NSTextField *prefsFontField; 16 | 17 | 18 | IBOutlet NSMenu *statusMenu; 19 | NSStatusItem *statusItem; 20 | NSString *_serviceError; 21 | } 22 | 23 | - (void)chooseExternalEditor:(id)sender; 24 | - (void)prefsChoosefont:(id)sender; 25 | 26 | - (NSFont*)defaultEditorFont; 27 | - (void)setDefaultEditorFont:(NSFont*)f; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /src/editor/JSTDocument.h: -------------------------------------------------------------------------------- 1 | // 2 | // JSTDocument.h 3 | // JSTalk 4 | // 5 | // Created by August Mueller on 1/14/09. 6 | // Copyright Flying Meat Inc 2009 . All rights reserved. 7 | // 8 | 9 | 10 | #import 11 | #import "JSTTextView.h" 12 | #import "JSTFileWatcher.h" 13 | 14 | @interface JSTDocument : NSDocument { 15 | IBOutlet JSTTextView *jsTextView; 16 | IBOutlet NSTextView *outputTextView; 17 | IBOutlet NSSplitView *splitView; 18 | IBOutlet NSTextField *errorLabel; 19 | 20 | //NoodleLineNumberView *lineNumberView; 21 | //TDTokenizer *_tokenizer; 22 | //NSDictionary *_keywords; 23 | 24 | NSMutableDictionary *_toolbarItems; 25 | 26 | JSTFileWatcher *_externalEditorFileWatcher; 27 | 28 | NSDictionary *_previousOutputTypingAttributes; 29 | } 30 | 31 | @property (retain) JSTFileWatcher *externalEditorFileWatcher; 32 | @property (retain) NSDictionary *previousOutputTypingAttributes; 33 | @property (assign) BOOL shouldCleanupAfterRun; 34 | 35 | - (void) executeScript:(id)sender; 36 | - (void) clearConsole:(id)sender; 37 | 38 | @end 39 | 40 | 41 | NSToolbarItem *JSTAddToolbarItem(NSMutableDictionary *theDict, 42 | NSString *identifier, 43 | NSString *label, 44 | NSString *paletteLabel, 45 | NSString *toolTip, 46 | id target, 47 | SEL settingSelector, 48 | id itemContent, 49 | SEL action, 50 | NSMenu * menu); 51 | 52 | -------------------------------------------------------------------------------- /src/editor/JSTDocumentController.h: -------------------------------------------------------------------------------- 1 | // 2 | // JSTDocumentController.h 3 | // jstalk 4 | // 5 | // Created by August Mueller on 8/15/10. 6 | // Copyright 2010 Flying Meat Inc. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface JSTDocumentController : NSDocumentController { 13 | 14 | } 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /src/editor/JSTDocumentController.m: -------------------------------------------------------------------------------- 1 | // 2 | // JSTDocumentController.m 3 | // jstalk 4 | // 5 | // Created by August Mueller on 8/15/10. 6 | // Copyright 2010 Flying Meat Inc. All rights reserved. 7 | // 8 | 9 | #import "JSTDocumentController.h" 10 | #import "JSTDocument.h" 11 | 12 | @implementation JSTDocumentController 13 | 14 | - (void)noteNewRecentDocument:(NSDocument *)document { 15 | if ([document isKindOfClass:[JSTDocument class]]) { 16 | [super noteNewRecentDocument:document]; 17 | } 18 | } 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /src/editor/JSTFileWatcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // JSTFileWatcher.h 3 | // jstalk 4 | // 5 | // Created by August Mueller on 3/15/09. 6 | // Copyright 2009 Flying Meat Inc. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface JSTFileWatcher : NSObject { 13 | 14 | FSEventStreamRef streamRef; 15 | } 16 | 17 | 18 | @property (weak) id delegate; 19 | @property (retain) NSString *path; 20 | 21 | + (id) fileWatcherWithPath:(NSString*)filePath delegate:(id)delegate; 22 | 23 | @end 24 | 25 | 26 | @interface NSObject (JSTFileWatcherDelegate) 27 | - (void) fileWatcherDidRecieveFSEvent:(JSTFileWatcher*)fw; 28 | @end 29 | -------------------------------------------------------------------------------- /src/editor/JSTFileWatcher.m: -------------------------------------------------------------------------------- 1 | // 2 | // JSTFileWatcher.m 3 | // jstalk 4 | // 5 | // Created by August Mueller on 3/15/09. 6 | // Copyright 2009 Flying Meat Inc. All rights reserved. 7 | // 8 | 9 | #import "JSTFileWatcher.h" 10 | 11 | @interface JSTFileWatcher (Private) 12 | - (void)setupEventStreamRef; 13 | @end 14 | 15 | 16 | 17 | @implementation JSTFileWatcher 18 | 19 | 20 | + (id) fileWatcherWithPath:(NSString*)filePath delegate:(id)delegate { 21 | 22 | JSTFileWatcher *fw = [self new]; 23 | 24 | fw.path = filePath; 25 | fw.delegate = delegate; 26 | 27 | [fw setupEventStreamRef]; 28 | 29 | return fw; 30 | } 31 | 32 | - (void)dealloc { 33 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 34 | 35 | if (streamRef) { 36 | FSEventStreamStop(streamRef); 37 | FSEventStreamInvalidate(streamRef); 38 | FSEventStreamRelease(streamRef); 39 | } 40 | 41 | } 42 | 43 | 44 | static void fsevents_callback(FSEventStreamRef streamRef, JSTFileWatcher *fw, int numEvents, const char *const eventPaths[], const FSEventStreamEventFlags *eventMasks, const uint64_t *eventIDs) 45 | { 46 | id delegate = [fw delegate]; 47 | 48 | if (delegate && [delegate respondsToSelector:@selector(fileWatcherDidRecieveFSEvent:)]) { 49 | [delegate fileWatcherDidRecieveFSEvent:fw]; 50 | } 51 | 52 | } 53 | 54 | - (void)setupEventStreamRef { 55 | 56 | FSEventStreamContext context = {0, (__bridge void *)self, NULL, NULL, NULL}; 57 | NSArray *pathsToWatch = [NSArray arrayWithObject:[_path stringByDeletingLastPathComponent]]; 58 | 59 | streamRef = FSEventStreamCreate(kCFAllocatorDefault, 60 | (FSEventStreamCallback)&fsevents_callback, 61 | &context, 62 | (CFArrayRef)CFBridgingRetain(pathsToWatch), 63 | kFSEventStreamEventIdSinceNow, 64 | 2, 65 | 0); 66 | 67 | FSEventStreamScheduleWithRunLoop(streamRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); 68 | 69 | FSEventStreamStart(streamRef); 70 | 71 | } 72 | 73 | @end 74 | 75 | -------------------------------------------------------------------------------- /src/editor/JSTPluginMover.h: -------------------------------------------------------------------------------- 1 | // 2 | // JSTPluginMover.h 3 | // jstalk 4 | // 5 | // Created by August Mueller on 8/15/10. 6 | // Copyright 2010 Flying Meat Inc. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface JSTPluginMover : NSDocument { 13 | 14 | } 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /src/editor/JSTTextView.h: -------------------------------------------------------------------------------- 1 | // 2 | // JSTTextView.h 3 | // jstalk 4 | // 5 | // Created by August Mueller on 1/18/09. 6 | // Copyright 2009 Flying Meat Inc. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class NoodleLineNumberView; 12 | 13 | typedef NS_ENUM(NSUInteger, JSTTextViewTheme) { 14 | JSTTextViewThemeLight = 0, 15 | JSTTextViewThemeDark, 16 | JSTTextViewThemeDefault = JSTTextViewThemeLight, 17 | }; 18 | 19 | typedef void (^JSTTextViewDragHandler)(NSTextView *draggedObject, NSString *draggedLine); 20 | 21 | @interface JSTTextView : NSTextView { 22 | NSDictionary *_keywords; 23 | NSString *_lastAutoInsert; 24 | NSSet *_ignoredSymbols; 25 | } 26 | 27 | 28 | @property (retain) NSDictionary *keywords; 29 | @property (retain) NSString *lastAutoInsert; 30 | @property (retain) NSSet *ignoredSymbols; 31 | @property (copy) JSTTextViewDragHandler numberDragHandler; // will be called continuously as a number is dragged 32 | 33 | - (void)parseCode:(id)sender; 34 | - (JSTTextViewTheme) theme; 35 | - (void)setTheme:(JSTTextViewTheme)theme; 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /src/editor/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // JSTalk 4 | // 5 | // Created by August Mueller on 1/14/09. 6 | // Copyright Flying Meat Inc 2009 . All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) { 12 | return NSApplicationMain(argc, (const char **) argv); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /src/framework/COSAlertWindow.h: -------------------------------------------------------------------------------- 1 | // 2 | // COSAlertWindow.h 3 | // Cocoa Script 4 | // 5 | // Created by August Mueller on 11/9/13. 6 | // 7 | // 8 | 9 | #import 10 | 11 | @interface COSAlertWindow : NSObject { 12 | 13 | 14 | } 15 | 16 | @property (strong) NSAlert *alert; 17 | 18 | - (void)addTextFieldWithValue:(NSString*)value; 19 | - (void)addAccessoryView:(NSView*)view; 20 | 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /src/framework/COSExtras.h: -------------------------------------------------------------------------------- 1 | 2 | #import 3 | 4 | 5 | @interface NSApplication (COSExtras) 6 | - (id)open:(NSString*)pathToFile; 7 | @end 8 | 9 | @interface NSString (JSTExtras) 10 | 11 | + (id)stringWithUUID; 12 | 13 | @end -------------------------------------------------------------------------------- /src/framework/COSFiber.h: -------------------------------------------------------------------------------- 1 | // 2 | // COSFiber.h 3 | // Cocoa Script 4 | // 5 | // Created by Mathieu Dutour on 12/04/17. 6 | // 7 | // 8 | 9 | #import 10 | 11 | #import "MOJavaScriptObject.h" 12 | #import 13 | 14 | @interface COSFiber : NSObject 15 | 16 | @property (weak) COScript *coscript; 17 | @property (strong) MOJavaScriptObject *cleanUpJSfunc; 18 | 19 | + (id)createWithCocoaScript:(COScript*)cos; 20 | - (void)onCleanup:(MOJavaScriptObject *)jsFunction; 21 | - (void)cleanup; 22 | 23 | @end 24 | 25 | -------------------------------------------------------------------------------- /src/framework/COSFiber.m: -------------------------------------------------------------------------------- 1 | // 2 | // COSFiber.m 3 | // Cocoa Script Editor 4 | // 5 | // Created by Mathieu Dutour on 04/12/2017. 6 | // 7 | 8 | #import "COSFiber.h" 9 | #import "COScript+Fiber.h" 10 | 11 | @implementation COSFiber 12 | + (id)createWithCocoaScript:(COScript *)cos { 13 | 14 | COSFiber *fiber = [[[self class] alloc] init]; 15 | 16 | [fiber setCoscript:cos]; 17 | 18 | return fiber; 19 | 20 | } 21 | 22 | - (void)onCleanup:(MOJavaScriptObject *)jsFunction { 23 | _cleanUpJSfunc = jsFunction; 24 | } 25 | 26 | - (void)cleanup { 27 | if (_cleanUpJSfunc != nil) { 28 | [_coscript callJSFunction:[_cleanUpJSfunc JSObject] withArgumentsInArray:@[]]; 29 | } 30 | 31 | [_coscript removeFiber:self]; 32 | 33 | _cleanUpJSfunc = nil; 34 | _coscript = nil; 35 | } 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /src/framework/COSGifAnimator.h: -------------------------------------------------------------------------------- 1 | // 2 | // COSGifAnimator.h 3 | // Cocoa Script 4 | // 5 | // Created by August Mueller on 6/1/14. 6 | // 7 | // 8 | 9 | #import 10 | #import 11 | #import "MOJavaScriptObject.h" 12 | 13 | @interface COSGifAnimator : NSObject { 14 | COScript *_jstalk; 15 | } 16 | 17 | 18 | @property (assign) CGFloat fps; 19 | @property (assign) CGFloat seconds; 20 | @property (assign) NSSize size; 21 | 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /src/framework/COSInterval.h: -------------------------------------------------------------------------------- 1 | // 2 | // COSInterval.h 3 | // Cocoa Script 4 | // 5 | // Created by August Mueller on 11/21/13. 6 | // 7 | // 8 | 9 | #import 10 | 11 | #import "MOJavaScriptObject.h" 12 | #import 13 | #import "COSFiber.h" 14 | 15 | @interface COSInterval : COSFiber { 16 | MOJavaScriptObject *_jsfunc; 17 | NSTimer *_timer; 18 | BOOL _onshot; 19 | } 20 | 21 | @property (strong) MOJavaScriptObject *jsfunc; 22 | 23 | + (id)scheduleWithInterval:(NSTimeInterval)i cocoaScript:(COScript*)cos jsFunction:(MOJavaScriptObject *)jsFunction repeat:(BOOL)repeat; 24 | - (void)cancel; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /src/framework/COSInterval.m: -------------------------------------------------------------------------------- 1 | // 2 | // COSInterval.m 3 | // Cocoa Script 4 | // 5 | // Created by August Mueller on 11/21/13. 6 | // 7 | // 8 | 9 | #import "COSInterval.h" 10 | #import "COSFiber.h" 11 | 12 | @implementation COSInterval 13 | 14 | + (id)scheduleWithInterval:(NSTimeInterval)i cocoaScript:(COScript*)cos jsFunction:(MOJavaScriptObject *)jsFunction repeat:(BOOL)repeat { 15 | 16 | COSInterval *interval = [COSInterval createWithCocoaScript: cos]; 17 | 18 | interval->_jsfunc = jsFunction; 19 | 20 | NSTimer *t = [NSTimer scheduledTimerWithTimeInterval:i target:interval selector:@selector(timerHit:) userInfo:nil repeats:repeat]; 21 | 22 | interval->_onshot = !repeat; 23 | 24 | interval->_timer = t; 25 | 26 | return interval; 27 | 28 | } 29 | 30 | - (void)dealloc { 31 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 32 | } 33 | 34 | - (void)cleanup { 35 | 36 | [super cleanup]; 37 | 38 | _jsfunc = nil; 39 | } 40 | 41 | - (void)cancel { 42 | [_timer invalidate]; 43 | _timer = nil; 44 | 45 | [self cleanup]; 46 | } 47 | 48 | - (void)timerHit:(NSTimer*)timer { 49 | 50 | [self.coscript callJSFunction:[_jsfunc JSObject] withArgumentsInArray:@[self]]; 51 | 52 | if (_onshot) { 53 | [self cancel]; 54 | } 55 | 56 | } 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /src/framework/COSListener.h: -------------------------------------------------------------------------------- 1 | // 2 | // JSTListener.h 3 | // jstalk 4 | // 5 | // Created by August Mueller on 1/14/09. 6 | // Copyright 2009 Flying Meat Inc. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface COSListener : NSObject { 13 | 14 | CFMessagePortRef messagePort; 15 | 16 | NSConnection *_conn; 17 | 18 | } 19 | 20 | @property (weak) id rootObject; 21 | 22 | + (COSListener*)sharedListener; 23 | 24 | + (void)listen; 25 | + (void)listenWithRootObject:(id)rootObject; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /src/framework/COSListener.m: -------------------------------------------------------------------------------- 1 | // 2 | // JSTListener.m 3 | // jstalk 4 | // 5 | // Created by August Mueller on 1/14/09. 6 | // Copyright 2009 Flying Meat Inc. All rights reserved. 7 | // 8 | 9 | #import "COSListener.h" 10 | 11 | @interface COSListener (Private) 12 | - (void)setupListener; 13 | @end 14 | 15 | 16 | @implementation COSListener 17 | 18 | + (id)sharedListener { 19 | static COSListener *me = nil; 20 | if (!me) { 21 | me = [[COSListener alloc] init]; 22 | } 23 | 24 | return me; 25 | } 26 | 27 | + (void)listen { 28 | [[self sharedListener] setupListener]; 29 | } 30 | 31 | + (void)listenWithRootObject:(id)rootObject; { 32 | ((COSListener*)[self sharedListener]).rootObject = rootObject; 33 | [self listen]; 34 | } 35 | 36 | 37 | - (void)setupListener { 38 | NSString *myBundleId = [[NSBundle mainBundle] bundleIdentifier]; 39 | NSString *port = [NSString stringWithFormat:@"%@.JSTalk", myBundleId]; 40 | 41 | _conn = [[NSConnection alloc] init]; 42 | // Pick your poision: 43 | // "Without Independent Conversation Queueing, your app will be re-entered during upon a 2nd remote DO call if you return to the run loop" 44 | // http://www.mac-developer-network.com/shows/podcasts/lnc/lnc020/ 45 | // "Because independent conversation queueing causes remote messages to block where they normally do not, it can cause deadlock to occur between applications." 46 | // http://developer.apple.com/documentation/Cocoa/Conceptual/DistrObjects/Tasks/configuring.html#//apple_ref/doc/uid/20000766 47 | // We'll go with ICQ for now. 48 | [_conn setIndependentConversationQueueing:YES]; 49 | [_conn setRootObject:_rootObject ? _rootObject : NSApp]; 50 | 51 | if ([_conn registerName:port]) { 52 | //NSLog(@"JSTalk listening on port %@", port); 53 | } 54 | else { 55 | NSLog(@"CocoaScript could not listen on port %@", port); 56 | _conn = nil; 57 | } 58 | } 59 | 60 | @end 61 | -------------------------------------------------------------------------------- /src/framework/COSMarkdown.h: -------------------------------------------------------------------------------- 1 | // 2 | // COSMarkdown.h 3 | // Cocoa Script 4 | // 5 | // Created by August Mueller on 7/25/14. 6 | // 7 | // 8 | 9 | #import 10 | 11 | @interface COSMarkdown : NSObject 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /src/framework/COSMarkdown.m: -------------------------------------------------------------------------------- 1 | // 2 | // COSMarkdown.m 3 | // Cocoa Script 4 | // 5 | // Created by August Mueller on 7/25/14. 6 | // 7 | // 8 | 9 | #import "COSMarkdown.h" 10 | #import "libMultiMarkdown.h" 11 | 12 | @implementation COSMarkdown 13 | 14 | 15 | 16 | + (NSString*)convertStringToMarkdown:(NSString*)s { 17 | return [self convertStringToMarkdown:s usingFlags:EXT_NOTES]; 18 | } 19 | 20 | + (NSString*)convertStringToMarkdown:(NSString*)s usingFlags:(unsigned long)flags { 21 | 22 | const char *c = [s cStringUsingEncoding:NSUTF8StringEncoding]; 23 | 24 | char *ret = markdown_to_string((char*)c, flags, HTML_FORMAT); 25 | 26 | return [NSString stringWithCString:ret encoding:NSUTF8StringEncoding]; 27 | 28 | } 29 | 30 | 31 | 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /src/framework/COSPreprocessor.h: -------------------------------------------------------------------------------- 1 | // 2 | // JSTPreprocessor.h 3 | // jstalk 4 | // 5 | // Created by August Mueller on 2/14/09. 6 | // Copyright 2009 Flying Meat Inc. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface COSPreprocessor : NSObject { 13 | 14 | } 15 | 16 | + (NSString*)preprocessCode:(NSString*)sourceString; 17 | 18 | + (NSString*)preprocessCode:(NSString*)sourceString withBaseURL:(NSURL*)base; 19 | 20 | @end 21 | 22 | 23 | 24 | @interface JSTPSymbolGroup : NSObject { 25 | 26 | unichar _openSymbol; 27 | NSMutableArray *_args; 28 | JSTPSymbolGroup *_parent; 29 | } 30 | 31 | @property (retain) NSMutableArray *args; 32 | @property (retain) JSTPSymbolGroup *parent; 33 | 34 | - (void)addSymbol:(id)aSymbol; 35 | 36 | @end 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/framework/COSR.h: -------------------------------------------------------------------------------- 1 | // 2 | // COSR.h 3 | // Cocoa Script 4 | // 5 | // Created by August Mueller on 6/24/14. 6 | // 7 | // 8 | 9 | #import 10 | 11 | @interface COSR : NSObject 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /src/framework/COSScript+Spelunking.h: -------------------------------------------------------------------------------- 1 | // 2 | // COSScript+Spelunking.h 3 | // Cocoa Script 4 | // 5 | // Created by August Mueller on 11/29/13. 6 | // 7 | // 8 | 9 | #import 10 | 11 | #import "COScript.h" 12 | 13 | @interface COScript (SpelunkingAdditions) 14 | 15 | + (BOOL)insertInMainMenu; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /src/framework/COSScript+Spelunking.m: -------------------------------------------------------------------------------- 1 | // 2 | // COSScript+Spelunking.m 3 | // Cocoa Script 4 | // 5 | // Created by August Mueller on 11/29/13. 6 | // 7 | // 8 | 9 | #import "COSScript+Spelunking.h" 10 | #import 11 | #import 12 | #import 13 | #include 14 | 15 | @interface CIContext (TSAdditions) { 16 | 17 | } 18 | 19 | @end 20 | 21 | @implementation CIContext (TSAdditions) 22 | 23 | - (id)tsinitWithCGContext:(struct CGContext *)arg1 options:(id)ops{ 24 | debug(@"%s:%d", __FUNCTION__, __LINE__); 25 | debug(@"ops: '%@'", ops); 26 | return [self tsinitWithCGContext:arg1 options:ops]; 27 | } 28 | 29 | - (void)tsdrawImage:(CIImage *)im inRect:(CGRect)dest fromRect:(CGRect)src { 30 | 31 | 32 | int viewport[4]; 33 | glGetIntegerv(GL_VIEWPORT, viewport); 34 | 35 | printf("----------------------------------\n"); 36 | debug(@"viewport: %d %d %d %d", viewport[0], viewport[1], viewport[2], viewport[3]); 37 | 38 | debug(@"im: '%@'", im); 39 | debug(@"dest: %@", NSStringFromRect(dest)); 40 | debug(@"src: %@", NSStringFromRect(src)); 41 | [self tsdrawImage:im inRect:dest fromRect:src]; 42 | } 43 | 44 | 45 | @end 46 | 47 | 48 | 49 | 50 | @implementation COScript (SpelunkingAdditions) 51 | 52 | + (BOOL)insertInMainMenu { 53 | 54 | NSMenu *mainMenu = [NSApp mainMenu]; 55 | 56 | NSMenuItem *mi = [[NSMenuItem alloc] init]; 57 | NSMenu *submenu = [[NSMenu alloc] initWithTitle:@"Cocoa Script"]; 58 | [mi setTitle:@"Cocoa Script"]; 59 | [mi setSubmenu:submenu]; 60 | 61 | // insert it before the Help menu. 62 | [mainMenu insertItem:mi atIndex:[[mainMenu itemArray] count] - 1]; 63 | 64 | NSMenuItem *sItem = [submenu addItemWithTitle:@"Spelunk" action:@selector(cosShowSpelunker:) keyEquivalent:@""]; 65 | 66 | [sItem setTarget:self]; 67 | 68 | return YES; 69 | } 70 | 71 | + (void)cosShowSpelunker:(id)sender { 72 | debug(@"%s:%d", __FUNCTION__, __LINE__); 73 | 74 | 75 | 76 | } 77 | 78 | + (void)cosLogCIContextDrawImageInRectFromRect { 79 | 80 | method_exchangeImplementations(class_getInstanceMethod([CIContext class], @selector(drawImage:inRect:fromRect:)), 81 | class_getInstanceMethod([CIContext class], @selector(tsdrawImage:inRect:fromRect:))); 82 | 83 | 84 | } 85 | 86 | @end 87 | -------------------------------------------------------------------------------- /src/framework/COSTarget.h: -------------------------------------------------------------------------------- 1 | // 2 | // COSTarget.h 3 | // Cocoa Script 4 | // 5 | // Created by Abhi Beckert on 13/11/2013. 6 | // 7 | // 8 | 9 | #import 10 | #import "MOJavaScriptObject.h" 11 | #import 12 | 13 | @interface COSTarget : NSObject 14 | 15 | @property (strong) MOJavaScriptObject *jsFunction; 16 | @property NSUInteger callCount; 17 | 18 | + (instancetype)targetWithJSFunction:(MOJavaScriptObject *)jsFunction; 19 | 20 | - (instancetype)initWithJSFunction:(MOJavaScriptObject *)jsFunction; 21 | 22 | - (void)callAction:(id)sender; 23 | 24 | - (SEL)action; 25 | 26 | @end 27 | 28 | @interface NSObject (COSTargetAdditions) 29 | 30 | - (void)setCOSJSTargetFunction:(MOJavaScriptObject *)jsFunction; 31 | 32 | @end 33 | 34 | -------------------------------------------------------------------------------- /src/framework/COSTarget.m: -------------------------------------------------------------------------------- 1 | // 2 | // COSTarget.m 3 | // Cocoa Script 4 | // 5 | // Created by Abhi Beckert on 13/11/2013. 6 | // 7 | // 8 | 9 | #import "COSTarget.h" 10 | #import 11 | 12 | @interface COSTarget () 13 | 14 | @property (weak) COScript *cosContext; 15 | @end 16 | 17 | @implementation COSTarget 18 | 19 | + (instancetype)targetWithJSFunction:(MOJavaScriptObject *)jsFunction { 20 | return [[[self class] alloc] initWithJSFunction:jsFunction]; 21 | } 22 | 23 | - (instancetype)initWithJSFunction:(MOJavaScriptObject *)jsFunction { 24 | self = [super init]; 25 | if (self != nil) { 26 | [self setJsFunction:jsFunction]; 27 | 28 | [self setCosContext:[COScript currentCOScript]]; 29 | 30 | } 31 | 32 | return self; 33 | } 34 | 35 | - (void)callAction:(id)sender { 36 | 37 | if (!_cosContext) { 38 | NSLog(@"%s:%d", __FUNCTION__, __LINE__); 39 | NSLog(@"_cosContext is nil when calling. Did it dealloc or was it never set?"); 40 | } 41 | 42 | JSObjectRef actionRef = [[self jsFunction] JSObject]; 43 | 44 | [_cosContext callJSFunction:actionRef withArgumentsInArray:@[sender]]; 45 | } 46 | 47 | - (SEL)action { 48 | return @selector(callAction:); 49 | } 50 | 51 | @end 52 | 53 | 54 | @implementation NSObject (COSTargetAdditions) 55 | 56 | - (void)setCOSJSTargetFunction:(MOJavaScriptObject *)jsFunction { 57 | 58 | if (!([self respondsToSelector:@selector(setTarget:)] && [self respondsToSelector:@selector(setAction:)])) { 59 | NSLog(@"Could not set the target and action on %@", self); 60 | return; 61 | } 62 | 63 | COSTarget *t = [COSTarget targetWithJSFunction:jsFunction]; 64 | 65 | [(id)self setTarget:t]; 66 | 67 | [(id)self setAction:[t action]]; 68 | 69 | objc_setAssociatedObject(self, _cmd, t, OBJC_ASSOCIATION_RETAIN); 70 | } 71 | 72 | @end 73 | -------------------------------------------------------------------------------- /src/framework/COScript+Fiber.h: -------------------------------------------------------------------------------- 1 | // 2 | // COScript+Fiber.h 3 | // Cocoa Script 4 | // 5 | // Created by Mathieu Dutour on 12/04/17. 6 | // 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @class COSFiber; 13 | 14 | @interface COScript (FiberAdditions) 15 | - (void)addFiber:(COSFiber*)fiber; 16 | - (void)cleanupFibers; 17 | - (void)removeFiber:(COSFiber*)fiber; 18 | @end 19 | 20 | -------------------------------------------------------------------------------- /src/framework/COScript+Fiber.m: -------------------------------------------------------------------------------- 1 | // 2 | // COScript+Fiber.m 3 | // Cocoa Script 4 | // 5 | // Created by Mathieu Dutour on 12/04/17. 6 | // 7 | // 8 | 9 | #import "COScript+Fiber.h" 10 | #import "COSFiber.h" 11 | 12 | @implementation COScript (FiberAdditions) 13 | 14 | - (void)addFiber:(COSFiber*)fiber { 15 | 16 | if (!_activeFibers) { 17 | _activeFibers = [NSMutableArray array]; 18 | } 19 | 20 | [_activeFibers addObject:fiber]; 21 | } 22 | 23 | - (void)cleanupFibers { 24 | for (COSFiber *fiber in _activeFibers) { 25 | [fiber cleanup]; 26 | } 27 | 28 | [_activeFibers removeAllObjects]; 29 | _activeFibers = nil; 30 | } 31 | 32 | - (void)removeFiber:(COSFiber*)fiber { 33 | 34 | if ([_activeFibers indexOfObject:fiber] == NSNotFound) { 35 | NSLog(@"Could not clean up fiber %@ because it is not in %@'s fiber stack.", fiber, self); 36 | return; 37 | } 38 | 39 | [_activeFibers removeObject:fiber]; 40 | } 41 | 42 | - (id)createFiber { 43 | 44 | COSFiber *fiber = [COSFiber createWithCocoaScript:self]; 45 | [self addFiber:fiber]; 46 | 47 | return fiber; 48 | } 49 | 50 | @end 51 | 52 | -------------------------------------------------------------------------------- /src/framework/COScript+Interval.h: -------------------------------------------------------------------------------- 1 | // 2 | // COScript+Interval.h 3 | // Cocoa Script 4 | // 5 | // Created by August Mueller on 11/21/13. 6 | // 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @class COSInterval; 13 | 14 | @interface COScript (IntervalAdditions) 15 | @end 16 | -------------------------------------------------------------------------------- /src/framework/COScript+Interval.m: -------------------------------------------------------------------------------- 1 | // 2 | // COScript+Interval.m 3 | // Cocoa Script 4 | // 5 | // Created by August Mueller on 11/21/13. 6 | // 7 | // 8 | 9 | #import "COScript+Interval.h" 10 | #import "COScript+Fiber.h" 11 | #import "COSInterval.h" 12 | 13 | @implementation COScript (IntervalAdditions) 14 | 15 | - (id)scheduleWithRepeatingInterval:(NSTimeInterval)i jsFunction:(MOJavaScriptObject *)jsFunction { 16 | 17 | COSInterval *cosi = [COSInterval scheduleWithInterval:i cocoaScript:self jsFunction:jsFunction repeat:YES]; 18 | [self addFiber:cosi]; 19 | 20 | return cosi; 21 | } 22 | 23 | - (id)scheduleWithInterval:(NSTimeInterval)i jsFunction:(MOJavaScriptObject *)jsFunction { 24 | 25 | COSInterval *cosi = [COSInterval scheduleWithInterval:i cocoaScript:self jsFunction:jsFunction repeat:NO]; 26 | [self addFiber:cosi]; 27 | 28 | return cosi; 29 | } 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /src/framework/COScript.h: -------------------------------------------------------------------------------- 1 | // 2 | // JSTalk.h 3 | // jstalk 4 | // 5 | // Created by August Mueller on 1/15/09. 6 | // Copyright 2009 Flying Meat Inc. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @class Mocha; 13 | @class COScript; 14 | 15 | 16 | @protocol CODebugController 17 | - (void)output:(NSString*)format args:(va_list)args; 18 | @end 19 | 20 | @interface COScript : NSObject { 21 | 22 | Mocha *_mochaRuntime; 23 | 24 | // used in COScript+Fiber 25 | NSMutableArray *_activeFibers; 26 | int _nextFiberId; 27 | } 28 | 29 | @property (weak) id printController; 30 | @property (weak) id errorController; 31 | @property (retain) NSMutableDictionary *env; 32 | @property (assign) BOOL shouldPreprocess; 33 | @property (assign) BOOL shouldKeepAround; 34 | 35 | - (void)cleanup; 36 | - (void)garbageCollect; 37 | - (id)executeString:(NSString*) str; 38 | - (id)executeString:(NSString*)str baseURL:(NSURL*)base; 39 | - (void)pushObject:(id)obj withName:(NSString*)name; 40 | - (void)deleteObjectWithName:(NSString*)name; 41 | - (void)print:(NSString*)s; 42 | - (BOOL)shouldKeepRunning; 43 | 44 | - (JSGlobalContextRef)context; 45 | - (id)callFunctionNamed:(NSString*)name withArguments:(NSArray*)args; 46 | - (BOOL)hasFunctionNamed:(NSString*)name; 47 | 48 | - (id)callJSFunction:(JSObjectRef)jsFunction withArgumentsInArray:(NSArray *)arguments; 49 | 50 | + (void)loadBridgeSupportFileAtURL:(NSURL*)url; 51 | + (void)listen; 52 | + (void)resetPlugins; 53 | + (void)loadPlugins; 54 | + (void)setShouldLoadJSTPlugins:(BOOL)b; 55 | + (id)application:(NSString*)app; 56 | + (id)app:(NSString*)app; 57 | + (COScript*)currentCOScript; 58 | 59 | + (id)setDebugController:(id)debugController; 60 | 61 | @end 62 | 63 | @interface NSObject (COScriptErrorControllerMethods) 64 | - (void)coscript:(id)coscript hadError:(NSString*)error onLineNumber:(NSInteger)lineNumber atSourceURL:(id)url; 65 | @end 66 | 67 | @interface JSTalk : COScript // compatibility 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /src/framework/CocoaScript_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'JSTalk' target in the 'JSTalk' project 3 | // 4 | 5 | //#define NS_BUILD_32_LIKE_64 1 6 | 7 | #ifdef __OBJC__ 8 | #import 9 | #endif 10 | 11 | #ifdef DEBUG 12 | extern void COScriptDebug(NSString* format, ...) NS_FORMAT_FUNCTION(1,2); 13 | #define debug COScriptDebug 14 | #else 15 | #define debug(...) 16 | #endif 17 | 18 | #define JSTPrefs [NSUserDefaults standardUserDefaults] 19 | -------------------------------------------------------------------------------- /src/framework/MarkerLineNumberView.h: -------------------------------------------------------------------------------- 1 | // 2 | // MarkerTextView.h 3 | // Line View Test 4 | // 5 | // Created by Paul Kim on 10/4/08. 6 | // Copyright (c) 2008 Noodlesoft, LLC. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import 31 | #import "NoodleLineNumberView.h" 32 | 33 | @interface MarkerLineNumberView : NoodleLineNumberView 34 | { 35 | NSImage *markerImage; 36 | } 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /src/framework/NoodleLineNumberMarker.h: -------------------------------------------------------------------------------- 1 | // 2 | // NoodleLineNumberMarker.h 3 | // Line View Test 4 | // 5 | // Created by Paul Kim on 9/30/08. 6 | // Copyright (c) 2008 Noodlesoft, LLC. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import 31 | 32 | 33 | @interface NoodleLineNumberMarker : NSRulerMarker 34 | { 35 | NSUInteger lineNumber; 36 | } 37 | 38 | - (id)initWithRulerView:(NSRulerView *)aRulerView lineNumber:(CGFloat)line image:(NSImage *)anImage imageOrigin:(NSPoint)imageOrigin; 39 | 40 | - (void)setLineNumber:(NSUInteger)line; 41 | - (NSUInteger)lineNumber; 42 | 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /src/framework/NoodleLineNumberView.h: -------------------------------------------------------------------------------- 1 | // 2 | // NoodleLineNumberView.h 3 | // Line View Test 4 | // 5 | // Created by Paul Kim on 9/28/08. 6 | // Copyright (c) 2008 Noodlesoft, LLC. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import 31 | 32 | @class NoodleLineNumberMarker; 33 | 34 | @interface NoodleLineNumberView : NSRulerView 35 | { 36 | // Array of character indices for the beginning of each line 37 | NSMutableArray *lineIndices; 38 | // Maps line numbers to markers 39 | NSMutableDictionary *linesToMarkers; 40 | NSFont *font; 41 | NSColor *textColor; 42 | NSColor *alternateTextColor; 43 | NSColor *backgroundColor; 44 | } 45 | 46 | - (id)initWithScrollView:(NSScrollView *)aScrollView; 47 | 48 | - (void)setFont:(NSFont *)aFont; 49 | - (NSFont *)font; 50 | 51 | - (void)setTextColor:(NSColor *)color; 52 | - (NSColor *)textColor; 53 | 54 | - (void)setAlternateTextColor:(NSColor *)color; 55 | - (NSColor *)alternateTextColor; 56 | 57 | - (void)setBackgroundColor:(NSColor *)color; 58 | - (NSColor *)backgroundColor; 59 | 60 | - (NSInteger)lineNumberForLocation:(CGFloat)location; 61 | - (NoodleLineNumberMarker *)markerAtLine:(NSUInteger)line; 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /src/framework/TETextUtils.h: -------------------------------------------------------------------------------- 1 | // TETextUtils.h 2 | // TextExtras 3 | // 4 | // Copyright © 1996-2006, Mike Ferris. 5 | // All rights reserved. 6 | 7 | #import 8 | 9 | // Identifying paragraph boundaries 10 | extern BOOL TE_IsParagraphSeparator(unichar uchar, NSString *str, unsigned index); 11 | extern BOOL TE_IsHardLineBreakUnichar(unichar uchar, NSString *str, unsigned index); 12 | 13 | // Space/Tab utilities 14 | extern unsigned TE_numberOfLeadingSpacesFromRangeInString(NSString *string, NSRange *range, unsigned tabWidth); 15 | extern NSString *TE_tabbifiedStringWithNumberOfSpaces(unsigned origNumSpaces, unsigned tabWidth, BOOL usesTabs); 16 | extern NSArray *TE_tabStopArrayForFontAndTabWidth(NSFont *font, unsigned tabWidth); 17 | 18 | extern NSRange TE_rangeOfLineWithLeadingWhiteSpace(NSString *string, NSRange startRange, unsigned leadingSpaces, NSComparisonResult matchStyle, BOOL backwardFlag, unsigned tabWidth); 19 | // Starting at the given startRange in string, this function locates the next (or previous) line whose leading whitespace is either smaller than, equal to or greater than the given leadingSpaces. NSOrderedAscending means greater than, NSOrderedDescending means smaller than. Return value is the range of the line whose leading space staisfies the match. 20 | 21 | // Nest/Unnest utilities 22 | extern NSAttributedString *TE_attributedStringByIndentingParagraphs(NSAttributedString *origString, int levels, NSRange *selRange, NSDictionary *defaultAttrs, unsigned tabWidth, unsigned indentWidth, BOOL usesTabs); 23 | 24 | // Brace matching utilities 25 | extern unichar TE_matchingDelimiter(unichar delimiter); 26 | extern BOOL TE_isOpeningBrace(unichar delimiter); 27 | extern BOOL TE_isClosingBrace(unichar delimiter); 28 | extern NSRange TE_findMatchingBraceForRangeInString(NSRange origRange, NSString *string); 29 | 30 | // Variable substitution 31 | 32 | extern unsigned TE_expandVariablesInString(NSMutableString *input, NSString *variableStart, NSString *variableEnd, id modalDelegate, SEL callbackSelector, void *context); 33 | // Variable references must begin with variableStart and end with variableEnd. There's no support for "escaping" the end string. 34 | // callbackSelector must have the following signature: 35 | // - (NSString *)expansionForVariableName:(NSString *)name inputString:(NSString *)input variableNameRange:(NSRange)nameRange fullVariableRange:(NSRange)fullRange context:(void *)context; 36 | // The return value of the callback is the replacement for the whole variable reference, or nil if the reference should be left unreplaced. 37 | // The return value of the funtion is the number of variables found and replaced. 38 | -------------------------------------------------------------------------------- /src/framework/fmdb/makebs.sh: -------------------------------------------------------------------------------- 1 | gen_bridge_metadata -c '-I.' *.h -o FMDB.bridgesupport -------------------------------------------------------------------------------- /src/framework/imagetools/COSCIImageAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // JSTCIImageAdditions.h 3 | // ImageTools 4 | // 5 | // Created by August Mueller on 4/3/11. 6 | // Copyright 2011 Flying Meat Inc. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface CIImage (COSCIImageAdditions) 13 | 14 | + (id)cosImageNamed:(NSString*)imageName; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /src/framework/imagetools/COSCIImageAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // JSTCIImageAdditions.m 3 | // ImageTools 4 | // 5 | // Created by August Mueller on 4/3/11. 6 | // Copyright 2011 Flying Meat Inc. All rights reserved. 7 | // 8 | 9 | #import "COSCIImageAdditions.h" 10 | #import "COSImageTools.h" 11 | 12 | @implementation CIImage (COSCIImageAdditions) 13 | 14 | + (id)jstImageNamed:(NSString*)imageName { 15 | return [self cosImageNamed:imageName]; 16 | } 17 | 18 | + (id)cosImageNamed:(NSString*)imageName { 19 | 20 | NSURL *url = [[NSBundle bundleForClass:[COSImageTools class]] URLForImageResource:imageName]; 21 | 22 | if (!url) { 23 | url = [[NSBundle mainBundle] URLForImageResource:imageName]; 24 | } 25 | 26 | if (!url) { 27 | return 0x00; 28 | } 29 | 30 | return [CIImage imageWithContentsOfURL:url]; 31 | 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /src/framework/imagetools/COSCodeSketcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // JSTCodeSketcher.h 3 | // ImageTools 4 | // 5 | // Created by August Mueller on 11/11/11. 6 | // Copyright (c) 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import 12 | 13 | @interface COSCodeSketcher : NSView { 14 | 15 | COScript *_jstalk; 16 | 17 | MOJavaScriptObject *_drawRect; 18 | MOJavaScriptObject *_setup; 19 | MOJavaScriptObject *_mouseMoved; 20 | MOJavaScriptObject *_mouseUp; 21 | MOJavaScriptObject *_mouseDown; 22 | MOJavaScriptObject *_mouseDragged; 23 | 24 | CGFloat _frameRate; 25 | 26 | NSWindow *_mwindow; 27 | 28 | BOOL _flipped; 29 | 30 | NSString *_lookupName; 31 | 32 | NSTimer *_redrawTimer; 33 | 34 | CGContextRef _context; 35 | NSGraphicsContext *_nsContext; 36 | 37 | // Processing type stuff. 38 | NSPoint _mouseLocation; 39 | NSPoint _pmouseLocation; 40 | BOOL _mousePressed; 41 | NSSize _size; 42 | 43 | 44 | } 45 | 46 | @property (assign) CGFloat frameRate; 47 | @property (retain) COScript *jstalk; 48 | @property (assign) NSPoint mouseLocation; 49 | @property (assign) NSPoint pmouseLocation; 50 | @property (assign, getter=isMousePressed) BOOL mousePressed; 51 | @property (retain) NSString *lookupName; 52 | @property (retain) NSGraphicsContext *nsContext; 53 | @property (assign) NSSize size; 54 | 55 | //@property (strong) MOJavaScriptObject *drawRect; 56 | @property (strong) MOJavaScriptObject *setup; 57 | @property (strong) MOJavaScriptObject *mouseMoved; 58 | @property (strong) MOJavaScriptObject *mouseUp; 59 | @property (strong) MOJavaScriptObject *mouseDown; 60 | @property (strong) MOJavaScriptObject *mouseDragged; 61 | 62 | - (void)stop; 63 | - (void)start; 64 | 65 | - (void)setDrawRect:(MOJavaScriptObject *)drawRect; 66 | 67 | 68 | @end 69 | 70 | 71 | @interface JSTFakePoint : NSObject { 72 | CGFloat _x; 73 | CGFloat _y; 74 | } 75 | @property (assign) CGFloat x; 76 | @property (assign) CGFloat y; 77 | @end 78 | 79 | @interface JSTFakeSize : NSObject { 80 | CGFloat _width; 81 | CGFloat _height; 82 | } 83 | @property (assign) CGFloat width; 84 | @property (assign) CGFloat height; 85 | @end 86 | 87 | 88 | @interface JSTFakeRect : NSObject { 89 | JSTFakePoint *_origin; 90 | JSTFakeSize *_size; 91 | } 92 | @property (retain) JSTFakePoint *origin; 93 | @property (retain) JSTFakeSize *size; 94 | + (id)rectWithRect:(NSRect)rect; 95 | @end 96 | 97 | CGColorRef JSTCGColorCreateFromNSColor(NSColor *c); 98 | -------------------------------------------------------------------------------- /src/framework/imagetools/COSImageTools.h: -------------------------------------------------------------------------------- 1 | // 2 | // JSTNSStringExtras.h 3 | // samplejstalkextra 4 | // 5 | // Created by August Mueller on 3/14/09. 6 | // Copyright 2009 Flying Meat Inc. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface COSImageTools : NSObject { 13 | 14 | } 15 | 16 | @end 17 | 18 | @interface JSTSimpleCIView : NSView { 19 | CIImage *_theImage; 20 | } 21 | 22 | @property (retain) CIImage *theImage; 23 | 24 | @end 25 | 26 | @interface NSImage (JSTExtras) 27 | + (id)imageWithSize:(NSSize)s; 28 | @end 29 | -------------------------------------------------------------------------------- /src/framework/imagetools/COSOpenCLContext.h: -------------------------------------------------------------------------------- 1 | // Originally Created by Guy English on 09-10-27. 2 | // Hacked to pieces by Gus Mueller on 2010-07-30 3 | 4 | #import 5 | #import 6 | 7 | @class COSOpenCLProgram; 8 | @class JSTOpenCLBuffer; 9 | 10 | @interface COSOpenCLContext : NSObject { 11 | 12 | cl_context computeContext; 13 | cl_command_queue computeCommands; 14 | cl_device_id computeDeviceId; 15 | cl_device_type computeDeviceType; 16 | } 17 | 18 | @property (readonly) cl_context computeContext; 19 | @property (readonly) cl_command_queue computeCommands; 20 | @property (readonly) cl_device_id computeDeviceId; 21 | @property (readonly) cl_device_type computeDeviceType; 22 | 23 | @property (readonly) NSUInteger maximumWorkItemDimensions; 24 | @property (readonly) NSArray *maximumWorkItemSizes; 25 | @property (readonly) NSUInteger maximum2DImageWidth; 26 | @property (readonly) NSUInteger maximum2DImageHeight; 27 | 28 | - (COSOpenCLProgram*)programWithSource:(NSString*)sourceCode; 29 | - (JSTOpenCLBuffer*)bufferWithSize:(size_t)size attributes:(cl_bitfield) attribs; 30 | - (JSTOpenCLBuffer*)bufferWithMemory:(void*)memory size:(size_t)size attributes:(cl_bitfield)attribs; 31 | 32 | - (void)finish; // waits until all processing has finished 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /src/framework/imagetools/COSQuickCIFilter.h: -------------------------------------------------------------------------------- 1 | // 2 | // JSTQuickCIFilter.h 3 | // CIOpenCLTools 4 | // 5 | // Created by August Mueller on 8/4/10. 6 | // Copyright 2010 Flying Meat Inc. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import 12 | #import 13 | 14 | @interface COSQuickCIFilter : CIFilter { 15 | CIKernel *_theKernel; 16 | NSMutableArray *_kernelArgs; 17 | } 18 | 19 | @property (strong) CIFilterShape *applyDefinitionShape; 20 | @property (retain) CIKernel *theKernel; 21 | @property (retain) NSMutableArray *kernelArgs; 22 | 23 | @property (strong) MOJavaScriptObject *roiMethod; 24 | @property (strong) MOJavaScriptObject *outputImageMethod; 25 | 26 | @end 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/framework/mocha/BridgeSupport/MOBridgeSupportController.h: -------------------------------------------------------------------------------- 1 | // 2 | // MOBridgeSupportController.h 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/11/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @class MOBridgeSupportSymbol; 13 | 14 | 15 | @interface MOBridgeSupportController : NSObject 16 | 17 | + (MOBridgeSupportController *)sharedController; 18 | 19 | - (BOOL)isBridgeSupportLoadedForURL:(NSURL *)aURL; 20 | - (BOOL)loadBridgeSupportAtURL:(NSURL *)aURL error:(NSError **)outError; 21 | 22 | @property (copy, readonly) NSDictionary *symbols; 23 | - (NSDictionary *)performQueryForSymbolsOfType:(NSArray *)classes; 24 | 25 | - (id)performQueryForSymbolName:(NSString *)name; 26 | - (id)performQueryForSymbolName:(NSString *)name ofType:(Class)klass; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /src/framework/mocha/BridgeSupport/MOBridgeSupportLibrary.h: -------------------------------------------------------------------------------- 1 | // 2 | // MOBridgeSupportLibrary.h 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/11/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @class MOBridgeSupportSymbol; 13 | 14 | 15 | @interface MOBridgeSupportLibrary : NSObject 16 | 17 | @property (copy) NSString *name; 18 | @property (copy) NSURL *URL; 19 | 20 | @property (copy) NSArray *dependencies; 21 | - (void)addDependency:(NSString *)dependency; 22 | - (void)removeDependency:(NSString *)dependency; 23 | 24 | @property (copy) NSDictionary *symbols; 25 | - (MOBridgeSupportSymbol *)symbolWithName:(NSString *)name; 26 | - (void)setSymbol:(MOBridgeSupportSymbol *)symbol forName:(NSString *)name; 27 | - (void)removeSymbolForName:(NSString *)name; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /src/framework/mocha/BridgeSupport/MOBridgeSupportLibrary.m: -------------------------------------------------------------------------------- 1 | // 2 | // MOBridgeSupportLibrary.m 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/11/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import "MOBridgeSupportLibrary.h" 10 | 11 | 12 | @implementation MOBridgeSupportLibrary { 13 | NSMutableArray *_dependencies; 14 | NSMutableDictionary *_symbols; 15 | } 16 | 17 | @synthesize name=_name; 18 | @synthesize URL=_URL; 19 | 20 | - (id)init { 21 | self = [super init]; 22 | if (self) { 23 | _dependencies = [[NSMutableArray alloc] init]; 24 | _symbols = [[NSMutableDictionary alloc] init]; 25 | } 26 | return self; 27 | } 28 | 29 | 30 | #pragma mark - 31 | #pragma mark Dependencies 32 | 33 | - (NSArray *)dependencies { 34 | return _dependencies; 35 | } 36 | 37 | - (void)setDependencies:(NSArray *)dependencies { 38 | [_dependencies setArray:dependencies]; 39 | } 40 | 41 | - (void)addDependency:(NSString *)dependency { 42 | if (![_dependencies containsObject:dependency]) { 43 | [_dependencies addObject:dependency]; 44 | } 45 | } 46 | 47 | - (void)removeDependency:(NSString *)dependency { 48 | if ([_dependencies containsObject:dependency]) { 49 | [_dependencies removeObject:dependency]; 50 | } 51 | } 52 | 53 | 54 | #pragma mark - 55 | #pragma mark Symbols 56 | 57 | - (NSDictionary *)symbols { 58 | return _symbols; 59 | } 60 | 61 | - (void)setSymbols:(NSDictionary *)symbols { 62 | [_symbols setDictionary:symbols]; 63 | } 64 | 65 | - (MOBridgeSupportSymbol *)symbolWithName:(NSString *)name { 66 | return [_symbols objectForKey:name]; 67 | } 68 | 69 | - (void)setSymbol:(MOBridgeSupportSymbol *)symbol forName:(NSString *)name { 70 | [_symbols setObject:symbol forKey:name]; 71 | } 72 | 73 | - (void)removeSymbolForName:(NSString *)name { 74 | [_symbols removeObjectForKey:name]; 75 | } 76 | 77 | @end 78 | -------------------------------------------------------------------------------- /src/framework/mocha/BridgeSupport/MOBridgeSupportParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // MOBridgeSupportParser.h 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/11/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @class MOBridgeSupportLibrary; 13 | 14 | 15 | @interface MOBridgeSupportParser : NSObject 16 | 17 | - (MOBridgeSupportLibrary *)libraryWithBridgeSupportURL:(NSURL *)aURL error:(NSError **)outError; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /src/framework/mocha/Categories/NSArray+MochaAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+MochaAdditions.h 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/12/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface NSArray (MochaAdditions) 13 | 14 | - (id)mo_objectForIndexedSubscript:(NSUInteger)idx; 15 | 16 | @end 17 | 18 | 19 | @interface NSMutableArray (MochaAdditions) 20 | 21 | - (void)mo_setObject:(id)obj forIndexedSubscript:(NSUInteger)idx; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /src/framework/mocha/Categories/NSArray+MochaAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+MochaAdditions.m 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/12/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import "NSArray+MochaAdditions.h" 10 | 11 | 12 | @implementation NSArray (MochaAdditions) 13 | 14 | - (id)mo_objectForIndexedSubscript:(NSUInteger)idx { 15 | return [self objectAtIndex:idx]; 16 | } 17 | 18 | @end 19 | 20 | 21 | @implementation NSMutableArray (MochaAdditions) 22 | 23 | - (void)mo_setObject:(id)obj forIndexedSubscript:(NSUInteger)idx { 24 | if ([self count] > idx && obj != nil) { 25 | [self replaceObjectAtIndex:idx withObject:obj]; 26 | } 27 | else if ([self count] == idx && obj != nil) { 28 | [self addObject:obj]; 29 | } 30 | else if (obj == nil) { 31 | [self removeObjectAtIndex:idx]; 32 | } 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /src/framework/mocha/Categories/NSDictionary+MochaAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSDictionary+MochaAdditions.h 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/12/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface NSDictionary (MochaAdditions) 13 | 14 | - (id)mo_objectForKeyedSubscript:(id)key; 15 | 16 | @end 17 | 18 | 19 | @interface NSMutableDictionary (MochaAdditions) 20 | 21 | - (void)mo_setObject:(id)obj forKeyedSubscript:(id )key; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /src/framework/mocha/Categories/NSDictionary+MochaAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSDictionary+MochaAdditions.m 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/12/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import "NSDictionary+MochaAdditions.h" 10 | 11 | 12 | @implementation NSDictionary (MochaAdditions) 13 | 14 | - (id)mo_objectForKeyedSubscript:(id)key { 15 | return [self objectForKey:key]; 16 | } 17 | 18 | @end 19 | 20 | 21 | @implementation NSMutableDictionary (MochaAdditions) 22 | 23 | - (void)mo_setObject:(id)obj forKeyedSubscript:(id )key { 24 | if (obj != nil) { 25 | [self setObject:obj forKey:key]; 26 | } 27 | else { 28 | [self removeObjectForKey:key]; 29 | } 30 | } 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /src/framework/mocha/Categories/NSObject+MochaAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+MochaAdditions.h 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/17/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @class MOClassDescription; 13 | 14 | 15 | @interface NSObject (MochaAdditions) 16 | 17 | + (void)mo_swizzleAdditions; 18 | 19 | + (MOClassDescription *)mo_mocha; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /src/framework/mocha/Categories/NSObject+MochaAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+MochaAdditions.m 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/17/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import "NSObject+MochaAdditions.h" 10 | 11 | #import "MOClassDescription.h" 12 | 13 | #import 14 | 15 | @interface NSObject(DeclaredToKeepTheCompilerHappy) 16 | + (MOClassDescription *)mocha; 17 | @end 18 | 19 | @implementation NSObject (MochaAdditions) 20 | 21 | + (void)mo_swizzleAdditions { 22 | Class metaClass = object_getClass(self); 23 | 24 | SEL classDescriptionSelector = @selector(mocha); 25 | if (!class_respondsToSelector(self, classDescriptionSelector)) { 26 | IMP imp = class_getMethodImplementation(metaClass, @selector(mo_mocha)); 27 | class_addMethod(metaClass, classDescriptionSelector, imp, "@@:"); 28 | } 29 | } 30 | 31 | + (MOClassDescription *)mo_mocha { 32 | return [MOClassDescription descriptionForClass:self]; 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /src/framework/mocha/Categories/NSOrderedSet+MochaAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSOrderedSet+MochaAdditions.h 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/17/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface NSOrderedSet (MochaAdditions) 13 | 14 | - (id)mo_objectForIndexedSubscript:(NSUInteger)idx; 15 | 16 | @end 17 | 18 | 19 | @interface NSMutableOrderedSet (MochaAdditions) 20 | 21 | - (void)mo_setObject:(id)obj forIndexedSubscript:(NSUInteger)idx; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /src/framework/mocha/Categories/NSOrderedSet+MochaAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSOrderedSet+MochaAdditions.m 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/17/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import "NSOrderedSet+MochaAdditions.h" 10 | 11 | 12 | @implementation NSOrderedSet (MochaAdditions) 13 | 14 | - (id)mo_objectForIndexedSubscript:(NSUInteger)idx { 15 | return [self objectAtIndex:idx]; 16 | } 17 | 18 | @end 19 | 20 | 21 | @implementation NSMutableOrderedSet (MochaAdditions) 22 | 23 | - (void)mo_setObject:(id)obj forIndexedSubscript:(NSUInteger)idx { 24 | if ([self count] > idx && obj != nil) { 25 | [self replaceObjectAtIndex:idx withObject:obj]; 26 | } 27 | else if ([self count] == idx && obj != nil) { 28 | [self addObject:obj]; 29 | } 30 | else if (obj == nil) { 31 | [self removeObjectAtIndex:idx]; 32 | } 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /src/framework/mocha/Mocha.h: -------------------------------------------------------------------------------- 1 | // 2 | // Mocha.h 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/10/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import "MochaDefines.h" 10 | #import "MochaRuntime.h" 11 | #import "MOMethod.h" 12 | #import "MOPointer.h" 13 | #import "MOUndefined.h" 14 | 15 | #import "MOClassDescription.h" 16 | #import "MOInstanceVariableDescription.h" 17 | #import "MOMethodDescription.h" 18 | #import "MOPropertyDescription.h" 19 | #import "MOProtocolDescription.h" 20 | -------------------------------------------------------------------------------- /src/framework/mocha/Mocha.m: -------------------------------------------------------------------------------- 1 | // 2 | // Mocha.m 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/10/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import "Mocha.h" 10 | 11 | -------------------------------------------------------------------------------- /src/framework/mocha/MochaDefines.h: -------------------------------------------------------------------------------- 1 | // 2 | // MochaDefines.h 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/10/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | 10 | #define MOCHA_EXTERN extern __attribute__((visibility("default"))) 11 | #define MOCHA_INLINE static inline __attribute__((visibility("default"))) 12 | 13 | #if (__has_feature(objc_fixed_enum)) 14 | #define MOCHA_ENUM(_type, _name) enum _name : _type _name; enum _name : _type 15 | #define MOCHA_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type 16 | #else 17 | #define MOCHA_ENUM(_type, _name) _type _name; enum 18 | #define MOCHA_OPTIONS(_type, _name) _type _name; enum 19 | #endif 20 | -------------------------------------------------------------------------------- /src/framework/mocha/MochaRuntime_Private.h: -------------------------------------------------------------------------------- 1 | // 2 | // MochaRuntime_Private.h 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/10/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import "MochaRuntime.h" 10 | 11 | 12 | 13 | @interface Mocha () 14 | 15 | + (Mocha *)runtimeWithContext:(JSContextRef)ctx; 16 | 17 | - (id)initWithGlobalContext:(JSGlobalContextRef)ctx; 18 | 19 | @property (readonly) JSGlobalContextRef context; 20 | 21 | // JSValue <-> id 22 | + (JSValueRef)JSValueForObject:(id)object inContext:(JSContextRef)ctx; 23 | 24 | + (id)objectForJSValue:(JSValueRef)value inContext:(JSContextRef)ctx; 25 | + (id)objectForJSValue:(JSValueRef)value inContext:(JSContextRef)ctx unboxObjects:(BOOL)unboxObjects; 26 | 27 | + (NSArray *)arrayForJSArray:(JSObjectRef)arrayValue inContext:(JSContextRef)ctx; 28 | + (NSDictionary *)dictionaryForJSHash:(JSObjectRef)hashValue inContext:(JSContextRef)ctx; 29 | 30 | - (JSValueRef)JSValueForObject:(id)object; 31 | 32 | - (id)objectForJSValue:(JSValueRef)value; 33 | - (id)objectForJSValue:(JSValueRef)value unboxObjects:(BOOL)unboxObjects; 34 | 35 | // JSObject <-> id 36 | - (JSObjectRef)boxedJSObjectForObject:(id)object; 37 | - (id)unboxedObjectForJSObject:(JSObjectRef)jsObject; 38 | 39 | // Object storage 40 | - (id)objectWithName:(NSString *)name; 41 | - (JSValueRef)setObject:(id)object withName:(NSString *)name; 42 | - (JSValueRef)setObject:(id)object withName:(NSString *)name attributes:(JSPropertyAttributes)attributes; 43 | - (BOOL)removeObjectWithName:(NSString *)name; 44 | 45 | // Evaluation 46 | - (JSValueRef)evalJSString:(NSString *)string; 47 | - (JSValueRef)evalJSString:(NSString *)string scriptPath:(NSString *)scriptPath; 48 | 49 | // Functions 50 | - (JSObjectRef)JSFunctionWithName:(NSString *)functionName; 51 | - (JSValueRef)callJSFunctionWithName:(NSString *)functionName withArgumentsInArray:(NSArray *)arguments; 52 | - (JSValueRef)callJSFunction:(JSObjectRef)jsFunction withArgumentsInArray:(NSArray *)arguments; 53 | 54 | // Exceptions 55 | + (NSException *)exceptionWithJSException:(JSValueRef)exception context:(JSContextRef)ctx; 56 | - (NSException *)exceptionWithJSException:(JSValueRef)exception; 57 | - (void)throwJSException:(JSValueRef)exception; 58 | 59 | // Support 60 | - (void)installBuiltins; 61 | - (void)cleanUp; 62 | //- (void)unlinkAllReferences; 63 | 64 | @end 65 | -------------------------------------------------------------------------------- /src/framework/mocha/Objects/MOAllocator.h: -------------------------------------------------------------------------------- 1 | // 2 | // MOAllocator.h 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 7/25/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | /*! 13 | * @class MOAllocator 14 | * @abstract A proxy used to represent the result of -alloc. 15 | * 16 | * @discussion 17 | * Some Cocoa classes do not play well when the result of -alloc 18 | * is sent messages other than an initializer. As such, this object 19 | * serves as a proxy to delay allocation of the object until it is sent 20 | * its initialization message. 21 | * 22 | * Any unimplemented message sent to this class will be forwarded to 23 | * the target object class. This will always be something along the lines 24 | * of -init or -initWith*: 25 | */ 26 | @interface MOAllocator : NSObject 27 | 28 | /*! 29 | * @method allocator 30 | * @abstract Creates a new allocator 31 | * 32 | * @result An MOAllocator object 33 | */ 34 | + (MOAllocator *)allocator; 35 | 36 | /*! 37 | * @property objectClass 38 | * @abstract The target object class 39 | * 40 | * @result A Class object 41 | */ 42 | @property (unsafe_unretained) Class objectClass; 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /src/framework/mocha/Objects/MOAllocator.m: -------------------------------------------------------------------------------- 1 | // 2 | // MOAllocator.m 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 7/25/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import "MOAllocator.h" 10 | 11 | 12 | @implementation MOAllocator 13 | 14 | @synthesize objectClass=_objectClass; 15 | 16 | + (MOAllocator *)allocator { 17 | return [[self alloc] init]; 18 | } 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /src/framework/mocha/Objects/MOBox.h: -------------------------------------------------------------------------------- 1 | // 2 | // MOBox.h 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/12/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | 13 | @class Mocha; 14 | 15 | 16 | /*! 17 | * @class MOBox 18 | * @abstract A boxed Objective-C object 19 | */ 20 | @interface MOBox : NSObject 21 | 22 | /*! 23 | * @property representedObject 24 | * @abstract The boxed Objective-C object 25 | * 26 | * @result An object 27 | */ 28 | @property (strong) id representedObject; 29 | 30 | /*! 31 | * @property JSObject 32 | * @abstract The JSObject representation of the box 33 | * 34 | * @result A JSObjectRef value 35 | */ 36 | @property JSObjectRef JSObject; 37 | 38 | /*! 39 | * @property runtime 40 | * @abstract The runtime for the object 41 | * 42 | * @result A Mocha object 43 | */ 44 | @property (weak) Mocha *runtime; 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /src/framework/mocha/Objects/MOBox.m: -------------------------------------------------------------------------------- 1 | // 2 | // MOBox.m 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/12/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import "MOBox.h" 10 | 11 | 12 | @implementation MOBox 13 | 14 | @synthesize JSObject=_JSObject; 15 | @synthesize runtime=_runtime; 16 | @synthesize representedObject=_representedObject; 17 | 18 | - (void)dealloc { 19 | //debug(@"MOBox dealloc releasing: '%@'", _representedObjectCanaryDesc); 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /src/framework/mocha/Objects/MOClosure.h: -------------------------------------------------------------------------------- 1 | // 2 | // MOClosure.h 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/19/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | /*! 13 | * @class MOClosure 14 | * @abstract A thin wrapper around a block object 15 | */ 16 | @interface MOClosure : NSObject 17 | 18 | /*! 19 | * @method closureWithBlock: 20 | * @abstract Creates a new closure 21 | * 22 | * @param block 23 | * The block object 24 | * 25 | * @result An MOClosure object 26 | */ 27 | + (MOClosure *)closureWithBlock:(id)block; 28 | 29 | /*! 30 | * @method initWithBlock: 31 | * @abstract Creates a new closure 32 | * 33 | * @param block 34 | * The block object 35 | * 36 | * @result An MOClosure object 37 | */ 38 | - (id)initWithBlock:(id)block; 39 | 40 | 41 | /*! 42 | * @property block 43 | * @abstract The block object 44 | * 45 | * @result A block object 46 | */ 47 | @property (copy, readonly) id block; 48 | 49 | /*! 50 | * @property callAddress 51 | * @abstract The address of the block's function pointer 52 | * 53 | * @result A void pointer value 54 | */ 55 | @property (readonly) void * callAddress; 56 | 57 | /*! 58 | * @property typeEncoding 59 | * @abstract The type encoding of the block 60 | * 61 | * @result A const char * value 62 | */ 63 | @property (readonly) const char * typeEncoding; 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /src/framework/mocha/Objects/MOClosure.m: -------------------------------------------------------------------------------- 1 | // 2 | // MOClosure.m 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/19/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import "MOClosure.h" 10 | #import "MOClosure_Private.h" 11 | 12 | #import "MOUtilities.h" 13 | 14 | 15 | @implementation MOClosure 16 | 17 | @synthesize block=_block; 18 | 19 | // 20 | // The following two structs are taken from clang's source. 21 | // 22 | 23 | struct Block_descriptor { 24 | unsigned long reserved; 25 | unsigned long size; 26 | void *rest[1]; 27 | }; 28 | 29 | struct Block_literal { 30 | void *isa; 31 | int flags; 32 | int reserved; 33 | void *invoke; 34 | struct Block_descriptor *descriptor; 35 | }; 36 | 37 | + (MOClosure *)closureWithBlock:(id)block { 38 | return [[self alloc] initWithBlock:block]; 39 | } 40 | 41 | - (id)initWithBlock:(id)block { 42 | self = [super init]; 43 | if (self) { 44 | _block = [block copy]; 45 | } 46 | return self; 47 | } 48 | 49 | - (void *)callAddress { 50 | return ((__bridge struct Block_literal *)_block)->invoke; 51 | } 52 | 53 | - (const char *)typeEncoding { 54 | struct Block_literal *block = (__bridge struct Block_literal *)_block; 55 | struct Block_descriptor *descriptor = block->descriptor; 56 | 57 | int copyDisposeFlag = 1 << 25; 58 | int signatureFlag = 1 << 30; 59 | 60 | assert(block->flags & signatureFlag); 61 | 62 | int index = 0; 63 | if (block->flags & copyDisposeFlag) { 64 | index += 2; 65 | } 66 | 67 | return descriptor->rest[index]; 68 | } 69 | 70 | @end 71 | -------------------------------------------------------------------------------- /src/framework/mocha/Objects/MOClosure_Private.h: -------------------------------------------------------------------------------- 1 | // 2 | // MOClosure_Private.h 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/19/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import "MOClosure.h" 10 | 11 | 12 | @interface MOClosure () 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /src/framework/mocha/Objects/MOInstanceVariableDescription.h: -------------------------------------------------------------------------------- 1 | // 2 | // MOInstanceVariableDescription.h 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/26/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | /*! 13 | * @class MOInstanceVariableDescription 14 | * @abstract A description of an Objective-C instance variable 15 | */ 16 | @interface MOInstanceVariableDescription : NSObject 17 | 18 | /*! 19 | * @method instanceVariableWithName:typeEncoding: 20 | * @abstract Creates a new instance variable 21 | * 22 | * @param name 23 | * The name of the instance variable 24 | * 25 | * @param typeEncoding 26 | * The type encoding of the instance variable 27 | * 28 | * @result An MOInstanceVariableDescription object 29 | */ 30 | + (MOInstanceVariableDescription *)instanceVariableWithName:(NSString *)name typeEncoding:(NSString *)typeEncoding; 31 | 32 | 33 | /*! 34 | * @property name 35 | * @abstract The name of the instance variable 36 | * 37 | * @result An NSString object 38 | */ 39 | @property (copy, readonly) NSString *name; 40 | 41 | /*! 42 | * @property typeEncoding 43 | * @abstract The type encoding of the instance variable 44 | * 45 | * @result An NSString object 46 | */ 47 | @property (copy, readonly) NSString *typeEncoding; 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /src/framework/mocha/Objects/MOInstanceVariableDescription.m: -------------------------------------------------------------------------------- 1 | // 2 | // MOInstanceVariableDescription.m 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/26/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import "MOInstanceVariableDescription.h" 10 | #import "MOInstanceVariableDescription_Private.h" 11 | 12 | 13 | @implementation MOInstanceVariableDescription 14 | 15 | @synthesize name=_name; 16 | @synthesize typeEncoding=_typeEncoding; 17 | 18 | + (MOInstanceVariableDescription *)instanceVariableWithName:(NSString *)name typeEncoding:(NSString *)typeEncoding { 19 | return [[self alloc] initWithName:name typeEncoding:typeEncoding]; 20 | } 21 | 22 | - (id)initWithName:(NSString *)name typeEncoding:(NSString *)typeEncoding { 23 | self = [super init]; 24 | if (self) { 25 | self.name = name; 26 | self.typeEncoding = typeEncoding; 27 | } 28 | return self; 29 | } 30 | 31 | 32 | - (NSString *)description { 33 | return [NSString stringWithFormat:@"<%@: %p : name=%@, typeEncoding=%@>", [self class], self, self.name, self.typeEncoding]; 34 | } 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /src/framework/mocha/Objects/MOInstanceVariableDescription_Private.h: -------------------------------------------------------------------------------- 1 | // 2 | // MOInstanceVariableDescription_Private.h 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/28/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import "MOInstanceVariableDescription.h" 10 | 11 | 12 | @interface MOInstanceVariableDescription () 13 | 14 | - (id)initWithName:(NSString *)name typeEncoding:(NSString *)typeEncoding; 15 | 16 | @property (copy, readwrite) NSString *name; 17 | @property (copy, readwrite) NSString *typeEncoding; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /src/framework/mocha/Objects/MOJavaScriptObject.h: -------------------------------------------------------------------------------- 1 | // 2 | // MOJavaScriptObject.h 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/28/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | 13 | /*! 14 | * @class MOJavaScriptObject 15 | * @abstract A thin wrapper around a pure JavaScript object 16 | */ 17 | @interface MOJavaScriptObject : NSObject 18 | 19 | /*! 20 | * @method objectWithJSObject:context: 21 | * @abstract Creates a new JavaScript wrapper object 22 | * 23 | * @param jsObject 24 | * @abstract The JavaScript object reference 25 | * 26 | * @param context 27 | * The JavaScript context reference 28 | * 29 | * @result An MOJavaScriptObject object 30 | */ 31 | + (MOJavaScriptObject *)objectWithJSObject:(JSObjectRef)jsObject context:(JSContextRef)ctx; 32 | 33 | 34 | /*! 35 | * @property JSObject 36 | * @abstract The JavaScript object reference 37 | * 38 | * @result A JSObjectRef value 39 | */ 40 | @property (readonly) JSObjectRef JSObject; 41 | 42 | /*! 43 | * @property JSContext 44 | * @abstract The JavaScript context reference 45 | * 46 | * @result A JSContextRef value 47 | */ 48 | @property (readonly) JSContextRef JSContext; 49 | 50 | @end 51 | -------------------------------------------------------------------------------- /src/framework/mocha/Objects/MOJavaScriptObject.m: -------------------------------------------------------------------------------- 1 | // 2 | // MOJavaScriptObject.m 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/28/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import "MOJavaScriptObject.h" 10 | 11 | 12 | @implementation MOJavaScriptObject { 13 | JSObjectRef _JSObject; 14 | JSContextRef _JSContext; 15 | } 16 | 17 | + (MOJavaScriptObject *)objectWithJSObject:(JSObjectRef)jsObject context:(JSContextRef)ctx { 18 | MOJavaScriptObject *object = [[MOJavaScriptObject alloc] init]; 19 | [object setJSObject:jsObject JSContext:ctx]; 20 | return object; 21 | } 22 | 23 | - (void)dealloc { 24 | if (_JSObject != NULL) { 25 | debug(@"%s:%d Unprotecting %p %p", __FUNCTION__, __LINE__, _JSObject, _JSContext); 26 | JSValueUnprotect(_JSContext, _JSObject); 27 | } 28 | 29 | if (_JSContext != NULL) { 30 | JSGlobalContextRelease((JSGlobalContextRef)_JSContext); 31 | } 32 | 33 | } 34 | 35 | - (JSObjectRef)JSObject { 36 | return _JSObject; 37 | } 38 | 39 | - (void)setJSObject:(JSObjectRef)JSObject JSContext:(JSContextRef)JSContext { 40 | if (_JSObject != NULL) { 41 | debug(@"%s:%d Unprotecting %p (s)", __FUNCTION__, __LINE__, _JSObject); 42 | JSValueUnprotect(_JSContext, _JSObject); 43 | } 44 | 45 | _JSObject = JSObject; 46 | _JSContext = JSGlobalContextRetain((JSGlobalContextRef)JSContext); 47 | if (_JSObject != NULL) { 48 | debug(@"%s:%d Protecting %p %p (s)", __FUNCTION__, __LINE__, _JSObject, _JSContext); 49 | JSValueProtect(_JSContext, _JSObject); 50 | } 51 | } 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /src/framework/mocha/Objects/MOMethod.h: -------------------------------------------------------------------------------- 1 | // 2 | // MOMethod.h 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/12/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | /*! 13 | * @class MOMethod 14 | * @abstract Represents a callable method 15 | */ 16 | @interface MOMethod : NSObject 17 | 18 | /*! 19 | * @method methodWithTarget:selector: 20 | * @abstract Creates a new method object from a target and selector 21 | * 22 | * @param target 23 | * The target of the method call 24 | * 25 | * @param selector 26 | * The selector called on the method target 27 | * 28 | * @result An MOMethod object 29 | */ 30 | + (MOMethod *)methodWithTarget:(id)target selector:(SEL)selector; 31 | 32 | 33 | /*! 34 | * @property target 35 | * @abstract The target of the method call 36 | * 37 | * @result An object 38 | */ 39 | @property (strong, readonly) id target; 40 | 41 | /*! 42 | * @property selector 43 | * @abstract The selector called on the method target 44 | * 45 | * @result A SEL value 46 | */ 47 | @property (readonly) SEL selector; 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /src/framework/mocha/Objects/MOMethod.m: -------------------------------------------------------------------------------- 1 | // 2 | // MOMethod.m 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/12/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import "MOMethod.h" 10 | #import "MOMethod_Private.h" 11 | 12 | 13 | @implementation MOMethod 14 | 15 | @synthesize target=_target; 16 | @synthesize selector=_selector; 17 | @synthesize block=_block; 18 | 19 | + (MOMethod *)methodWithTarget:(id)target selector:(SEL)selector { 20 | MOMethod *method = [[self alloc] init]; 21 | method.target = target; 22 | method.selector = selector; 23 | return method; 24 | } 25 | 26 | + (MOMethod *)methodWithBlock:(id)block { 27 | MOMethod *method = [[self alloc] init]; 28 | method.block = block; 29 | return method; 30 | } 31 | 32 | - (NSString *)description { 33 | return [NSString stringWithFormat:@"<%@: %p : target=%p%@, selector=%@>", [self class], self, [self target], [self target], NSStringFromSelector([self selector])]; 34 | } 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /src/framework/mocha/Objects/MOMethodDescription.h: -------------------------------------------------------------------------------- 1 | // 2 | // MOMethodDescription.h 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/26/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | /*! 13 | * @class MOMethodDescription 14 | * @abstract A description of an Objective-C method 15 | */ 16 | @interface MOMethodDescription : NSObject 17 | 18 | /*! 19 | * @method methodWithSelector:typeEncoding: 20 | * @abstract Creates a new method 21 | * 22 | * @param selector 23 | * The selector of the method 24 | * 25 | * @param typeEncoding 26 | * The type encoding of the method 27 | * 28 | * @result An MOMethodDescription object 29 | */ 30 | + (MOMethodDescription *)methodWithSelector:(SEL)selector typeEncoding:(NSString *)typeEncoding; 31 | 32 | /*! 33 | * @property selector 34 | * @abstract The selector of the method 35 | * 36 | * @result A SEL value 37 | */ 38 | @property (readonly) SEL selector; 39 | 40 | /*! 41 | * @property typeEncoding 42 | * @abstract The type encoding of the method 43 | * 44 | * @result An NSString object 45 | */ 46 | @property (copy, readonly) NSString *typeEncoding; 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /src/framework/mocha/Objects/MOMethodDescription.m: -------------------------------------------------------------------------------- 1 | // 2 | // MOMethodDescription.m 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/26/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import "MOMethodDescription.h" 10 | #import "MOMethodDescription_Private.h" 11 | 12 | 13 | @implementation MOMethodDescription 14 | 15 | @synthesize selector=_selector; 16 | @synthesize typeEncoding=_typeEncoding; 17 | 18 | + (MOMethodDescription *)methodWithSelector:(SEL)selector typeEncoding:(NSString *)typeEncoding { 19 | return [[self alloc] initWithSelector:selector typeEncoding:typeEncoding]; 20 | } 21 | 22 | - (id)initWithSelector:(SEL)selector typeEncoding:(NSString *)typeEncoding { 23 | self = [super init]; 24 | if (self) { 25 | self.selector = selector; 26 | self.typeEncoding = typeEncoding; 27 | } 28 | return self; 29 | } 30 | 31 | 32 | - (NSString *)description { 33 | return [NSString stringWithFormat:@"<%@: %p : selector=%@, typeEncoding=%@>", [self class], self, NSStringFromSelector(self.selector), self.typeEncoding]; 34 | } 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /src/framework/mocha/Objects/MOMethodDescription_Private.h: -------------------------------------------------------------------------------- 1 | // 2 | // MOMethodDescription_Private.h 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/28/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import "MOMethodDescription.h" 10 | 11 | 12 | @interface MOMethodDescription () 13 | 14 | - (id)initWithSelector:(SEL)selector typeEncoding:(NSString *)typeEncoding; 15 | 16 | @property (readwrite) SEL selector; 17 | @property (copy, readwrite) NSString *typeEncoding; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /src/framework/mocha/Objects/MOMethod_Private.h: -------------------------------------------------------------------------------- 1 | // 2 | // MOMethod_Private.h 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/12/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import "MOMethod.h" 10 | 11 | 12 | @interface MOMethod () 13 | 14 | @property (strong, readwrite) id target; 15 | @property (readwrite) SEL selector; 16 | 17 | @property (copy, readwrite) id block; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /src/framework/mocha/Objects/MOObjCRuntime.h: -------------------------------------------------------------------------------- 1 | // 2 | // MOObjCRuntime.h 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/16/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MochaDefines.h" 11 | 12 | 13 | /*! 14 | * @enum MOObjcOwnershipRule 15 | * @abstract Objective-C ownership rules 16 | * 17 | * @constant MOObjCOwnershipRuleAssign Assigned (unretained) 18 | * @constant MOObjCOwnershipRuleRetain Retained 19 | * @constant MOObjCOwnershipRuleCopy Copied/retained 20 | */ 21 | typedef MOCHA_ENUM(NSUInteger, MOObjCOwnershipRule) { 22 | MOObjCOwnershipRuleAssign = 0, 23 | MOObjCOwnershipRuleRetain, 24 | MOObjCOwnershipRuleCopy, 25 | }; 26 | 27 | 28 | /*! 29 | * @class MOObjCRuntime 30 | * @abstract Interface bridge to the Objective-C runtime 31 | */ 32 | @interface MOObjCRuntime : NSObject 33 | 34 | /*! 35 | * @method sharedRuntime 36 | * @abstract Gets the shared runtime instance 37 | * 38 | * @result An MOObjCRuntime object 39 | */ 40 | + (MOObjCRuntime *)sharedRuntime; 41 | 42 | 43 | /*! 44 | * @property classes 45 | * @abstract Gets the names of all classes registered with the runtime 46 | * 47 | * @discussion 48 | * This method will ignore any classes that begin with an underscore, as 49 | * convention is that they are considered private. 50 | * 51 | * @result An NSArray of NSString objects 52 | */ 53 | @property (copy, readonly) NSArray *classes; 54 | 55 | /*! 56 | * @property protocols 57 | * @abstract Gets the names of all protocols registered with the runtime 58 | * 59 | * @discussion 60 | * This method will ignore any protocols that begin with an underscore, as 61 | * convention is that they are considered private. 62 | * 63 | * @result An NSArray of NSString objects 64 | */ 65 | @property (copy, readonly) NSArray *protocols; 66 | 67 | @end 68 | -------------------------------------------------------------------------------- /src/framework/mocha/Objects/MOObjCRuntime.m: -------------------------------------------------------------------------------- 1 | // 2 | // MOObjCRuntime.m 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/16/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import "MOObjCRuntime.h" 10 | 11 | #import 12 | 13 | 14 | @implementation MOObjCRuntime 15 | 16 | + (MOObjCRuntime *)sharedRuntime { 17 | static MOObjCRuntime * sharedRuntime = nil; 18 | static dispatch_once_t onceToken; 19 | dispatch_once(&onceToken, ^{ 20 | sharedRuntime = [[self alloc] init]; 21 | }); 22 | return sharedRuntime; 23 | } 24 | 25 | - (id)init { 26 | self = [super init]; 27 | if (self) { 28 | 29 | } 30 | return self; 31 | } 32 | 33 | 34 | #pragma mark - 35 | #pragma mark Accessors 36 | 37 | - (NSArray *)classes { 38 | unsigned int count; 39 | Class *classList = objc_copyClassList(&count); 40 | NSMutableArray *classes = [NSMutableArray arrayWithCapacity:count]; 41 | for (NSUInteger i=0; i 10 | 11 | 12 | /*! 13 | * @class MOPointer 14 | * @abstract A pointer to a value 15 | */ 16 | @interface MOPointer : NSObject 17 | 18 | /*! 19 | * @method initWithValue: 20 | * @abstract Creates a new pointer 21 | * 22 | * @param value 23 | * The value for the pointer 24 | * 25 | * @result An MOPointer object 26 | */ 27 | - (id)initWithValue:(id)value; 28 | 29 | 30 | /*! 31 | * @property value 32 | * @abstract The value of the pointer 33 | * 34 | * @result An object, or nil 35 | */ 36 | @property (strong, readonly) id value; 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /src/framework/mocha/Objects/MOPointer.m: -------------------------------------------------------------------------------- 1 | // 2 | // MOPointer.m 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 7/31/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import "MOPointer.h" 10 | #import "MOPointer_Private.h" 11 | 12 | 13 | @implementation MOPointer 14 | 15 | @synthesize value=_value; 16 | 17 | - (id)initWithValue:(id)value { 18 | self = [super init]; 19 | if (self) { 20 | self.value = value; 21 | } 22 | return self; 23 | } 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /src/framework/mocha/Objects/MOPointerValue.h: -------------------------------------------------------------------------------- 1 | // 2 | // MOPointerValue.h 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 7/26/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | /*! 13 | * @class MOPointerValue 14 | * @abstract An object representation of a C pointer value 15 | */ 16 | @interface MOPointerValue : NSObject 17 | 18 | /*! 19 | * @method initWithPointerValue:typeEncoding: 20 | * @abstract Creates a new pointer value 21 | * 22 | * @param pointerValue 23 | * The C pointer value 24 | * 25 | * @param typeEncoding 26 | * The type encoding of the pointer 27 | * 28 | * @result An MOPointerValue object 29 | */ 30 | - (id)initWithPointerValue:(void *)pointerValue typeEncoding:(NSString *)typeEncoding; 31 | 32 | 33 | /*! 34 | * @property pointerValue 35 | * @abstract The C pointer value 36 | * 37 | * @result A void pointer value 38 | */ 39 | @property (readonly) void * pointerValue; 40 | 41 | /*! 42 | * @property typeEncoding 43 | * @abstract The type encoding of the pointer 44 | * 45 | * @result An NSString object 46 | */ 47 | @property (copy, readonly) NSString *typeEncoding; 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /src/framework/mocha/Objects/MOPointerValue.m: -------------------------------------------------------------------------------- 1 | // 2 | // MOPointerValue.m 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 7/26/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import "MOPointerValue.h" 10 | 11 | 12 | @interface MOPointerValue () 13 | 14 | @property (readwrite) void * pointerValue; 15 | @property (copy, readwrite) NSString *typeEncoding; 16 | 17 | @end 18 | 19 | 20 | @implementation MOPointerValue 21 | 22 | @synthesize pointerValue=_pointerValue; 23 | @synthesize typeEncoding=_typeEncoding; 24 | 25 | - (id)initWithPointerValue:(void *)pointerValue typeEncoding:(NSString *)typeEncoding { 26 | self = [super init]; 27 | if (self) { 28 | self.pointerValue = pointerValue; 29 | self.typeEncoding = typeEncoding; 30 | } 31 | return self; 32 | } 33 | 34 | - (NSString *)description { 35 | if ([self.typeEncoding length] > 0) { 36 | return [NSString stringWithFormat:@"<%p type=%@>", self.pointerValue, self.typeEncoding]; 37 | } 38 | else { 39 | return [NSString stringWithFormat:@"<%p>", self.pointerValue]; 40 | } 41 | } 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /src/framework/mocha/Objects/MOPointer_Private.h: -------------------------------------------------------------------------------- 1 | // 2 | // MOPointer_Private.h 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 8/6/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import "MOPointer.h" 10 | 11 | 12 | @interface MOPointer () 13 | 14 | @property (strong) id value; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /src/framework/mocha/Objects/MOPropertyDescription.h: -------------------------------------------------------------------------------- 1 | // 2 | // MOPropertyDescription.h 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/26/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MOObjCRuntime.h" 11 | 12 | 13 | /*! 14 | * @class MOPropertyDescription 15 | * @abstract Description for an Objective-C class property 16 | */ 17 | @interface MOPropertyDescription : NSObject 18 | 19 | /*! 20 | * @property name 21 | * @abstract The name of the property 22 | * 23 | * @result An NSString object 24 | */ 25 | @property (copy) NSString *name; 26 | 27 | /*! 28 | * @property typeEncoding 29 | * @abstract The type encoding of the property 30 | * 31 | * @result An NSString object 32 | */ 33 | @property (copy) NSString *typeEncoding; 34 | 35 | 36 | /*! 37 | * @property ivarName 38 | * @abstract The name of the backing instance variable 39 | * 40 | * @result An NSString object 41 | */ 42 | @property (copy) NSString *ivarName; 43 | 44 | 45 | /*! 46 | * @property getterSelector 47 | * @abstract The selector for the getter method 48 | * 49 | * @result A SEL value 50 | */ 51 | @property SEL getterSelector; 52 | 53 | /*! 54 | * @property setterSelector 55 | * @abstract The selector for the setter method 56 | * 57 | * @result A SEL value 58 | */ 59 | @property SEL setterSelector; 60 | 61 | 62 | /*! 63 | * @property ownershipRule 64 | * @abstract The ownership rule for the property 65 | * 66 | * @result An MOObjCOwnershipRule value 67 | */ 68 | @property MOObjCOwnershipRule ownershipRule; 69 | 70 | 71 | /*! 72 | * @property dynamic 73 | * @abstract Whether getter and setter methods are created at runtime 74 | * 75 | * @result A BOOL value 76 | */ 77 | @property (getter=isDynamic) BOOL dynamic; 78 | 79 | /*! 80 | * @property nonAtomic 81 | * @abstract Whether the property should work non-atomically (without synchronization code) 82 | * 83 | * @result A BOOL value 84 | */ 85 | @property (getter=isNonAtomic) BOOL nonAtomic; 86 | 87 | /*! 88 | * @property readOnly 89 | * @abstract Whether the property is read-only 90 | * 91 | * @result A BOOL value 92 | */ 93 | @property (getter=isReadOnly) BOOL readOnly; 94 | 95 | /*! 96 | * @property weak 97 | * @abstract Whether the property's value is weakly assigned 98 | * 99 | * @result A BOOL value 100 | */ 101 | @property (getter=isWeak) BOOL weak; 102 | 103 | @end 104 | -------------------------------------------------------------------------------- /src/framework/mocha/Objects/MOPropertyDescription.m: -------------------------------------------------------------------------------- 1 | // 2 | // MOPropertyDescription.m 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/26/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import "MOPropertyDescription.h" 10 | 11 | 12 | @implementation MOPropertyDescription 13 | 14 | @synthesize name=_name; 15 | @synthesize typeEncoding=_typeEncoding; 16 | @synthesize ivarName=_ivarName; 17 | @synthesize getterSelector=_getterSelector; 18 | @synthesize setterSelector=_setterSelector; 19 | @synthesize ownershipRule=_ownershipRule; 20 | @synthesize dynamic=_dynamic; 21 | @synthesize nonAtomic=_nonAtomic; 22 | @synthesize readOnly=_readOnly; 23 | @synthesize weak=_weak; 24 | 25 | - (NSString *)description { 26 | NSMutableArray *attributeValues = [NSMutableArray array]; 27 | 28 | if (self.ownershipRule == MOObjCOwnershipRuleAssign) { 29 | [attributeValues addObject:@"assign"]; 30 | } 31 | else if (self.ownershipRule == MOObjCOwnershipRuleCopy) { 32 | [attributeValues addObject:@"copy"]; 33 | } 34 | else if (self.ownershipRule == MOObjCOwnershipRuleRetain) { 35 | [attributeValues addObject:@"retain"]; 36 | } 37 | 38 | if (self.dynamic) { 39 | [attributeValues addObject:@"dynamic"]; 40 | } 41 | if (self.nonAtomic) { 42 | [attributeValues addObject:@"nonatomic"]; 43 | } 44 | if (self.readOnly) { 45 | [attributeValues addObject:@"readonly"]; 46 | } 47 | if (self.weak) { 48 | [attributeValues addObject:@"weak"]; 49 | } 50 | 51 | if (self.getterSelector != NULL) { 52 | [attributeValues addObject:[NSString stringWithFormat:@"getter=%@", NSStringFromSelector(self.getterSelector)]]; 53 | } 54 | if (self.setterSelector != NULL) { 55 | [attributeValues addObject:[NSString stringWithFormat:@"setter=%@", NSStringFromSelector(self.setterSelector)]]; 56 | } 57 | 58 | NSString *attributes = [attributeValues componentsJoinedByString:@","]; 59 | 60 | return [NSString stringWithFormat:@"<%@: %p : name=%@, typeEncoding=%@, ivar=%@, attributes=(%@)>", [self class], self, self.name, self.typeEncoding, self.ivarName, attributes]; 61 | } 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /src/framework/mocha/Objects/MOProtocolDescription_Private.h: -------------------------------------------------------------------------------- 1 | // 2 | // MOProtocolDescription_Private.h 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/28/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import "MOProtocolDescription.h" 10 | 11 | 12 | @interface MOProtocolDescription () 13 | 14 | @property (unsafe_unretained, readonly) Protocol *protocol; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /src/framework/mocha/Objects/MOStruct.h: -------------------------------------------------------------------------------- 1 | // 2 | // MOStruct.h 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/15/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | /*! 13 | * @class MOStruct 14 | * @abstract An object representation of a C struct 15 | */ 16 | @interface MOStruct : NSObject 17 | 18 | /*! 19 | * @method structureWithName:memberNames: 20 | * @abstract Creates a new structure 21 | * 22 | * @param name 23 | * The name of the structure 24 | * 25 | * @param memberNames 26 | * The ordered list of member names of the structure 27 | * 28 | * @result An MOStruct object 29 | */ 30 | + (MOStruct *)structureWithName:(NSString *)name memberNames:(NSArray *)memberNames; 31 | 32 | /*! 33 | * @method initWithName:memberNames: 34 | * @abstract Creates a new structure 35 | * 36 | * @param name 37 | * The name of the structure 38 | * 39 | * @param memberNames 40 | * The ordered list of member names of the structure 41 | * 42 | * @result An MOStruct object 43 | */ 44 | - (id)initWithName:(NSString *)name memberNames:(NSArray *)memberNames; 45 | 46 | 47 | /*! 48 | * @property name 49 | * @abstract The name of the structure 50 | * 51 | * @result An NSString object 52 | */ 53 | @property (copy, readonly) NSString *name; 54 | 55 | /*! 56 | * @property memberNames 57 | * @abstract The ordered list of member names of the structure 58 | * 59 | * @result An NSArray of NSString objects 60 | */ 61 | @property (copy, readonly) NSArray *memberNames; 62 | 63 | 64 | /*! 65 | * @method objectForMemberName: 66 | * @abstract Gets the value for a specified member name 67 | * 68 | * @param memberName 69 | * The member name 70 | * 71 | * @discussion 72 | * This method raises an MORuntime exception if the structure has 73 | * no member named name. 74 | * 75 | * @result An object, or nil 76 | */ 77 | - (id)objectForMemberName:(NSString *)name; 78 | 79 | /*! 80 | * @method setObject:forMemberName: 81 | * @abstract Sets the value for a specified member name 82 | * 83 | * @param obj 84 | * The new value 85 | * 86 | * @param name 87 | * The member name 88 | * 89 | * @discussion 90 | * This method raises an MORuntime exception if the structure has 91 | * no member named name. 92 | */ 93 | - (void)setObject:(id)obj forMemberName:(NSString *)name; 94 | 95 | @end 96 | -------------------------------------------------------------------------------- /src/framework/mocha/Objects/MOUndefined.h: -------------------------------------------------------------------------------- 1 | // 2 | // MOUndefined.h 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/15/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | /*! 13 | * @class MOUndefined 14 | * @abstract Represents an "undefined" value, as passed from JavaScript to Objective-C 15 | * 16 | * @discussion 17 | * Syntactically, the undefined value represents the return value of a function that returns 'void' in C. 18 | */ 19 | @interface MOUndefined : NSObject 20 | 21 | /*! 22 | * @method undefined 23 | * @abstract Gets the singleton undefined instance 24 | * 25 | * @result An MOUndefined object 26 | */ 27 | + (MOUndefined *)undefined; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /src/framework/mocha/Objects/MOUndefined.m: -------------------------------------------------------------------------------- 1 | // 2 | // MOUndefined.m 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/15/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import "MOUndefined.h" 10 | 11 | 12 | @implementation MOUndefined 13 | 14 | + (MOUndefined *)undefined { 15 | static MOUndefined *sharedInstance = nil; 16 | static dispatch_once_t onceToken; 17 | dispatch_once(&onceToken, ^{ 18 | sharedInstance = [[self alloc] init]; 19 | }); 20 | return sharedInstance; 21 | } 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /src/framework/mocha/Utilities/MOUtilities.h: -------------------------------------------------------------------------------- 1 | // 2 | // MOUtilities.h 3 | // Mocha 4 | // 5 | // Created by Logan Collins on 5/11/12. 6 | // Copyright (c) 2012 Sunflower Softworks. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | #if TARGET_OS_IPHONE 13 | #import "ffi.h" 14 | #else 15 | #import 16 | #endif 17 | 18 | 19 | @class MOBridgeSupportFunction, MOFunctionArgument, MOJavaScriptObject; 20 | 21 | 22 | JSValueRef MOJSValueToType(JSContextRef ctx, JSObjectRef objectJS, JSType type, JSValueRef *exception); 23 | NSString * MOJSValueToString(JSContextRef ctx, JSValueRef value, JSValueRef *exception); 24 | 25 | JSValueRef MOSelectorInvoke(id target, SEL selector, JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception); 26 | JSValueRef MOFunctionInvoke(id function, JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception); 27 | 28 | BOOL MOSelectorIsVariadic(Class klass, SEL selector); 29 | void * MOInvocationGetObjCCallAddressForArguments(NSArray *arguments); 30 | 31 | MOFunctionArgument * MOFunctionArgumentForTypeEncoding(NSString *typeEncoding); 32 | NSArray * MOParseObjCMethodEncoding(const char *typeEncoding); 33 | 34 | SEL MOSelectorFromPropertyName(NSString *propertyName); 35 | NSString * MOSelectorToPropertyName(SEL selector); 36 | 37 | NSString * MOPropertyNameToSetterName(NSString *propertyName); 38 | 39 | id MOGetBlockForJavaScriptFunction(MOJavaScriptObject *function, NSUInteger *argCount); 40 | -------------------------------------------------------------------------------- /src/framework/mocha/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDAlternation.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDAlternation.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 7/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TDCollectionParser.h" 11 | 12 | /*! 13 | @class TDAlternation 14 | @brief A TDAlternation object is a collection of parsers, any one of which can successfully match against an assembly. 15 | */ 16 | @interface TDAlternation : TDCollectionParser { 17 | 18 | } 19 | 20 | /*! 21 | @brief Convenience factory method for initializing an autoreleased TDAlternation parser. 22 | @result an initialized autoreleased TDAlternation parser. 23 | */ 24 | + (id)alternation; 25 | @end 26 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDAlternation.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDAlternation.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 7/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDAlternation.h" 10 | #import "TDAssembly.h" 11 | 12 | @interface TDParser () 13 | - (NSSet *)matchAndAssemble:(NSSet *)inAssemblies; 14 | @end 15 | 16 | @implementation TDAlternation 17 | 18 | + (id)alternation { 19 | return [[[self alloc] init] autorelease]; 20 | } 21 | 22 | 23 | - (NSSet *)allMatchesFor:(NSSet *)inAssemblies { 24 | NSParameterAssert(inAssemblies); 25 | NSMutableSet *outAssemblies = [NSMutableSet set]; 26 | 27 | for (TDParser *p in subparsers) { 28 | [outAssemblies unionSet:[p matchAndAssemble:inAssemblies]]; 29 | } 30 | 31 | return outAssemblies; 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDAny.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDAny.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 12/14/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TDTerminal.h" 11 | 12 | /*! 13 | @class TDAny 14 | @brief A TDAny matches any token from a token assembly. 15 | */ 16 | @interface TDAny : TDTerminal { 17 | 18 | } 19 | 20 | /*! 21 | @brief Convenience factory method for initializing an autoreleased TDAny object. 22 | @result an initialized autoreleased TDAny object 23 | */ 24 | + (id)any; 25 | @end 26 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDAny.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDAny.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 12/14/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDAny.h" 10 | #import "TDToken.h" 11 | 12 | @implementation TDAny 13 | 14 | + (id)any { 15 | return [[[self alloc] initWithString:nil] autorelease]; 16 | } 17 | 18 | 19 | - (BOOL)qualifies:(id)obj { 20 | return [obj isKindOfClass:[TDToken class]]; 21 | } 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDCaseInsensitiveLiteral.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDCaseInsensitiveLiteral.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 7/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TDLiteral.h" 11 | 12 | /*! 13 | @class TDCaseInsensitiveLiteral 14 | @brief A TDCaselessLiteral matches a specified NSString from an assembly, disregarding case. 15 | */ 16 | @interface TDCaseInsensitiveLiteral : TDLiteral { 17 | 18 | } 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDCaseInsensitiveLiteral.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDCaseInsensitiveLiteral.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 7/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDCaseInsensitiveLiteral.h" 10 | #import "TDToken.h" 11 | 12 | @implementation TDCaseInsensitiveLiteral 13 | 14 | - (BOOL)qualifies:(id)obj { 15 | return NSOrderedSame == [literal.stringValue caseInsensitiveCompare:[obj stringValue]]; 16 | // return [literal isEqualIgnoringCase:obj]; 17 | } 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDChar.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDChar.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 8/14/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDTerminal.h" 10 | 11 | /*! 12 | @class TDChar 13 | @brief A TDChar matches a character from a character assembly. 14 | @details -[TDChar qualifies:] returns true every time, since this class assumes it is working against a TDCharacterAssembly. 15 | */ 16 | @interface TDChar : TDTerminal { 17 | 18 | } 19 | 20 | /*! 21 | @brief Convenience factory method for initializing an autoreleased TDChar parser. 22 | @result an initialized autoreleased TDChar parser. 23 | */ 24 | + (id)char; 25 | @end 26 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDChar.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDChar.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 8/14/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDChar.h" 10 | 11 | @implementation TDChar 12 | 13 | + (id)char { 14 | return [[[self alloc] initWithString:nil] autorelease]; 15 | } 16 | 17 | 18 | - (BOOL)qualifies:(id)obj { 19 | return YES; 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDCharacterAssembly.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDCharacterAssembly.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 7/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDAssembly.h" 10 | 11 | /*! 12 | @class TDCharacterAssembly 13 | @brief A TDCharacterAssembly is a TDAssembly whose elements are characters. 14 | */ 15 | @interface TDCharacterAssembly : TDAssembly { 16 | 17 | } 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDCollectionParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDCollectionParser.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 7/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TDParser.h" 11 | 12 | /*! 13 | @class TDCollectionParser 14 | @brief An Abstract class. This class abstracts the behavior common to parsers that consist of a series of other parsers. 15 | */ 16 | @interface TDCollectionParser : TDParser { 17 | NSMutableArray *subparsers; 18 | } 19 | 20 | /*! 21 | @brief Adds a parser to the collection. 22 | @param p parser to add 23 | */ 24 | - (void)add:(TDParser *)p; 25 | 26 | /*! 27 | @property subparsers 28 | @brief This parser's subparsers. 29 | */ 30 | @property (nonatomic, readonly, retain) NSMutableArray *subparsers; 31 | @end 32 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDCollectionParser.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDCollectionParser.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 7/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDCollectionParser.h" 10 | 11 | @interface TDCollectionParser () 12 | @property (nonatomic, readwrite, retain) NSMutableArray *subparsers; 13 | @end 14 | 15 | @implementation TDCollectionParser 16 | 17 | - (id)init { 18 | self = [super init]; 19 | if (self) { 20 | self.subparsers = [NSMutableArray array]; 21 | } 22 | return self; 23 | } 24 | 25 | 26 | - (void)dealloc { 27 | self.subparsers = nil; 28 | [super dealloc]; 29 | } 30 | 31 | 32 | - (void)add:(TDParser *)p { 33 | NSParameterAssert(p); 34 | [subparsers addObject:p]; 35 | } 36 | 37 | @synthesize subparsers; 38 | @end 39 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDComment.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDComment.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 12/31/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TDTerminal.h" 11 | 12 | /*! 13 | @class TDComment 14 | @brief A Comment matches a comment from a token assembly. 15 | */ 16 | @interface TDComment : TDTerminal { 17 | 18 | } 19 | 20 | /*! 21 | @brief Convenience factory method for initializing an autoreleased TDComment object. 22 | @result an initialized autoreleased TDComment object 23 | */ 24 | + (id)comment; 25 | @end 26 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDComment.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDComment.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 12/31/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDComment.h" 10 | #import "TDToken.h" 11 | 12 | @implementation TDComment 13 | 14 | + (id)comment { 15 | return [[[self alloc] initWithString:nil] autorelease]; 16 | } 17 | 18 | 19 | - (BOOL)qualifies:(id)obj { 20 | TDToken *tok = (TDToken *)obj; 21 | return tok.isComment; 22 | } 23 | 24 | @end -------------------------------------------------------------------------------- /src/framework/todparsekit/TDDigit.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDDigit.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 8/14/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDTerminal.h" 10 | 11 | /*! 12 | @class TDDigit 13 | @brief A TDDigit matches a digit from a character assembly. 14 | @details -[TDDitgit qualifies:] returns true if an assembly's next element is a digit. 15 | */ 16 | @interface TDDigit : TDTerminal { 17 | 18 | } 19 | 20 | /*! 21 | @brief Convenience factory method for initializing an autoreleased TDDigit parser. 22 | @result an initialized autoreleased TDDigit parser. 23 | */ 24 | + (id)digit; 25 | @end 26 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDDigit.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDDigit.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 8/14/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDDigit.h" 10 | 11 | @implementation TDDigit 12 | 13 | + (id)digit { 14 | return [[[self alloc] initWithString:nil] autorelease]; 15 | } 16 | 17 | 18 | - (BOOL)qualifies:(id)obj { 19 | NSInteger c = [obj integerValue]; 20 | return isdigit((int)c); 21 | } 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDEmpty.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDEmpty.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 7/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TDParser.h" 11 | 12 | /*! 13 | @class TDEmpty 14 | @brief A TDEmpty parser matches any assembly once, and applies its assembler that one time. 15 | @details

Language elements often contain empty parts. For example, a language may at some point allow a list of parameters in parentheses, and may allow an empty list. An empty parser makes it easy to match, within the parenthesis, either a list of parameters or "empty".

16 | */ 17 | @interface TDEmpty : TDParser { 18 | 19 | } 20 | 21 | /*! 22 | @brief Convenience factory method for initializing an autoreleased TDEmpty parser. 23 | @result an initialized autoreleased TDEmpty parser. 24 | */ 25 | + (id)empty; 26 | @end 27 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDEmpty.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDEmpty.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 7/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDEmpty.h" 10 | 11 | @implementation TDEmpty 12 | 13 | + (id)empty { 14 | return [[[self alloc] init] autorelease]; 15 | } 16 | 17 | 18 | - (NSSet *)allMatchesFor:(NSSet *)inAssemblies { 19 | NSParameterAssert(inAssemblies); 20 | //return [[[NSSet alloc] initWithSet:inAssemblies copyItems:YES] autorelease]; 21 | return inAssemblies; 22 | } 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDLetter.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDLetter.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 8/14/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDTerminal.h" 10 | 11 | /*! 12 | @class TDLetter 13 | @brief A TDLetter matches any letter from a character assembly. 14 | @details -[TDLetter qualifies:] returns true if an assembly's next element is a letter. 15 | */ 16 | @interface TDLetter : TDTerminal { 17 | 18 | } 19 | 20 | /*! 21 | @brief Convenience factory method for initializing an autoreleased TDLetter parser. 22 | @result an initialized autoreleased TDLetter parser. 23 | */ 24 | + (id)letter; 25 | @end 26 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDLetter.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDLetter.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 8/14/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDLetter.h" 10 | 11 | @implementation TDLetter 12 | 13 | + (id)letter { 14 | return [[[self alloc] initWithString:nil] autorelease]; 15 | } 16 | 17 | 18 | - (BOOL)qualifies:(id)obj { 19 | NSInteger c = [obj integerValue]; 20 | return isalpha((int)c); 21 | } 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDLiteral.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDLiteral.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 7/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TDTerminal.h" 11 | 12 | @class TDToken; 13 | 14 | /*! 15 | @class TDLiteral 16 | @brief A Literal matches a specific word from an assembly. 17 | */ 18 | @interface TDLiteral : TDTerminal { 19 | TDToken *literal; 20 | } 21 | 22 | /*! 23 | @brief Convenience factory method for initializing an autoreleased TDLiteral object with a given string. 24 | @param s the word represented by this literal 25 | @result an initialized autoreleased TDLiteral object representing s 26 | */ 27 | + (id)literalWithString:(NSString *)s; 28 | @end 29 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDLiteral.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDLiteral.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 7/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDLiteral.h" 10 | #import "TDToken.h" 11 | 12 | @interface TDLiteral () 13 | @property (nonatomic, retain) TDToken *literal; 14 | @end 15 | 16 | @implementation TDLiteral 17 | 18 | + (id)literalWithString:(NSString *)s { 19 | return [[[self alloc] initWithString:s] autorelease]; 20 | } 21 | 22 | 23 | - (id)initWithString:(NSString *)s { 24 | //NSParameterAssert(s); 25 | self = [super initWithString:s]; 26 | if (self) { 27 | self.literal = [TDToken tokenWithTokenType:TDTokenTypeWord stringValue:s floatValue:0.0]; 28 | } 29 | return self; 30 | } 31 | 32 | 33 | - (void)dealloc { 34 | self.literal = nil; 35 | [super dealloc]; 36 | } 37 | 38 | 39 | - (BOOL)qualifies:(id)obj { 40 | return [literal.stringValue isEqualToString:[obj stringValue]]; 41 | //return [literal isEqual:obj]; 42 | } 43 | 44 | 45 | - (NSString *)description { 46 | NSString *className = [[self className] substringFromIndex:2]; 47 | if (name.length) { 48 | return [NSString stringWithFormat:@"%@ (%@) %@", className, name, literal.stringValue]; 49 | } else { 50 | return [NSString stringWithFormat:@"%@ %@", className, literal.stringValue]; 51 | } 52 | } 53 | 54 | @synthesize literal; 55 | @end 56 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDLowercaseWord.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDLowercaseWord.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 8/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TDWord.h" 11 | 12 | @interface TDLowercaseWord : TDWord { 13 | 14 | } 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDLowercaseWord.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDLowercaseWord.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 8/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDLowercaseWord.h" 10 | #import "TDToken.h" 11 | 12 | @implementation TDLowercaseWord 13 | 14 | - (BOOL)qualifies:(id)obj { 15 | TDToken *tok = (TDToken *)obj; 16 | if (!tok.isWord) { 17 | return NO; 18 | } 19 | 20 | NSString *s = tok.stringValue; 21 | return s.length && islower([s characterAtIndex:0]); 22 | } 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDMultiLineCommentState.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDMultiLineCommentState.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 12/28/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TDTokenizerState.h" 11 | 12 | @interface TDMultiLineCommentState : TDTokenizerState { 13 | NSMutableArray *startSymbols; 14 | NSMutableArray *endSymbols; 15 | NSString *currentStartSymbol; 16 | } 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDNonReservedWord.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDNonReservedWord.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 8/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TDWord.h" 11 | 12 | @interface TDNonReservedWord : TDWord { 13 | 14 | } 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDNonReservedWord.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDNonReservedWord.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 8/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDNonReservedWord.h" 10 | #import "TDReservedWord.h" 11 | #import "TDToken.h" 12 | 13 | @interface TDReservedWord () 14 | + (NSArray *)reservedWords; 15 | @end 16 | 17 | @implementation TDNonReservedWord 18 | 19 | - (BOOL)qualifies:(id)obj { 20 | TDToken *tok = (TDToken *)obj; 21 | if (!tok.isWord) { 22 | return NO; 23 | } 24 | 25 | NSString *s = tok.stringValue; 26 | return s.length && ![[TDReservedWord reservedWords] containsObject:s]; 27 | } 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDNum.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDNum.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 7/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TDTerminal.h" 11 | 12 | /*! 13 | @class TDNum 14 | @brief A Num matches a number from a token assembly. 15 | */ 16 | @interface TDNum : TDTerminal { 17 | 18 | } 19 | 20 | /*! 21 | @brief Convenience factory method for initializing an autoreleased TDNum object. 22 | @result an initialized autoreleased TDNum object 23 | */ 24 | + (id)num; 25 | @end 26 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDNum.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDNum.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 7/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDNum.h" 10 | #import "TDToken.h" 11 | 12 | @implementation TDNum 13 | 14 | + (id)num { 15 | return [[[self alloc] initWithString:nil] autorelease]; 16 | } 17 | 18 | 19 | - (BOOL)qualifies:(id)obj { 20 | TDToken *tok = (TDToken *)obj; 21 | return tok.isNumber; 22 | } 23 | 24 | @end -------------------------------------------------------------------------------- /src/framework/todparsekit/TDNumberState.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDNumberState.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 1/20/06. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TDTokenizerState.h" 11 | 12 | /*! 13 | @class TDNumberState 14 | @brief A number state returns a number from a reader. 15 | @details This state's idea of a number allows an optional, initial minus sign, followed by one or more digits. A decimal point and another string of digits may follow these digits. 16 | */ 17 | @interface TDNumberState : TDTokenizerState { 18 | BOOL allowsTrailingDot; 19 | BOOL gotADigit; 20 | BOOL negative; 21 | NSInteger c; 22 | CGFloat floatValue; 23 | } 24 | 25 | /*! 26 | @property allowsTrailingDot 27 | @brief If true, numbers are allowed to end with a trialing dot, e.g. 42. 28 | @details false by default. 29 | */ 30 | @property (nonatomic) BOOL allowsTrailingDot; 31 | @end 32 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDQuoteState.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDQuoteState.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 1/20/06. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TDTokenizerState.h" 11 | 12 | /*! 13 | @class TDQuoteState 14 | @brief A quote state returns a quoted string token from a reader 15 | @details This state will collect characters until it sees a match to the character that the tokenizer used to switch to this state. For example, if a tokenizer uses a double- quote character to enter this state, then -nextToken will search for another double-quote until it finds one or finds the end of the reader. 16 | */ 17 | @interface TDQuoteState : TDTokenizerState { 18 | BOOL balancesEOFTerminatedQuotes; 19 | } 20 | 21 | /*! 22 | @property balancesEOFTerminatedQuotes 23 | @brief if true, this state will append a matching quote char (' or ") to quotes terminated by EOF. Default is NO. 24 | */ 25 | @property (nonatomic) BOOL balancesEOFTerminatedQuotes; 26 | @end 27 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDQuoteState.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDQuoteState.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 1/20/06. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDQuoteState.h" 10 | #import "TDReader.h" 11 | #import "TDToken.h" 12 | 13 | @interface TDTokenizerState () 14 | - (void)reset; 15 | - (void)append:(NSInteger)c; 16 | - (NSString *)bufferedString; 17 | @end 18 | 19 | @implementation TDQuoteState 20 | 21 | - (void)dealloc { 22 | [super dealloc]; 23 | } 24 | 25 | 26 | - (TDToken *)nextTokenFromReader:(TDReader *)r startingWith:(NSInteger)cin tokenizer:(TDTokenizer *)t { 27 | NSParameterAssert(r); 28 | [self reset]; 29 | 30 | [self append:cin]; 31 | NSInteger c; 32 | do { 33 | c = [r read]; 34 | if (-1 == c) { 35 | c = cin; 36 | if (balancesEOFTerminatedQuotes) { 37 | [self append:c]; 38 | } 39 | } else { 40 | [self append:c]; 41 | } 42 | 43 | } while (c != cin); 44 | 45 | return [TDToken tokenWithTokenType:TDTokenTypeQuotedString stringValue:[self bufferedString] floatValue:0.0]; 46 | } 47 | 48 | @synthesize balancesEOFTerminatedQuotes; 49 | @end 50 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDQuotedString.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDQuotedString.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 7/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TDTerminal.h" 11 | 12 | /*! 13 | @class TDQuotedString 14 | @brief A TDQuotedString matches a quoted string, like "this one" from a token assembly. 15 | */ 16 | @interface TDQuotedString : TDTerminal { 17 | 18 | } 19 | 20 | /*! 21 | @brief Convenience factory method for initializing an autoreleased TDQuotedString object. 22 | @result an initialized autoreleased TDQuotedString object 23 | */ 24 | + (id)quotedString; 25 | @end 26 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDQuotedString.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDQuotedString.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 7/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDQuotedString.h" 10 | #import "TDToken.h" 11 | 12 | @implementation TDQuotedString 13 | 14 | + (id)quotedString { 15 | return [[[self alloc] initWithString:nil] autorelease]; 16 | } 17 | 18 | 19 | - (BOOL)qualifies:(id)obj { 20 | TDToken *tok = (TDToken *)obj; 21 | return tok.isQuotedString; 22 | } 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDReader.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDReader.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 1/21/06. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | /*! 12 | @class TDReader 13 | @brief A character-stream reader that allows characters to be pushed back into the stream. 14 | */ 15 | @interface TDReader : NSObject { 16 | NSString *string; 17 | NSUInteger cursor; 18 | NSUInteger length; 19 | } 20 | 21 | /*! 22 | @brief Designated Initializer. Initializes a reader with a given string. 23 | @details Designated Initializer. 24 | @param s string from which to read 25 | @result an initialized reader 26 | */ 27 | - (id)initWithString:(NSString *)s; 28 | 29 | /*! 30 | @brief Read a single character 31 | @result The character read, or -1 if the end of the stream has been reached 32 | */ 33 | - (NSInteger)read; 34 | 35 | /*! 36 | @brief Push back a single character 37 | @details moves the cursor back one position 38 | */ 39 | - (void)unread; 40 | 41 | /*! 42 | @property string 43 | @brief This reader's string. 44 | */ 45 | @property (nonatomic, retain) NSString *string; 46 | @end 47 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDReader.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDReader.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 1/21/06. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDReader.h" 10 | 11 | @implementation TDReader 12 | 13 | - (id)init { 14 | return [self initWithString:nil]; 15 | } 16 | 17 | 18 | - (id)initWithString:(NSString *)s { 19 | self = [super init]; 20 | if (self) { 21 | self.string = s; 22 | } 23 | return self; 24 | } 25 | 26 | 27 | - (void)dealloc { 28 | self.string = nil; 29 | [super dealloc]; 30 | } 31 | 32 | 33 | - (NSString *)string { 34 | return string; 35 | } 36 | 37 | 38 | - (void)setString:(NSString *)s { 39 | if (string != s) { 40 | [string release]; 41 | string = [s retain]; 42 | length = string.length; 43 | } 44 | // reset cursor 45 | cursor = 0; 46 | } 47 | 48 | 49 | - (NSInteger)read { 50 | if (0 == length || cursor > length - 1) { 51 | return -1; 52 | } 53 | return [string characterAtIndex:cursor++]; 54 | } 55 | 56 | 57 | - (void)unread { 58 | cursor = (0 == cursor) ? 0 : cursor - 1; 59 | } 60 | 61 | @end 62 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDRepetition.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDRepetition.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 7/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDRepetition.h" 10 | #import "TDAssembly.h" 11 | 12 | @interface TDParser () 13 | - (NSSet *)matchAndAssemble:(NSSet *)inAssemblies; 14 | @end 15 | 16 | @interface TDRepetition () 17 | @property (nonatomic, readwrite, retain) TDParser *subparser; 18 | @end 19 | 20 | @implementation TDRepetition 21 | 22 | + (id)repetitionWithSubparser:(TDParser *)p { 23 | return [[[self alloc] initWithSubparser:p] autorelease]; 24 | } 25 | 26 | 27 | - (id)init { 28 | return [self initWithSubparser:nil]; 29 | } 30 | 31 | 32 | - (id)initWithSubparser:(TDParser *)p { 33 | //NSParameterAssert(p); 34 | self = [super init]; 35 | if (self) { 36 | self.subparser = p; 37 | } 38 | return self; 39 | } 40 | 41 | 42 | - (void)dealloc { 43 | self.subparser = nil; 44 | self.preassembler = nil; 45 | self.preassemblerSelector = nil; 46 | [super dealloc]; 47 | } 48 | 49 | 50 | - (void)setPreassembler:(id)a selector:(SEL)sel { 51 | self.preassembler = a; 52 | self.preassemblerSelector = sel; 53 | } 54 | 55 | 56 | - (NSSet *)allMatchesFor:(NSSet *)inAssemblies { 57 | NSParameterAssert(inAssemblies); 58 | if (preassembler) { 59 | NSAssert2([preassembler respondsToSelector:preassemblerSelector], @"provided preassembler %@ should respond to %@", preassembler, NSStringFromSelector(preassemblerSelector)); 60 | for (TDAssembly *a in inAssemblies) { 61 | [preassembler performSelector:preassemblerSelector withObject:a]; 62 | } 63 | } 64 | 65 | //NSMutableSet *outAssemblies = [[[NSSet alloc] initWithSet:inAssemblies copyItems:YES] autorelease]; 66 | NSMutableSet *outAssemblies = [[inAssemblies mutableCopy] autorelease]; 67 | 68 | NSSet *s = inAssemblies; 69 | while (s.count) { 70 | s = [subparser matchAndAssemble:s]; 71 | [outAssemblies unionSet:s]; 72 | } 73 | 74 | return outAssemblies; 75 | } 76 | 77 | @synthesize subparser; 78 | @synthesize preassembler; 79 | @synthesize preassemblerSelector; 80 | @end 81 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDReservedWord.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDReservedWord.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 8/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TDWord.h" 11 | 12 | @interface TDReservedWord : TDWord { 13 | 14 | } 15 | 16 | + (void)setReservedWords:(NSArray *)inWords; 17 | @end 18 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDReservedWord.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDReservedWord.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 8/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDReservedWord.h" 10 | #import "TDToken.h" 11 | 12 | static NSArray *sTDReservedWords = nil; 13 | 14 | @interface TDReservedWord () 15 | + (NSArray *)reservedWords; 16 | @end 17 | 18 | @implementation TDReservedWord 19 | 20 | + (NSArray *)reservedWords { 21 | return [[sTDReservedWords retain] autorelease]; 22 | } 23 | 24 | 25 | + (void)setReservedWords:(NSArray *)inWords { 26 | if (inWords != sTDReservedWords) { 27 | [sTDReservedWords autorelease]; 28 | sTDReservedWords = [inWords copy]; 29 | } 30 | } 31 | 32 | 33 | - (BOOL)qualifies:(id)obj { 34 | TDToken *tok = (TDToken *)obj; 35 | if (!tok.isWord) { 36 | return NO; 37 | } 38 | 39 | NSString *s = tok.stringValue; 40 | return s.length && [[TDReservedWord reservedWords] containsObject:s]; 41 | } 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDScientificNumberState.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDScientificNumberState.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 8/25/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDNumberState.h" 10 | 11 | /*! 12 | @class TDScientificNumberState 13 | @brief A TDScientificNumberState object returns a number from a reader. 14 | @details

This state's idea of a number expands on its superclass, allowing an 'e' followed by an integer to represent 10 to the indicated power. For example, this state will recognize 1e2 as equaling 100.

15 |

This class exists primarily to show how to introduce a new tokenizing state.

16 | */ 17 | @interface TDScientificNumberState : TDNumberState { 18 | CGFloat exp; 19 | BOOL negativeExp; 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDScientificNumberState.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDScientificNumberState.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 8/25/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDScientificNumberState.h" 10 | #import "TDReader.h" 11 | 12 | @interface TDTokenizerState () 13 | - (void)append:(NSInteger)c; 14 | @end 15 | 16 | @interface TDNumberState () 17 | - (CGFloat)absorbDigitsFromReader:(TDReader *)r isFraction:(BOOL)isFraction; 18 | - (void)parseRightSideFromReader:(TDReader *)r; 19 | - (void)reset:(NSInteger)cin; 20 | - (CGFloat)value; 21 | @end 22 | 23 | @implementation TDScientificNumberState 24 | 25 | - (void)parseRightSideFromReader:(TDReader *)r { 26 | NSParameterAssert(r); 27 | [super parseRightSideFromReader:r]; 28 | if ('e' == c || 'E' == c) { 29 | NSInteger e = c; 30 | c = [r read]; 31 | 32 | BOOL hasExp = isdigit((int)c); 33 | negativeExp = ('-' == c); 34 | BOOL positiveExp = ('+' == c); 35 | 36 | if (!hasExp && (negativeExp || positiveExp)) { 37 | c = [r read]; 38 | hasExp = isdigit((int)c); 39 | } 40 | if (-1 != c) { 41 | [r unread]; 42 | } 43 | if (hasExp) { 44 | [self append:e]; 45 | if (negativeExp) { 46 | [self append:'-']; 47 | } else if (positiveExp) { 48 | [self append:'+']; 49 | } 50 | c = [r read]; 51 | exp = [super absorbDigitsFromReader:r isFraction:NO]; 52 | } 53 | } 54 | } 55 | 56 | 57 | - (void)reset:(NSInteger)cin { 58 | [super reset:cin]; 59 | exp = (CGFloat)0.0; 60 | negativeExp = NO; 61 | } 62 | 63 | 64 | - (CGFloat)value { 65 | CGFloat result = (CGFloat)floatValue; 66 | 67 | NSUInteger i = 0; 68 | for ( ; i < exp; i++) { 69 | if (negativeExp) { 70 | result /= (CGFloat)10.0; 71 | } else { 72 | result *= (CGFloat)10.0; 73 | } 74 | } 75 | 76 | return (CGFloat)result; 77 | } 78 | 79 | @end 80 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDSequence.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDSequence.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 7/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TDCollectionParser.h" 11 | 12 | /*! 13 | @class TDSequence 14 | @brief A TDSequence object is a collection of parsers, all of which must in turn match against an assembly for this parser to successfully match. 15 | */ 16 | @interface TDSequence : TDCollectionParser { 17 | 18 | } 19 | 20 | /*! 21 | @brief Convenience factory method for initializing an autoreleased TDSequence parser. 22 | @result an initialized autoreleased TDSequence parser. 23 | */ 24 | + (id)sequence; 25 | @end 26 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDSequence.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDSequence.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 7/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDSequence.h" 10 | #import "TDAssembly.h" 11 | 12 | @interface TDParser () 13 | - (NSSet *)matchAndAssemble:(NSSet *)inAssemblies; 14 | @end 15 | 16 | @implementation TDSequence 17 | 18 | + (id)sequence { 19 | return [[[self alloc] init] autorelease]; 20 | } 21 | 22 | 23 | - (NSSet *)allMatchesFor:(NSSet *)inAssemblies { 24 | NSParameterAssert(inAssemblies); 25 | NSSet *outAssemblies = inAssemblies; 26 | 27 | for (TDParser *p in subparsers) { 28 | outAssemblies = [p matchAndAssemble:outAssemblies]; 29 | if (!outAssemblies.count) { 30 | break; 31 | } 32 | } 33 | 34 | return outAssemblies; 35 | } 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDSignificantWhitespaceState.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDSignificantWhitespaceState.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 7/14/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TDWhitespaceState.h" 11 | #import "TDToken.h" 12 | 13 | // NOTE: this class is not currently in use or included in the Framework. It is an example of how to add a new token type 14 | 15 | static const NSInteger TDTokenTypeWhitespace = 5; 16 | 17 | @interface TDToken (TDSignificantWhitespaceStateAdditions) 18 | @property (nonatomic, readonly, getter=isWhitespace) BOOL whitespace; 19 | @end 20 | 21 | @interface TDSignificantWhitespaceState : TDWhitespaceState { 22 | 23 | } 24 | @end 25 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDSignificantWhitespaceState.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDSignificantWhitespaceState.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 7/14/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDSignificantWhitespaceState.h" 10 | #import "TDReader.h" 11 | #import "TDTokenizer.h" 12 | #import "TDToken.h" 13 | 14 | @interface TDTokenizerState () 15 | - (void)reset; 16 | - (void)append:(NSInteger)c; 17 | - (NSString *)bufferedString; 18 | @end 19 | 20 | @implementation TDToken (TDSignificantWhitespaceStateAdditions) 21 | 22 | - (BOOL)isWhitespace { 23 | return self.tokenType == TDTokenTypeWhitespace; 24 | } 25 | 26 | 27 | - (NSString *)debugDescription { 28 | NSString *typeString = nil; 29 | if (self.isNumber) { 30 | typeString = @"Number"; 31 | } else if (self.isQuotedString) { 32 | typeString = @"Quoted String"; 33 | } else if (self.isSymbol) { 34 | typeString = @"Symbol"; 35 | } else if (self.isWord) { 36 | typeString = @"Word"; 37 | } else if (self.isWhitespace) { 38 | typeString = @"Whitespace"; 39 | } 40 | return [NSString stringWithFormat:@"<%@ %C%@%C>", typeString, 0x00ab, self.value, 0x00bb]; 41 | } 42 | 43 | @end 44 | 45 | @implementation TDSignificantWhitespaceState 46 | 47 | - (void)dealloc { 48 | [super dealloc]; 49 | } 50 | 51 | 52 | - (TDToken *)nextTokenFromReader:(TDReader *)r startingWith:(NSInteger)cin tokenizer:(TDTokenizer *)t { 53 | NSParameterAssert(r); 54 | [self reset]; 55 | 56 | c = cin; 57 | while ([self isWhitespaceChar:c]) { 58 | [self append:c]; 59 | c = [r read]; 60 | } 61 | if (c != -1) { 62 | [r unread]; 63 | } 64 | 65 | return [TDToken tokenWithTokenType:TDTokenTypeWhitespace stringValue:[self bufferedString] floatValue:0.0]; 66 | } 67 | 68 | @end 69 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDSingleLineCommentState.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDSingleLineCommentState.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 12/28/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TDTokenizerState.h" 11 | 12 | @interface TDSingleLineCommentState : TDTokenizerState { 13 | NSMutableArray *startSymbols; 14 | NSString *currentStartSymbol; 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDSingleLineCommentState.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDSingleLineCommentState.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 12/28/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDSingleLineCommentState.h" 10 | #import "TDCommentState.h" 11 | #import "TDReader.h" 12 | #import "TDTokenizer.h" 13 | #import "TDToken.h" 14 | 15 | @interface TDTokenizerState () 16 | - (void)reset; 17 | - (void)append:(NSInteger)c; 18 | - (void)appendString:(NSString *)s; 19 | - (NSString *)bufferedString; 20 | @end 21 | 22 | @interface TDSingleLineCommentState () 23 | - (void)addStartSymbol:(NSString *)start; 24 | - (void)removeStartSymbol:(NSString *)start; 25 | @property (nonatomic, retain) NSMutableArray *startSymbols; 26 | @property (nonatomic, retain) NSString *currentStartSymbol; 27 | @end 28 | 29 | @implementation TDSingleLineCommentState 30 | 31 | - (id)init { 32 | self = [super init]; 33 | if (self) { 34 | self.startSymbols = [NSMutableArray array]; 35 | } 36 | return self; 37 | } 38 | 39 | 40 | - (void)dealloc { 41 | self.startSymbols = nil; 42 | self.currentStartSymbol = nil; 43 | [super dealloc]; 44 | } 45 | 46 | 47 | - (void)addStartSymbol:(NSString *)start { 48 | NSParameterAssert(start.length); 49 | [startSymbols addObject:start]; 50 | } 51 | 52 | 53 | - (void)removeStartSymbol:(NSString *)start { 54 | NSParameterAssert(start.length); 55 | [startSymbols removeObject:start]; 56 | } 57 | 58 | 59 | - (TDToken *)nextTokenFromReader:(TDReader *)r startingWith:(NSInteger)cin tokenizer:(TDTokenizer *)t { 60 | NSParameterAssert(r); 61 | NSParameterAssert(t); 62 | 63 | BOOL reportTokens = t.commentState.reportsCommentTokens; 64 | if (reportTokens) { 65 | [self reset]; 66 | if (currentStartSymbol.length > 1) { 67 | [self appendString:currentStartSymbol]; 68 | } 69 | } 70 | 71 | NSInteger c; 72 | while (1) { 73 | c = [r read]; 74 | if ('\n' == c || '\r' == c || -1 == c) { 75 | break; 76 | } 77 | if (reportTokens) { 78 | [self append:c]; 79 | } 80 | } 81 | 82 | if (-1 != c) { 83 | [r unread]; 84 | } 85 | 86 | self.currentStartSymbol = nil; 87 | 88 | if (reportTokens) { 89 | return [TDToken tokenWithTokenType:TDTokenTypeComment stringValue:[self bufferedString] floatValue:0.0]; 90 | } else { 91 | return [t nextToken]; 92 | } 93 | } 94 | 95 | @synthesize startSymbols; 96 | @synthesize currentStartSymbol; 97 | @end 98 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDSpecificChar.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDSpecificChar.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 8/14/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDTerminal.h" 10 | 11 | /*! 12 | @class TDSpecificChar 13 | @brief A TDSpecificChar matches a specified character from a character assembly. 14 | @details -[TDSpecificChar qualifies:] returns true if an assembly's next element is equal to the character this object was constructed with. 15 | */ 16 | @interface TDSpecificChar : TDTerminal { 17 | } 18 | 19 | /*! 20 | @brief Convenience factory method for initializing an autoreleased TDSpecificChar parser. 21 | @param c the character this object should match 22 | @result an initialized autoreleased TDSpecificChar parser. 23 | */ 24 | + (id)specificCharWithChar:(NSInteger)c; 25 | 26 | /*! 27 | @brief Designated Initializer. Initializes a TDSpecificChar parser. 28 | @param c the character this object should match 29 | @result an initialized TDSpecificChar parser. 30 | */ 31 | - (id)initWithSpecificChar:(NSInteger)c; 32 | @end 33 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDSpecificChar.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDSpecificChar.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 8/14/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDSpecificChar.h" 10 | 11 | @implementation TDSpecificChar 12 | 13 | + (id)specificCharWithChar:(NSInteger)c { 14 | return [[[self alloc] initWithSpecificChar:c] autorelease]; 15 | } 16 | 17 | 18 | - (id)initWithSpecificChar:(NSInteger)c { 19 | self = [super initWithString:[NSString stringWithFormat:@"%C", (unsigned short)c]]; 20 | if (self) { 21 | } 22 | return self; 23 | } 24 | 25 | 26 | - (BOOL)qualifies:(id)obj { 27 | NSInteger c = [obj integerValue]; 28 | return c == [string characterAtIndex:0]; 29 | } 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDSymbol.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDSymbol.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 7/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TDTerminal.h" 11 | 12 | @class TDToken; 13 | 14 | /*! 15 | @class TDSymbol 16 | @brief A TDSymbol matches a specific sequence, such as <, or <= that a tokenizer returns as a symbol. 17 | */ 18 | @interface TDSymbol : TDTerminal { 19 | TDToken *symbol; 20 | } 21 | 22 | /*! 23 | @brief Convenience factory method for initializing an autoreleased TDSymbol object with a nil string value. 24 | @result an initialized autoreleased TDSymbol object with a nil string value 25 | */ 26 | + (id)symbol; 27 | 28 | /*! 29 | @brief Convenience factory method for initializing an autoreleased TDSymbol object with s as a string value. 30 | @param s the string represented by this symbol 31 | @result an initialized autoreleased TDSymbol object with s as a string value 32 | */ 33 | + (id)symbolWithString:(NSString *)s; 34 | @end 35 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDSymbol.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDSymbol.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 7/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDSymbol.h" 10 | #import "TDToken.h" 11 | 12 | @interface TDSymbol () 13 | @property (nonatomic, retain) TDToken *symbol; 14 | @end 15 | 16 | @implementation TDSymbol 17 | 18 | + (id)symbol { 19 | return [[[self alloc] initWithString:nil] autorelease]; 20 | } 21 | 22 | 23 | + (id)symbolWithString:(NSString *)s { 24 | return [[[self alloc] initWithString:s] autorelease]; 25 | } 26 | 27 | 28 | - (id)initWithString:(NSString *)s { 29 | self = [super initWithString:s]; 30 | if (self) { 31 | if (s.length) { 32 | self.symbol = [TDToken tokenWithTokenType:TDTokenTypeSymbol stringValue:s floatValue:0.0]; 33 | } 34 | } 35 | return self; 36 | } 37 | 38 | 39 | - (void)dealloc { 40 | self.symbol = nil; 41 | [super dealloc]; 42 | } 43 | 44 | 45 | - (BOOL)qualifies:(id)obj { 46 | if (symbol) { 47 | return [symbol isEqual:obj]; 48 | } else { 49 | TDToken *tok = (TDToken *)obj; 50 | return tok.isSymbol; 51 | } 52 | } 53 | 54 | 55 | - (NSString *)description { 56 | NSString *className = [[self className] substringFromIndex:2]; 57 | if (name.length) { 58 | if (symbol) { 59 | return [NSString stringWithFormat:@"%@ (%@) %@", className, name, symbol.stringValue]; 60 | } else { 61 | return [NSString stringWithFormat:@"%@ (%@)", className, name]; 62 | } 63 | } else { 64 | if (symbol) { 65 | return [NSString stringWithFormat:@"%@ %@", className, symbol.stringValue]; 66 | } else { 67 | return [NSString stringWithFormat:@"%@", className]; 68 | } 69 | } 70 | } 71 | 72 | @synthesize symbol; 73 | @end 74 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDSymbolNode.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDSymbolNode.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 1/20/06. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDSymbolNode.h" 10 | #import "TDSymbolRootNode.h" 11 | 12 | @interface TDSymbolNode () 13 | @property (nonatomic, readwrite, retain) NSString *ancestry; 14 | @property (nonatomic, assign) TDSymbolNode *parent; // this must be 'assign' to avoid retain loop leak 15 | @property (nonatomic, retain) NSMutableDictionary *children; 16 | @property (nonatomic) NSInteger character; 17 | @property (nonatomic, retain) NSString *string; 18 | 19 | - (void)determineAncestry; 20 | @end 21 | 22 | @implementation TDSymbolNode 23 | 24 | - (id)initWithParent:(TDSymbolNode *)p character:(NSInteger)c { 25 | self = [super init]; 26 | if (self) { 27 | self.parent = p; 28 | self.character = c; 29 | self.children = [NSMutableDictionary dictionary]; 30 | 31 | // this private property is an optimization. 32 | // cache the NSString for the char to prevent it being constantly recreated in -determinAncestry 33 | self.string = [NSString stringWithFormat:@"%C", (unsigned short)character]; 34 | 35 | [self determineAncestry]; 36 | } 37 | return self; 38 | } 39 | 40 | 41 | - (void)dealloc { 42 | parent = nil; // makes clang static analyzer happy 43 | self.ancestry = nil; 44 | self.string = nil; 45 | self.children = nil; 46 | [super dealloc]; 47 | } 48 | 49 | 50 | - (void)determineAncestry { 51 | if (-1 == parent.character) { // optimization for sinlge-char symbol (parent is symbol root node) 52 | self.ancestry = string; 53 | } else { 54 | NSMutableString *result = [NSMutableString string]; 55 | 56 | TDSymbolNode *n = self; 57 | while (-1 != n.character) { 58 | [result insertString:n.string atIndex:0]; 59 | n = n.parent; 60 | } 61 | 62 | self.ancestry = [[result copy] autorelease]; // assign an immutable copy 63 | } 64 | } 65 | 66 | 67 | - (NSString *)description { 68 | return [NSString stringWithFormat:@"", self.ancestry]; 69 | } 70 | 71 | @synthesize ancestry; 72 | @synthesize parent; 73 | @synthesize character; 74 | @synthesize string; 75 | @synthesize children; 76 | @end 77 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDSymbolRootNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDSymbolRootNode.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 1/20/06. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TDSymbolNode.h" 11 | 12 | @class TDReader; 13 | 14 | /*! 15 | @class TDSymbolRootNode 16 | @brief This class is a special case of a TDSymbolNode. 17 | @details This class is a special case of a TDSymbolNode. A TDSymbolRootNode object has no symbol of its own, but has children that represent all possible symbols. 18 | */ 19 | @interface TDSymbolRootNode : TDSymbolNode { 20 | } 21 | 22 | /*! 23 | @brief Adds the given string as a multi-character symbol. 24 | @param s a multi-character symbol that should be recognized as a single symbol token by this state 25 | */ 26 | - (void)add:(NSString *)s; 27 | 28 | /*! 29 | @brief Removes the given string as a multi-character symbol. 30 | @param s a multi-character symbol that should no longer be recognized as a single symbol token by this state 31 | @details if s was never added as a multi-character symbol, this has no effect 32 | */ 33 | - (void)remove:(NSString *)s; 34 | 35 | /*! 36 | @brief Return a symbol string from a reader. 37 | @param r the reader from which to read 38 | @param cin the character from witch to start 39 | @result a symbol string from a reader 40 | */ 41 | - (NSString *)nextSymbol:(TDReader *)r startingWith:(NSInteger)cin; 42 | @end 43 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDSymbolState.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDSymbolState.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 1/20/06. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TDTokenizerState.h" 11 | 12 | @class TDSymbolRootNode; 13 | 14 | /*! 15 | @class TDSymbolState 16 | @brief The idea of a symbol is a character that stands on its own, such as an ampersand or a parenthesis. 17 | @details

The idea of a symbol is a character that stands on its own, such as an ampersand or a parenthesis. For example, when tokenizing the expression (isReady)& (isWilling) , a typical tokenizer would return 7 tokens, including one for each parenthesis and one for the ampersand. Thus a series of symbols such as )&( becomes three tokens, while a series of letters such as isReady becomes a single word token.

18 |

Multi-character symbols are an exception to the rule that a symbol is a standalone character. For example, a tokenizer may want less-than-or-equals to tokenize as a single token. This class provides a method for establishing which multi-character symbols an object of this class should treat as single symbols. This allows, for example, "cat <= dog" to tokenize as three tokens, rather than splitting the less-than and equals symbols into separate tokens.

19 |

By default, this state recognizes the following multi- character symbols: !=, :-, <=, >=

20 | */ 21 | @interface TDSymbolState : TDTokenizerState { 22 | TDSymbolRootNode *rootNode; 23 | NSMutableArray *addedSymbols; 24 | } 25 | 26 | /*! 27 | @brief Adds the given string as a multi-character symbol. 28 | @param s a multi-character symbol that should be recognized as a single symbol token by this state 29 | */ 30 | - (void)add:(NSString *)s; 31 | 32 | /*! 33 | @brief Removes the given string as a multi-character symbol. 34 | @details If s was never added as a multi-character symbol, this has no effect. 35 | @param s a multi-character symbol that should no longer be recognized as a single symbol token by this state 36 | */ 37 | - (void)remove:(NSString *)s; 38 | @end 39 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDSymbolState.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDSymbolState.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 1/20/06. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDSymbolState.h" 10 | #import "TDToken.h" 11 | #import "TDSymbolRootNode.h" 12 | #import "TDReader.h" 13 | #import "TDTokenizer.h" 14 | 15 | @interface TDSymbolState () 16 | @property (nonatomic, retain) TDSymbolRootNode *rootNode; 17 | @property (nonatomic, retain) NSMutableArray *addedSymbols; 18 | @end 19 | 20 | @implementation TDSymbolState 21 | 22 | - (id)init { 23 | self = [super init]; 24 | if (self) { 25 | self.rootNode = [[[TDSymbolRootNode alloc] init] autorelease]; 26 | self.addedSymbols = [NSMutableArray array]; 27 | } 28 | return self; 29 | } 30 | 31 | 32 | - (void)dealloc { 33 | self.rootNode = nil; 34 | self.addedSymbols = nil; 35 | [super dealloc]; 36 | } 37 | 38 | 39 | - (TDToken *)nextTokenFromReader:(TDReader *)r startingWith:(NSInteger)cin tokenizer:(TDTokenizer *)t { 40 | NSParameterAssert(r); 41 | NSString *symbol = [rootNode nextSymbol:r startingWith:cin]; 42 | NSInteger len = symbol.length; 43 | 44 | if (0 == len || (len > 1 && [addedSymbols containsObject:symbol])) { 45 | return [TDToken tokenWithTokenType:TDTokenTypeSymbol stringValue:symbol floatValue:0.0]; 46 | } else { 47 | NSInteger i = 0; 48 | for ( ; i < len - 1; i++) { 49 | [r unread]; 50 | } 51 | return [TDToken tokenWithTokenType:TDTokenTypeSymbol stringValue:[NSString stringWithFormat:@"%C", (unsigned short)cin] floatValue:0.0]; 52 | } 53 | } 54 | 55 | 56 | - (void)add:(NSString *)s { 57 | NSParameterAssert(s); 58 | [rootNode add:s]; 59 | [addedSymbols addObject:s]; 60 | } 61 | 62 | 63 | - (void)remove:(NSString *)s { 64 | NSParameterAssert(s); 65 | [rootNode remove:s]; 66 | [addedSymbols removeObject:s]; 67 | } 68 | 69 | @synthesize rootNode; 70 | @synthesize addedSymbols; 71 | @end 72 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDTerminal.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDTerminal.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 7/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TDParser.h" 11 | 12 | @class TDToken; 13 | 14 | /*! 15 | @class TDTerminal 16 | @brief An Abstract Class. A TDTerminal is a parser that is not a composition of other parsers. 17 | */ 18 | @interface TDTerminal : TDParser { 19 | NSString *string; 20 | BOOL discardFlag; 21 | } 22 | 23 | /*! 24 | @brief Designated Initializer for all concrete TDTerminal subclasses. 25 | @details Note this is an abtract class and this method must be called on a concrete subclass. 26 | @param s the string matched by this parser 27 | @result an initialized TDTerminal subclass object 28 | */ 29 | - (id)initWithString:(NSString *)s; 30 | 31 | /*! 32 | @brief By default, terminals push themselves upon a assembly's stack, after a successful match. This method will turn off that behavior. 33 | @details This method returns this parser as a convenience for chainging-style usage. 34 | @result this parser, returned for chaining/convenience 35 | */ 36 | - (TDTerminal *)discard; 37 | 38 | /*! 39 | @property string 40 | @brief the string matched by this parser. 41 | */ 42 | @property (nonatomic, readonly, copy) NSString *string; 43 | @end 44 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDTerminal.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDTerminal.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 7/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDTerminal.h" 10 | #import "TDAssembly.h" 11 | #import "TDToken.h" 12 | 13 | @interface TDTerminal () 14 | - (TDAssembly *)matchOneAssembly:(TDAssembly *)inAssembly; 15 | - (BOOL)qualifies:(id)obj; 16 | 17 | @property (nonatomic, readwrite, copy) NSString *string; 18 | @end 19 | 20 | @implementation TDTerminal 21 | 22 | - (id)init { 23 | return [self initWithString:nil]; 24 | } 25 | 26 | 27 | - (id)initWithString:(NSString *)s { 28 | self = [super init]; 29 | if (self) { 30 | self.string = s; 31 | } 32 | return self; 33 | } 34 | 35 | 36 | - (void)dealloc { 37 | self.string = nil; 38 | [super dealloc]; 39 | } 40 | 41 | 42 | - (NSSet *)allMatchesFor:(NSSet *)inAssemblies { 43 | NSParameterAssert(inAssemblies); 44 | NSMutableSet *outAssemblies = [NSMutableSet set]; 45 | 46 | for (TDAssembly *a in inAssemblies) { 47 | TDAssembly *b = [self matchOneAssembly:a]; 48 | if (b) { 49 | [outAssemblies addObject:b]; 50 | } 51 | } 52 | 53 | return outAssemblies; 54 | } 55 | 56 | 57 | - (TDAssembly *)matchOneAssembly:(TDAssembly *)inAssembly { 58 | NSParameterAssert(inAssembly); 59 | if (![inAssembly hasMore]) { 60 | return nil; 61 | } 62 | 63 | TDAssembly *outAssembly = nil; 64 | 65 | if ([self qualifies:[inAssembly peek]]) { 66 | outAssembly = [[inAssembly copy] autorelease]; 67 | id obj = [outAssembly next]; 68 | if (!discardFlag) { 69 | [outAssembly push:obj]; 70 | } 71 | } 72 | 73 | return outAssembly; 74 | } 75 | 76 | 77 | - (BOOL)qualifies:(id)obj { 78 | NSAssert1(0, @"-[TDTerminal %@] must be overriden", NSStringFromSelector(_cmd)); 79 | return NO; 80 | } 81 | 82 | 83 | - (TDTerminal *)discard { 84 | discardFlag = YES; 85 | return self; 86 | } 87 | 88 | @synthesize string; 89 | @end 90 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDTokenArraySource.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDTokenArraySource.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 12/11/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class TDTokenizer; 12 | @class TDToken; 13 | 14 | /*! 15 | @class TDTokenArraySource 16 | @brief A TokenArraySource is a handy utility that enumerates over a specified reader, returning NSArrays of TDTokens delimited by a specified delimiter. 17 | @details For example, 18 | 19 | @code 20 | NSString *s = @"I came; I saw; I left in peace;"; 21 | 22 | TDTokenizer *t = [TDTokenizer tokenizerWithString:s]; 23 | TDTokenArraySource *src = [[[TDTokenArraySource alloc] initWithTokenizer:t delimiter:@";"] autorelease]; 24 | 25 | while ([src hasMore]) { 26 | NSLog(@"%@", [src nextTokenArray]); 27 | } 28 | @endcode 29 | 30 | prints out: 31 | 32 | @code 33 | I came 34 | I saw 35 | I left in peace 36 | @endcode 37 | */ 38 | @interface TDTokenArraySource : NSObject { 39 | TDTokenizer *tokenizer; 40 | NSString *delimiter; 41 | TDToken *nextToken; 42 | } 43 | 44 | /*! 45 | @brief Constructs a TDTokenArraySource that will read an NSArrays of TDTokens using the specified tokenizer, delimited by the specified delimiter. 46 | @param tokenizer a tokenizer to read tokens from 47 | @param delimiter the character(s) that fences off where one array of tokens ends and the next begins 48 | */ 49 | - (id)initWithTokenizer:(TDTokenizer *)t delimiter:(NSString *)s; 50 | 51 | /*! 52 | @brief true if the source has more arrays of tokens. 53 | @result true, if the source has more arrays of tokens that have not yet been popped with -nextTokenArray 54 | */ 55 | - (BOOL)hasMore; 56 | 57 | /*! 58 | @brief Returns the next array of tokens from the source. 59 | @result the next array of tokens from the source 60 | */ 61 | - (NSArray *)nextTokenArray; 62 | @end 63 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDTokenArraySource.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDTokenArraySource.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 12/11/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDTokenArraySource.h" 10 | #import "TDToken.h" 11 | #import "TDTokenizer.h" 12 | 13 | @interface TDTokenArraySource () 14 | @property (nonatomic, retain) TDTokenizer *tokenizer; 15 | @property (nonatomic, retain) NSString *delimiter; 16 | @property (nonatomic, retain) TDToken *nextToken; 17 | @end 18 | 19 | @implementation TDTokenArraySource 20 | 21 | - (id)init { 22 | return [self initWithTokenizer:nil delimiter:nil]; 23 | } 24 | 25 | 26 | - (id)initWithTokenizer:(TDTokenizer *)t delimiter:(NSString *)s { 27 | NSParameterAssert(t); 28 | NSParameterAssert(s); 29 | self = [super init]; 30 | if (self) { 31 | self.tokenizer = t; 32 | self.delimiter = s; 33 | } 34 | return self; 35 | } 36 | 37 | 38 | - (void)dealloc { 39 | self.tokenizer = nil; 40 | self.delimiter = nil; 41 | self.nextToken = nil; 42 | [super dealloc]; 43 | } 44 | 45 | 46 | - (BOOL)hasMore { 47 | if (!nextToken) { 48 | self.nextToken = [tokenizer nextToken]; 49 | } 50 | 51 | return ([TDToken EOFToken] != nextToken); 52 | } 53 | 54 | 55 | - (NSArray *)nextTokenArray { 56 | if (![self hasMore]) { 57 | return nil; 58 | } 59 | 60 | NSMutableArray *res = [NSMutableArray arrayWithObject:nextToken]; 61 | self.nextToken = nil; 62 | 63 | TDToken *eof = [TDToken EOFToken]; 64 | TDToken *tok = nil; 65 | 66 | while ((tok = [tokenizer nextToken]) != eof) { 67 | if ([tok.stringValue isEqualToString:delimiter]) { 68 | break; // discard delimiter tok 69 | } 70 | [res addObject:tok]; 71 | } 72 | 73 | //return [[res copy] autorelease]; 74 | return res; // optimization 75 | } 76 | 77 | @synthesize tokenizer; 78 | @synthesize delimiter; 79 | @synthesize nextToken; 80 | @end 81 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDTokenAssembly.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDTokenAssembly.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 7/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDAssembly.h" 10 | 11 | @class TDTokenizer; 12 | 13 | /*! 14 | @class TDTokenAssembly 15 | @brief A TDTokenAssembly is a TDAssembly whose elements are TDTokens. 16 | @details TDTokens are, roughly, the chunks of text that a TDTokenizer returns. 17 | */ 18 | @interface TDTokenAssembly : TDAssembly { 19 | TDTokenizer *tokenizer; 20 | NSArray *tokens; 21 | BOOL preservesWhitespaceTokens; 22 | } 23 | 24 | /*! 25 | @brief Convenience factory method for initializing an autoreleased assembly with the tokenizer t and its string 26 | @param t tokenizer whose string will be worked on 27 | @result an initialized autoreleased assembly 28 | */ 29 | + (id)assemblyWithTokenizer:(TDTokenizer *)t; 30 | 31 | /*! 32 | @brief Initializes an assembly with the tokenizer t and its string 33 | @param t tokenizer whose string will be worked on 34 | @result an initialized assembly 35 | */ 36 | - (id)initWithTokenzier:(TDTokenizer *)t; 37 | 38 | /*! 39 | @brief Convenience factory method for initializing an autoreleased assembly with the token array a and its string 40 | @param a token array whose string will be worked on 41 | @result an initialized autoreleased assembly 42 | */ 43 | + (id)assemblyWithTokenArray:(NSArray *)a; 44 | 45 | /*! 46 | @brief Initializes an assembly with the token array a and its string 47 | @param a token array whose string will be worked on 48 | @result an initialized assembly 49 | */ 50 | - (id)initWithTokenArray:(NSArray *)a; 51 | 52 | /*! 53 | @property preservesWhitespaceTokens 54 | @brief If true, whitespace tokens retreived from this assembly's tokenizier will be silently placed on this assembly's stack without being reported by -next or -peek. Default is false. 55 | */ 56 | @property (nonatomic) BOOL preservesWhitespaceTokens; 57 | @end 58 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDTokenizerState.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDParseKitState.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 1/20/06. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #define TD_USE_MUTABLE_STRING_BUF 1 12 | 13 | @class TDToken; 14 | @class TDTokenizer; 15 | @class TDReader; 16 | 17 | /*! 18 | @class TDTokenizerState 19 | @brief A TDTokenizerState returns a token, given a reader, an initial character read from the reader, and a tokenizer that is conducting an overall tokenization of the reader. 20 | @details The tokenizer will typically have a character state table that decides which state to use, depending on an initial character. If a single character is insufficient, a state such as TDSlashState will read a second character, and may delegate to another state, such as TDSlashStarState. This prospect of delegation is the reason that the -nextToken method has a tokenizer argument. 21 | */ 22 | @interface TDTokenizerState : NSObject { 23 | #if TD_USE_MUTABLE_STRING_BUF 24 | NSMutableString *stringbuf; 25 | #else 26 | unichar *__strong charbuf; 27 | NSUInteger length; 28 | NSUInteger index; 29 | #endif 30 | } 31 | 32 | /*! 33 | @brief Return a token that represents a logical piece of a reader. 34 | @param r the reader from which to read additional characters 35 | @param cin the character that a tokenizer used to determine to use this state 36 | @param t the tokenizer currently powering the tokenization 37 | @result a token that represents a logical piece of the reader 38 | */ 39 | - (TDToken *)nextTokenFromReader:(TDReader *)r startingWith:(NSInteger)cin tokenizer:(TDTokenizer *)t; 40 | @end 41 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDTrack.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDTrack.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 8/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TDSequence.h" 11 | 12 | /*! 13 | @class TDTrack 14 | @brief A TDTrack is a sequence that throws a TDTrackException if the sequence begins but does not complete. 15 | @details If -[TDTrack allMatchesFor:] begins but does not complete, it throws a TDTrackException. 16 | */ 17 | @interface TDTrack : TDSequence { 18 | 19 | } 20 | 21 | /*! 22 | @brief Convenience factory method for initializing an autoreleased TDTrack parser. 23 | @result an initialized autoreleased TDTrack parser. 24 | */ 25 | + (id)track; 26 | @end 27 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDTrack.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDTrack.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 8/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDTrack.h" 10 | #import "TDAssembly.h" 11 | #import "TDTrackException.h" 12 | 13 | @interface TDParser () 14 | - (NSSet *)matchAndAssemble:(NSSet *)inAssemblies; 15 | - (TDAssembly *)best:(NSSet *)inAssemblies; 16 | @end 17 | 18 | @interface TDTrack () 19 | - (void)throwTrackExceptionWithPreviousState:(NSSet *)inAssemblies parser:(TDParser *)p; 20 | @end 21 | 22 | @implementation TDTrack 23 | 24 | + (id)track { 25 | return [[[self alloc] init] autorelease]; 26 | } 27 | 28 | 29 | - (NSSet *)allMatchesFor:(NSSet *)inAssemblies { 30 | NSParameterAssert(inAssemblies); 31 | BOOL inTrack = NO; 32 | NSSet *lastAssemblies = inAssemblies; 33 | NSSet *outAssemblies = inAssemblies; 34 | 35 | for (TDParser *p in subparsers) { 36 | outAssemblies = [p matchAndAssemble:outAssemblies]; 37 | if (!outAssemblies.count) { 38 | if (inTrack) { 39 | [self throwTrackExceptionWithPreviousState:lastAssemblies parser:p]; 40 | } 41 | break; 42 | } 43 | inTrack = YES; 44 | lastAssemblies = outAssemblies; 45 | } 46 | 47 | return outAssemblies; 48 | } 49 | 50 | 51 | - (void)throwTrackExceptionWithPreviousState:(NSSet *)inAssemblies parser:(TDParser *)p { 52 | TDAssembly *best = [self best:inAssemblies]; 53 | 54 | NSString *after = [best consumedObjectsJoinedByString:@" "]; 55 | if (!after.length) { 56 | after = @"-nothing-"; 57 | } 58 | 59 | NSString *expected = [p description]; 60 | 61 | id next = [best peek]; 62 | NSString *found = next ? [next description] : @"-nothing-"; 63 | 64 | NSString *reason = [NSString stringWithFormat:@"\n\nAfter : %@\nExpected : %@\nFound : %@\n\n", after, expected, found]; 65 | NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys: 66 | after, @"after", 67 | expected, @"expected", 68 | found, @"found", 69 | nil]; 70 | [[TDTrackException exceptionWithName:TDTrackExceptionName reason:reason userInfo:userInfo] raise]; 71 | } 72 | 73 | @end 74 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDTrackException.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDTrackException.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 10/14/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | extern NSString * const TDTrackExceptionName; 12 | 13 | /*! 14 | @class TDTrackException 15 | @brief Signals that a parser could not match text after a specific point. 16 | @details The userInfo for this exception contains the following keys:
17 |             after (NSString *) - some indication of what text was interpretable before this exception occurred
18 |             expected (NSString *) - some indication of what kind of thing was expected, such as a ')' token
19 |             found (NSString *) - the text element the thrower actually found when it expected something else
20 | */ 21 | @interface TDTrackException : NSException { 22 | 23 | } 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDTrackException.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDTrackException.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 10/14/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDTrackException.h" 10 | 11 | NSString * const TDTrackExceptionName = @"Track Exception"; 12 | 13 | @implementation TDTrackException 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDUppercaseWord.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDUppercaseWord.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 8/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TDWord.h" 11 | 12 | @interface TDUppercaseWord : TDWord { 13 | 14 | } 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDUppercaseWord.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDUppercaseWord.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 8/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDUppercaseWord.h" 10 | #import "TDToken.h" 11 | 12 | @implementation TDUppercaseWord 13 | 14 | - (BOOL)qualifies:(id)obj { 15 | TDToken *tok = (TDToken *)obj; 16 | if (!tok.isWord) { 17 | return NO; 18 | } 19 | 20 | NSString *s = tok.stringValue; 21 | return s.length && isupper([s characterAtIndex:0]); 22 | } 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDWhitespaceState.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDWhitespaceState.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 1/20/06. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TDTokenizerState.h" 11 | 12 | /*! 13 | @class TDWhitespaceState 14 | @brief A whitespace state ignores whitespace (such as blanks and tabs), and returns the tokenizer's next token. 15 | @details By default, all characters from 0 to 32 are whitespace. 16 | */ 17 | @interface TDWhitespaceState : TDTokenizerState { 18 | NSMutableArray *whitespaceChars; 19 | BOOL reportsWhitespaceTokens; 20 | } 21 | 22 | /*! 23 | @brief Informs whether the given character is recognized as whitespace (and therefore ignored) by this state. 24 | @param cin the character to check 25 | @result true if the given chracter is recognized as whitespace 26 | */ 27 | - (BOOL)isWhitespaceChar:(NSInteger)cin; 28 | 29 | /*! 30 | @brief Establish the given character range as whitespace to ignore. 31 | @param yn true if the given character range is whitespace 32 | @param start the "start" character. e.g. 'a' or 65. 33 | @param end the "end" character. 'z' or 90. 34 | */ 35 | - (void)setWhitespaceChars:(BOOL)yn from:(NSInteger)start to:(NSInteger)end; 36 | 37 | /*! 38 | @property reportsWhitespaceTokens 39 | @brief determines whether a TDTokenizer associated with this state reports or silently consumes whitespace tokens. default is NO which causes silent consumption of whitespace chars 40 | */ 41 | @property (nonatomic) BOOL reportsWhitespaceTokens; 42 | @end 43 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDWord.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDWord.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 7/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TDTerminal.h" 11 | 12 | /*! 13 | @class TDWord 14 | @brief A TDWord matches a word from a token assembly. 15 | */ 16 | @interface TDWord : TDTerminal { 17 | 18 | } 19 | 20 | /*! 21 | @brief Convenience factory method for initializing an autoreleased TDWord object. 22 | @result an initialized autoreleased TDWord object 23 | */ 24 | + (id)word; 25 | @end 26 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDWord.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDWord.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 7/13/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDWord.h" 10 | #import "TDToken.h" 11 | 12 | @implementation TDWord 13 | 14 | + (id)word { 15 | return [[[self alloc] initWithString:nil] autorelease]; 16 | } 17 | 18 | 19 | - (BOOL)qualifies:(id)obj { 20 | TDToken *tok = (TDToken *)obj; 21 | return tok.isWord; 22 | } 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDWordOrReservedState.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDWordOrReservedState.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 8/14/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TDWordState.h" 11 | 12 | /*! 13 | @class TDWordOrReservedState 14 | @brief Override TDWordState to return known reserved words as tokens of type TDTT_RESERVED. 15 | */ 16 | @interface TDWordOrReservedState : TDWordState { 17 | NSMutableSet *reservedWords; 18 | } 19 | 20 | /*! 21 | @brief Adds the specified string as a known reserved word. 22 | @param s reserved word to add 23 | */ 24 | - (void)addReservedWord:(NSString *)s; 25 | @end 26 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDWordOrReservedState.m: -------------------------------------------------------------------------------- 1 | // 2 | // TDWordOrReservedState.m 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 8/14/08. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import "TDWordOrReservedState.h" 10 | 11 | @interface TDWordOrReservedState () 12 | @property (nonatomic, retain) NSMutableSet *reservedWords; 13 | @end 14 | 15 | @implementation TDWordOrReservedState 16 | 17 | - (id)init { 18 | self = [super init]; 19 | if (self) { 20 | self.reservedWords = [NSMutableSet set]; 21 | } 22 | return self; 23 | } 24 | 25 | 26 | - (void)dealloc { 27 | self.reservedWords = nil; 28 | [super dealloc]; 29 | } 30 | 31 | 32 | - (void)addReservedWord:(NSString *)s { 33 | [reservedWords addObject:s]; 34 | } 35 | 36 | 37 | - (TDToken *)nextTokenFromReader:(TDReader *)r startingWith:(NSInteger)cin tokenizer:(TDTokenizer *)t { 38 | NSParameterAssert(r); 39 | return nil; 40 | } 41 | 42 | @synthesize reservedWords; 43 | @end 44 | -------------------------------------------------------------------------------- /src/framework/todparsekit/TDWordState.h: -------------------------------------------------------------------------------- 1 | // 2 | // TDWordState.h 3 | // TDParseKit 4 | // 5 | // Created by Todd Ditchendorf on 1/20/06. 6 | // Copyright 2008 Todd Ditchendorf. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TDTokenizerState.h" 11 | 12 | /*! 13 | @class TDWordState 14 | @brief A word state returns a word from a reader. 15 | @details

Like other states, a tokenizer transfers the job of reading to this state, depending on an initial character. Thus, the tokenizer decides which characters may begin a word, and this state determines which characters may appear as a second or later character in a word. These are typically different sets of characters; in particular, it is typical for digits to appear as parts of a word, but not as the initial character of a word.

16 |

By default, the following characters may appear in a word. The method setWordChars() allows customizing this.

17 | @code 18 | From To 19 | 'a' 'z' 20 | 'A' 'Z' 21 | '0' '9' 22 | @endcode 23 |

as well as: minus sign -, underscore _, and apostrophe '.

24 | */ 25 | @interface TDWordState : TDTokenizerState { 26 | NSMutableArray *wordChars; 27 | } 28 | 29 | /*! 30 | @brief Establish characters in the given range as valid characters for part of a word after the first character. Note that the tokenizer must determine which characters are valid as the beginning character of a word. 31 | @param yn true if characters in the given range are word characters 32 | @param start the "start" character. e.g. 'a' or 65. 33 | @param end the "end" character. 'z' or 90. 34 | */ 35 | - (void)setWordChars:(BOOL)yn from:(NSInteger)start to:(NSInteger)end; 36 | 37 | /*! 38 | @brief Informs whether the given character is recognized as a word character by this state. 39 | @param cin the character to check 40 | @result true if the given chracter is recognized as a word character 41 | */ 42 | - (BOOL)isWordChar:(NSInteger)c; 43 | @end 44 | --------------------------------------------------------------------------------