mirror of
https://github.com/github/semantic.git
synced 2024-11-27 12:57:49 +03:00
Add 'prototype/' from commit 'a7fef6ced9d2b71dfdf5e6d8fb765ab0c0bc6be5'
git-subtree-dir: prototype
git-subtree-mainline: 0244ce39f68a04b515f32b2b8ea9a3e0228923c7
git-subtree-split: a7fef6ced9
This commit is contained in:
commit
93fd2acc81
6
prototype/.gitignore
vendored
Normal file
6
prototype/.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
.DS_Store
|
||||
xcuserdata
|
||||
*.xcuserdatad
|
||||
*.xccheckout
|
||||
*.mode*
|
||||
*.pbxuser
|
17
prototype/Doubt.playground/Contents.swift
Normal file
17
prototype/Doubt.playground/Contents.swift
Normal file
@ -0,0 +1,17 @@
|
||||
import Doubt
|
||||
|
||||
func fix<T, U>(f: (T -> U) -> T -> U) -> T -> U {
|
||||
return { f(fix(f))($0) }
|
||||
}
|
||||
|
||||
let atom = Syntax<Fix>.Variable <^> ^("abcdefghijklmnopqrstuvwxyz".characters.map { String($0) })
|
||||
let ws = ^(" \t\n".characters.map { String($0) })
|
||||
|
||||
let sexpr: String -> State<Fix>? = fix { sexpr in
|
||||
let list = Syntax<Fix>.Apply <^> (ws* *> ^"(" *> ws* *> sexpr <*> sexpr* <* ^")")
|
||||
return Fix.init <^> (atom <|> list) <* ws*
|
||||
}
|
||||
|
||||
if let s = sexpr("\t(\n( a) \n)\t")?.value, t = sexpr("((a))")?.value {
|
||||
Diff(s, t)
|
||||
}
|
4
prototype/Doubt.playground/contents.xcplayground
Normal file
4
prototype/Doubt.playground/contents.xcplayground
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<playground version='5.0' target-platform='osx' requires-full-environment='true'>
|
||||
<timeline fileName='timeline.xctimeline'/>
|
||||
</playground>
|
6
prototype/Doubt.playground/timeline.xctimeline
Normal file
6
prototype/Doubt.playground/timeline.xctimeline
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Timeline
|
||||
version = "3.0">
|
||||
<TimelineItems>
|
||||
</TimelineItems>
|
||||
</Timeline>
|
461
prototype/Doubt.xcodeproj/project.pbxproj
Normal file
461
prototype/Doubt.xcodeproj/project.pbxproj
Normal file
@ -0,0 +1,461 @@
|
||||
// !$*UTF8*$!
|
||||
{
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 46;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
D4AAE50E1B5AE22E004E581F /* Doubt.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D4AAE4FD1B5AE22E004E581F /* Doubt.framework */; };
|
||||
D4AAE5131B5AE22E004E581F /* DoubtTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4AAE5121B5AE22E004E581F /* DoubtTests.swift */; };
|
||||
D4AAE5401B5AE2D0004E581F /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4AAE5351B5AE2D0004E581F /* Array.swift */; };
|
||||
D4AAE5411B5AE2D0004E581F /* Diff.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4AAE5361B5AE2D0004E581F /* Diff.swift */; };
|
||||
D4AAE5421B5AE2D0004E581F /* Doc.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4AAE5371B5AE2D0004E581F /* Doc.swift */; };
|
||||
D4AAE5431B5AE2D0004E581F /* FixpointType.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4AAE5381B5AE2D0004E581F /* FixpointType.swift */; };
|
||||
D4AAE5441B5AE2D0004E581F /* Lambda.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4AAE5391B5AE2D0004E581F /* Lambda.swift */; };
|
||||
D4AAE5451B5AE2D0004E581F /* Operators.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4AAE53A1B5AE2D0004E581F /* Operators.swift */; };
|
||||
D4AAE5461B5AE2D0004E581F /* Parse.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4AAE53B1B5AE2D0004E581F /* Parse.swift */; };
|
||||
D4AAE5471B5AE2D0004E581F /* Prelude.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4AAE53C1B5AE2D0004E581F /* Prelude.swift */; };
|
||||
D4AAE5481B5AE2D0004E581F /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4AAE53D1B5AE2D0004E581F /* String.swift */; };
|
||||
D4AAE5491B5AE2D0004E581F /* StringLiteralConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4AAE53E1B5AE2D0004E581F /* StringLiteralConvertible.swift */; };
|
||||
D4AAE54A1B5AE2D0004E581F /* Syntax.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4AAE53F1B5AE2D0004E581F /* Syntax.swift */; };
|
||||
D4AAE54C1B5AE42D004E581F /* Equatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4AAE54B1B5AE42D004E581F /* Equatable.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
D4AAE50F1B5AE22E004E581F /* PBXContainerItemProxy */ = {
|
||||
isa = PBXContainerItemProxy;
|
||||
containerPortal = D4AAE4F41B5AE22E004E581F /* Project object */;
|
||||
proxyType = 1;
|
||||
remoteGlobalIDString = D4AAE4FC1B5AE22E004E581F;
|
||||
remoteInfo = Doubt;
|
||||
};
|
||||
/* End PBXContainerItemProxy section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
D443F4D61BA3157700049A57 /* Doubt.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = Doubt.playground; sourceTree = "<group>"; };
|
||||
D4AAE4FD1B5AE22E004E581F /* Doubt.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Doubt.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
D4AAE5011B5AE22E004E581F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
D4AAE50D1B5AE22E004E581F /* DoubtTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DoubtTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
D4AAE5121B5AE22E004E581F /* DoubtTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DoubtTests.swift; sourceTree = "<group>"; };
|
||||
D4AAE5141B5AE22E004E581F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
D4AAE5351B5AE2D0004E581F /* Array.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = "<group>"; };
|
||||
D4AAE5361B5AE2D0004E581F /* Diff.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Diff.swift; sourceTree = "<group>"; };
|
||||
D4AAE5371B5AE2D0004E581F /* Doc.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Doc.swift; sourceTree = "<group>"; };
|
||||
D4AAE5381B5AE2D0004E581F /* FixpointType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FixpointType.swift; sourceTree = "<group>"; };
|
||||
D4AAE5391B5AE2D0004E581F /* Lambda.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Lambda.swift; sourceTree = "<group>"; };
|
||||
D4AAE53A1B5AE2D0004E581F /* Operators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Operators.swift; sourceTree = "<group>"; };
|
||||
D4AAE53B1B5AE2D0004E581F /* Parse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Parse.swift; sourceTree = "<group>"; };
|
||||
D4AAE53C1B5AE2D0004E581F /* Prelude.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Prelude.swift; sourceTree = "<group>"; };
|
||||
D4AAE53D1B5AE2D0004E581F /* String.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = String.swift; sourceTree = "<group>"; };
|
||||
D4AAE53E1B5AE2D0004E581F /* StringLiteralConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringLiteralConvertible.swift; sourceTree = "<group>"; };
|
||||
D4AAE53F1B5AE2D0004E581F /* Syntax.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Syntax.swift; sourceTree = "<group>"; };
|
||||
D4AAE54B1B5AE42D004E581F /* Equatable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Equatable.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
D4AAE4F91B5AE22E004E581F /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
D4AAE50A1B5AE22E004E581F /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
D4AAE50E1B5AE22E004E581F /* Doubt.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
D4AAE4F31B5AE22E004E581F = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D443F4D61BA3157700049A57 /* Doubt.playground */,
|
||||
D4AAE4FF1B5AE22E004E581F /* Doubt */,
|
||||
D4AAE5111B5AE22E004E581F /* DoubtTests */,
|
||||
D4AAE4FE1B5AE22E004E581F /* Products */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
D4AAE4FE1B5AE22E004E581F /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D4AAE4FD1B5AE22E004E581F /* Doubt.framework */,
|
||||
D4AAE50D1B5AE22E004E581F /* DoubtTests.xctest */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
D4AAE4FF1B5AE22E004E581F /* Doubt */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D4AAE5351B5AE2D0004E581F /* Array.swift */,
|
||||
D4AAE5361B5AE2D0004E581F /* Diff.swift */,
|
||||
D4AAE5371B5AE2D0004E581F /* Doc.swift */,
|
||||
D4AAE5381B5AE2D0004E581F /* FixpointType.swift */,
|
||||
D4AAE5391B5AE2D0004E581F /* Lambda.swift */,
|
||||
D4AAE53A1B5AE2D0004E581F /* Operators.swift */,
|
||||
D4AAE53B1B5AE2D0004E581F /* Parse.swift */,
|
||||
D4AAE53C1B5AE2D0004E581F /* Prelude.swift */,
|
||||
D4AAE53D1B5AE2D0004E581F /* String.swift */,
|
||||
D4AAE53E1B5AE2D0004E581F /* StringLiteralConvertible.swift */,
|
||||
D4AAE53F1B5AE2D0004E581F /* Syntax.swift */,
|
||||
D4AAE54B1B5AE42D004E581F /* Equatable.swift */,
|
||||
D4AAE5001B5AE22E004E581F /* Supporting Files */,
|
||||
);
|
||||
path = Doubt;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
D4AAE5001B5AE22E004E581F /* Supporting Files */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D4AAE5011B5AE22E004E581F /* Info.plist */,
|
||||
);
|
||||
name = "Supporting Files";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
D4AAE5111B5AE22E004E581F /* DoubtTests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D4AAE5121B5AE22E004E581F /* DoubtTests.swift */,
|
||||
D4AAE5141B5AE22E004E581F /* Info.plist */,
|
||||
);
|
||||
path = DoubtTests;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXHeadersBuildPhase section */
|
||||
D4AAE4FA1B5AE22E004E581F /* Headers */ = {
|
||||
isa = PBXHeadersBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXHeadersBuildPhase section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
D4AAE4FC1B5AE22E004E581F /* Doubt */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = D4AAE5171B5AE22E004E581F /* Build configuration list for PBXNativeTarget "Doubt" */;
|
||||
buildPhases = (
|
||||
D4AAE4F81B5AE22E004E581F /* Sources */,
|
||||
D4AAE4F91B5AE22E004E581F /* Frameworks */,
|
||||
D4AAE4FA1B5AE22E004E581F /* Headers */,
|
||||
D4AAE4FB1B5AE22E004E581F /* Resources */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
name = Doubt;
|
||||
productName = Doubt;
|
||||
productReference = D4AAE4FD1B5AE22E004E581F /* Doubt.framework */;
|
||||
productType = "com.apple.product-type.framework";
|
||||
};
|
||||
D4AAE50C1B5AE22E004E581F /* DoubtTests */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = D4AAE51A1B5AE22E004E581F /* Build configuration list for PBXNativeTarget "DoubtTests" */;
|
||||
buildPhases = (
|
||||
D4AAE5091B5AE22E004E581F /* Sources */,
|
||||
D4AAE50A1B5AE22E004E581F /* Frameworks */,
|
||||
D4AAE50B1B5AE22E004E581F /* Resources */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
D4AAE5101B5AE22E004E581F /* PBXTargetDependency */,
|
||||
);
|
||||
name = DoubtTests;
|
||||
productName = DoubtTests;
|
||||
productReference = D4AAE50D1B5AE22E004E581F /* DoubtTests.xctest */;
|
||||
productType = "com.apple.product-type.bundle.unit-test";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
D4AAE4F41B5AE22E004E581F /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastSwiftUpdateCheck = 0700;
|
||||
LastUpgradeCheck = 0700;
|
||||
ORGANIZATIONNAME = GitHub;
|
||||
TargetAttributes = {
|
||||
D4AAE4FC1B5AE22E004E581F = {
|
||||
CreatedOnToolsVersion = 7.0;
|
||||
};
|
||||
D4AAE50C1B5AE22E004E581F = {
|
||||
CreatedOnToolsVersion = 7.0;
|
||||
};
|
||||
};
|
||||
};
|
||||
buildConfigurationList = D4AAE4F71B5AE22E004E581F /* Build configuration list for PBXProject "Doubt" */;
|
||||
compatibilityVersion = "Xcode 3.2";
|
||||
developmentRegion = English;
|
||||
hasScannedForEncodings = 0;
|
||||
knownRegions = (
|
||||
en,
|
||||
);
|
||||
mainGroup = D4AAE4F31B5AE22E004E581F;
|
||||
productRefGroup = D4AAE4FE1B5AE22E004E581F /* Products */;
|
||||
projectDirPath = "";
|
||||
projectRoot = "";
|
||||
targets = (
|
||||
D4AAE4FC1B5AE22E004E581F /* Doubt */,
|
||||
D4AAE50C1B5AE22E004E581F /* DoubtTests */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin PBXResourcesBuildPhase section */
|
||||
D4AAE4FB1B5AE22E004E581F /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
D4AAE50B1B5AE22E004E581F /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXResourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
D4AAE4F81B5AE22E004E581F /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
D4AAE5431B5AE2D0004E581F /* FixpointType.swift in Sources */,
|
||||
D4AAE5471B5AE2D0004E581F /* Prelude.swift in Sources */,
|
||||
D4AAE5441B5AE2D0004E581F /* Lambda.swift in Sources */,
|
||||
D4AAE5481B5AE2D0004E581F /* String.swift in Sources */,
|
||||
D4AAE5411B5AE2D0004E581F /* Diff.swift in Sources */,
|
||||
D4AAE5401B5AE2D0004E581F /* Array.swift in Sources */,
|
||||
D4AAE54C1B5AE42D004E581F /* Equatable.swift in Sources */,
|
||||
D4AAE54A1B5AE2D0004E581F /* Syntax.swift in Sources */,
|
||||
D4AAE5421B5AE2D0004E581F /* Doc.swift in Sources */,
|
||||
D4AAE5461B5AE2D0004E581F /* Parse.swift in Sources */,
|
||||
D4AAE5491B5AE2D0004E581F /* StringLiteralConvertible.swift in Sources */,
|
||||
D4AAE5451B5AE2D0004E581F /* Operators.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
D4AAE5091B5AE22E004E581F /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
D4AAE5131B5AE22E004E581F /* DoubtTests.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXTargetDependency section */
|
||||
D4AAE5101B5AE22E004E581F /* PBXTargetDependency */ = {
|
||||
isa = PBXTargetDependency;
|
||||
target = D4AAE4FC1B5AE22E004E581F /* Doubt */;
|
||||
targetProxy = D4AAE50F1B5AE22E004E581F /* PBXContainerItemProxy */;
|
||||
};
|
||||
/* End PBXTargetDependency section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
D4AAE5151B5AE22E004E581F /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
ENABLE_TESTABILITY = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||
"DEBUG=1",
|
||||
"$(inherited)",
|
||||
);
|
||||
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.10;
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = macosx;
|
||||
SWIFT_INSTALL_OBJC_HEADER = NO;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
VERSION_INFO_PREFIX = "";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
D4AAE5161B5AE22E004E581F /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
COPY_PHASE_STRIP = YES;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
ENABLE_NS_ASSERTIONS = NO;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.10;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = macosx;
|
||||
SWIFT_INSTALL_OBJC_HEADER = NO;
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
VERSION_INFO_PREFIX = "";
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
D4AAE5181B5AE22E004E581F /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
DEFINES_MODULE = YES;
|
||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||
DYLIB_CURRENT_VERSION = 1;
|
||||
DYLIB_INSTALL_NAME_BASE = "@rpath";
|
||||
FRAMEWORK_VERSION = A;
|
||||
INFOPLIST_FILE = Doubt/Info.plist;
|
||||
INSTALL_PATH = "@rpath";
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
D4AAE5191B5AE22E004E581F /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
DEFINES_MODULE = YES;
|
||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||
DYLIB_CURRENT_VERSION = 1;
|
||||
DYLIB_INSTALL_NAME_BASE = "@rpath";
|
||||
FRAMEWORK_VERSION = A;
|
||||
INFOPLIST_FILE = Doubt/Info.plist;
|
||||
INSTALL_PATH = "@rpath";
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SKIP_INSTALL = YES;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
D4AAE51B1B5AE22E004E581F /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(DEVELOPER_FRAMEWORKS_DIR)",
|
||||
"$(inherited)",
|
||||
);
|
||||
INFOPLIST_FILE = DoubtTests/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.github.DoubtTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
D4AAE51C1B5AE22E004E581F /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(DEVELOPER_FRAMEWORKS_DIR)",
|
||||
"$(inherited)",
|
||||
);
|
||||
INFOPLIST_FILE = DoubtTests/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.github.DoubtTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
D4AAE4F71B5AE22E004E581F /* Build configuration list for PBXProject "Doubt" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
D4AAE5151B5AE22E004E581F /* Debug */,
|
||||
D4AAE5161B5AE22E004E581F /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
D4AAE5171B5AE22E004E581F /* Build configuration list for PBXNativeTarget "Doubt" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
D4AAE5181B5AE22E004E581F /* Debug */,
|
||||
D4AAE5191B5AE22E004E581F /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
D4AAE51A1B5AE22E004E581F /* Build configuration list for PBXNativeTarget "DoubtTests" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
D4AAE51B1B5AE22E004E581F /* Debug */,
|
||||
D4AAE51C1B5AE22E004E581F /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
rootObject = D4AAE4F41B5AE22E004E581F /* Project object */;
|
||||
}
|
7
prototype/Doubt.xcodeproj/project.xcworkspace/contents.xcworkspacedata
generated
Normal file
7
prototype/Doubt.xcodeproj/project.xcworkspace/contents.xcworkspacedata
generated
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Workspace
|
||||
version = "1.0">
|
||||
<FileRef
|
||||
location = "self:Doubt.xcodeproj">
|
||||
</FileRef>
|
||||
</Workspace>
|
7
prototype/Doubt.xcworkspace/contents.xcworkspacedata
generated
Normal file
7
prototype/Doubt.xcworkspace/contents.xcworkspacedata
generated
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Workspace
|
||||
version = "1.0">
|
||||
<FileRef
|
||||
location = "group:Doubt.xcodeproj">
|
||||
</FileRef>
|
||||
</Workspace>
|
5
prototype/Doubt/Array.swift
Normal file
5
prototype/Doubt/Array.swift
Normal file
@ -0,0 +1,5 @@
|
||||
extension Array {
|
||||
static func cons(head: Element, _ tail: Array) -> Array {
|
||||
return [head] + tail
|
||||
}
|
||||
}
|
52
prototype/Doubt/Diff.swift
Normal file
52
prototype/Doubt/Diff.swift
Normal file
@ -0,0 +1,52 @@
|
||||
public enum Diff: CustomDocConvertible, Equatable {
|
||||
case Patch(Fix, Fix)
|
||||
indirect case Copy(Syntax<Diff>)
|
||||
|
||||
public var doc: Doc<Pretty> {
|
||||
switch self {
|
||||
case let .Patch(a, b):
|
||||
return .Horizontal([
|
||||
.Wrap(Pretty.Text("{-"), Pretty(a), Pretty.Text("-}")),
|
||||
.Wrap(Pretty.Text("{+"), Pretty(b), Pretty.Text("+}"))
|
||||
])
|
||||
case let .Copy(a):
|
||||
return a.doc
|
||||
}
|
||||
}
|
||||
|
||||
public var description: String {
|
||||
switch self {
|
||||
case let .Patch(a, b):
|
||||
return ".Patch(\(a), \(b))"
|
||||
case let .Copy(a):
|
||||
return ".Copy(\(a))"
|
||||
}
|
||||
}
|
||||
|
||||
public init(_ a: Fix, _ b: Fix) {
|
||||
switch (a.out, b.out) {
|
||||
case let (.Apply(a, aa), .Apply(b, bb)):
|
||||
// fixme: SES
|
||||
self = .Copy(.Apply(Diff(a, b), Array(zip(aa, bb).lazy.map(Diff.init))))
|
||||
|
||||
case let (.Abstract(p1, b1), .Abstract(p2, b2)):
|
||||
self = .Copy(.Abstract(Array(zip(p1, p2).lazy.map(Diff.init)), Diff(b1, b2)))
|
||||
|
||||
case let (.Assign(n1, v1), .Assign(n2, v2)) where n1 == n2:
|
||||
self = .Copy(.Assign(n2, Diff(v1, v2)))
|
||||
|
||||
case let (.Variable(n1), .Variable(n2)) where n1 == n2:
|
||||
self = .Copy(.Variable(n2))
|
||||
|
||||
case let (.Literal(v1), .Literal(v2)) where v1 == v2:
|
||||
self = .Copy(.Literal(v2))
|
||||
|
||||
case let (.Group(n1, v1), .Group(n2, v2)):
|
||||
self = .Copy(.Group(Diff(n1, n2), Array(zip(v1, v2).lazy.map(Diff.init))))
|
||||
|
||||
default:
|
||||
self = .Patch(a, b)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
94
prototype/Doubt/Doc.swift
Normal file
94
prototype/Doubt/Doc.swift
Normal file
@ -0,0 +1,94 @@
|
||||
public enum Doc<Payload>: AlgebraicType, CustomStringConvertible {
|
||||
case Empty
|
||||
case Text(String)
|
||||
case Horizontal([Payload])
|
||||
case Vertical([Payload])
|
||||
case Wrap(Payload, Payload, Payload)
|
||||
case Join(Payload, [Payload])
|
||||
|
||||
public func map<Other>(@noescape transform: Payload -> Other) -> Doc<Other> {
|
||||
switch self {
|
||||
case .Empty:
|
||||
return .Empty
|
||||
case let .Text(s):
|
||||
return .Text(s)
|
||||
case let .Horizontal(a):
|
||||
return .Horizontal(a.map(transform))
|
||||
case let .Vertical(a):
|
||||
return .Vertical(a.map(transform))
|
||||
case let .Wrap(open, body, close):
|
||||
return .Wrap(transform(open), transform(body), transform(close))
|
||||
case let .Join(separator, elements):
|
||||
return .Join(transform(separator), elements.map(transform))
|
||||
}
|
||||
}
|
||||
|
||||
public typealias Recur = Payload
|
||||
|
||||
public var description: String {
|
||||
switch self {
|
||||
case .Empty:
|
||||
return ""
|
||||
case let .Text(s):
|
||||
return s
|
||||
case let .Horizontal(a):
|
||||
return a.lazy.map { String($0) }.joinWithSeparator("")
|
||||
case let .Vertical(a):
|
||||
return a.lazy.map { String($0) }.joinWithSeparator("\n")
|
||||
case let .Wrap(open, body, close):
|
||||
return "\(String(open))\(String(body))\(String(close))"
|
||||
case let .Join(separator, elements):
|
||||
return elements.map { String($0) }.joinWithSeparator(String(separator))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public struct Pretty: CustomStringConvertible, Equatable, FixpointType {
|
||||
public init<T>(_ value: T) {
|
||||
self.init((value as? CustomDocConvertible)?.doc ?? .Text(String(value)))
|
||||
}
|
||||
|
||||
public init(_ doc: Doc<Pretty>) {
|
||||
self.init { doc }
|
||||
}
|
||||
|
||||
public init(_ doc: () -> Doc<Pretty>) {
|
||||
self.doc = doc
|
||||
}
|
||||
|
||||
let doc: () -> Doc<Pretty>
|
||||
public var out: Doc<Pretty> {
|
||||
return doc()
|
||||
}
|
||||
|
||||
public var description: String {
|
||||
return out.description
|
||||
}
|
||||
|
||||
|
||||
public static let Empty = Pretty(Doc<Pretty>.Empty)
|
||||
public static let Text = Doc<Pretty>.Text >>> Pretty.init
|
||||
public static let Horizontal = Doc<Pretty>.Horizontal >>> Pretty.init
|
||||
public static let Vertical = Doc<Pretty>.Vertical >>> Pretty.init
|
||||
public static let Wrap = Doc<Pretty>.Wrap >>> Pretty.init
|
||||
|
||||
public static func Wrap(open: Pretty, _ body: Pretty, _ close: Pretty) -> Pretty {
|
||||
return Pretty(.Wrap(open, body, close))
|
||||
}
|
||||
|
||||
public static func Join(separator: Pretty, _ elements: [Pretty]) -> Pretty {
|
||||
return Pretty(.Join(separator, elements))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public protocol CustomDocConvertible: CustomStringConvertible {
|
||||
var doc: Doc<Pretty> { get }
|
||||
}
|
||||
|
||||
extension CustomDocConvertible {
|
||||
public var description: String {
|
||||
return doc.description
|
||||
}
|
||||
}
|
56
prototype/Doubt/Equatable.swift
Normal file
56
prototype/Doubt/Equatable.swift
Normal file
@ -0,0 +1,56 @@
|
||||
public func == (left: Fix, right: Fix) -> Bool {
|
||||
return left.out == right.out
|
||||
}
|
||||
|
||||
public func == <F: Equatable> (left: Syntax<F>, right: Syntax<F>) -> Bool {
|
||||
switch (left, right) {
|
||||
case let (.Apply(a, aa), .Apply(b, bb)):
|
||||
return a == b && aa == bb
|
||||
case let (.Abstract(p1, b1), .Abstract(p2, b2)):
|
||||
return p1 == p2 && b1 == b2
|
||||
case let (.Assign(n1, v1), .Assign(n2, v2)):
|
||||
return n1 == n2 && v1 == v2
|
||||
case let (.Variable(n1), .Variable(n2)):
|
||||
return n1 == n2
|
||||
case let (.Literal(l1), .Literal(l2)):
|
||||
return l1 == l2
|
||||
case let (.Group(n1, v1), .Group(n2, v2)):
|
||||
return n1 == n2 && v1 == v2
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
public func == (left: Diff, right: Diff) -> Bool {
|
||||
switch (left, right) {
|
||||
case let (.Patch(a1, b1), .Patch(a2, b2)):
|
||||
return a1 == a2 && b1 == b2
|
||||
case let (.Copy(a), .Copy(b)):
|
||||
return a == b
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
public func == <F: Equatable> (left: Doc<F>, right: Doc<F>) -> Bool {
|
||||
switch (left, right) {
|
||||
case (.Empty, .Empty):
|
||||
return true
|
||||
case let (.Text(a), .Text(b)):
|
||||
return a == b
|
||||
case let (.Horizontal(a), .Horizontal(b)):
|
||||
return a == b
|
||||
case let (.Vertical(a), .Vertical(b)):
|
||||
return a == b
|
||||
case let (.Wrap(a1, b1, c1), .Wrap(a2, b2, c2)):
|
||||
return a1 == a2 && b1 == b2 && c1 == c2
|
||||
case let (.Join(s1, e1), .Join(s2, e2)):
|
||||
return s1 == s2 && e1 == e2
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
public func == (left: Pretty, right: Pretty) -> Bool {
|
||||
return left.out == right.out
|
||||
}
|
15
prototype/Doubt/FixpointType.swift
Normal file
15
prototype/Doubt/FixpointType.swift
Normal file
@ -0,0 +1,15 @@
|
||||
protocol FixpointType {
|
||||
typealias Algebra: AlgebraicType
|
||||
init(_ algebra: Algebra)
|
||||
var out: Algebra { get }
|
||||
}
|
||||
|
||||
protocol AlgebraicType {
|
||||
typealias Recur
|
||||
}
|
||||
|
||||
extension FixpointType {
|
||||
static func out(fix: Self) -> Algebra {
|
||||
return fix.out
|
||||
}
|
||||
}
|
28
prototype/Doubt/Info.plist
Normal file
28
prototype/Doubt/Info.plist
Normal file
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.github.$(PRODUCT_NAME:rfc1034identifier)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>0.0.1</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>$(CURRENT_PROJECT_VERSION)</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2015 Rob Rix. All rights reserved.</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string></string>
|
||||
</dict>
|
||||
</plist>
|
9
prototype/Doubt/Lambda.swift
Normal file
9
prototype/Doubt/Lambda.swift
Normal file
@ -0,0 +1,9 @@
|
||||
let word = ^("abcdefghijklmnopqrstuvwxyz".characters.map { String($0) })
|
||||
let ws = ^" "
|
||||
|
||||
let term: String -> State<Fix>? = fix { term in
|
||||
let variable = Syntax<Fix>.Variable <^> word
|
||||
let application = Syntax.Apply <^> (^"(" *> ws* *> term <*> (ws *> term)* <* ws* <* ^")")
|
||||
let abstraction = Syntax.Abstract <^> (^"λ" *> ws* *> interpolate(term, ws) <*> (ws* *> ^"." *> term))
|
||||
return Fix.init <^> (abstraction <|> application <|> variable)
|
||||
}
|
35
prototype/Doubt/Operators.swift
Normal file
35
prototype/Doubt/Operators.swift
Normal file
@ -0,0 +1,35 @@
|
||||
infix operator <|> {
|
||||
associativity left
|
||||
precedence 120
|
||||
}
|
||||
|
||||
infix operator <*> {
|
||||
associativity left
|
||||
precedence 130
|
||||
}
|
||||
|
||||
infix operator <* {
|
||||
associativity left
|
||||
precedence 130
|
||||
}
|
||||
|
||||
infix operator *> {
|
||||
associativity left
|
||||
precedence 130
|
||||
}
|
||||
|
||||
infix operator <^> {
|
||||
associativity left
|
||||
precedence 130
|
||||
}
|
||||
|
||||
infix operator >>- {
|
||||
associativity left
|
||||
precedence 100
|
||||
}
|
||||
|
||||
prefix operator ^ {}
|
||||
|
||||
postfix operator * {}
|
||||
|
||||
postfix operator + {}
|
68
prototype/Doubt/Parse.swift
Normal file
68
prototype/Doubt/Parse.swift
Normal file
@ -0,0 +1,68 @@
|
||||
public struct State<T> {
|
||||
public let rest: String
|
||||
public let value: T
|
||||
}
|
||||
|
||||
public prefix func ^(string: String)(_ input: String) -> State<String>? {
|
||||
return input.characters.startsWith(string.characters)
|
||||
? State(rest: input.from(string.characters.count), value: string)
|
||||
: nil
|
||||
}
|
||||
|
||||
public prefix func ^(strings: [String])(_ input: String) -> State<String>? {
|
||||
return strings.indexOf { input.characters.startsWith($0.characters) }
|
||||
.flatMap { index in
|
||||
let string = strings[index]
|
||||
return (^string)(input)
|
||||
}
|
||||
}
|
||||
|
||||
public func parseWhile(predicate: Character -> Bool)(_ input: String) -> State<String>? {
|
||||
return input.characters.count > 0 && predicate(input.characters[input.startIndex])
|
||||
? parseWhile(predicate)(input.from(1)).map { State(rest: $0.rest, value: input.to(1) + $0.value) } ?? State(rest: input.from(1), value: input.to(1))
|
||||
: nil
|
||||
}
|
||||
|
||||
public postfix func * <T>(parser: String -> State<T>?) -> String -> State<[T]>? {
|
||||
return (Array.cons <^> (parser <*> { (parser*)($0) })) <|> pure([])
|
||||
}
|
||||
|
||||
public postfix func + <T> (parser: String -> State<T>?) -> String -> State<[T]>? {
|
||||
return (Array.cons <^> (parser <*> parser*))
|
||||
}
|
||||
|
||||
public func interpolate<Separator, Element>(element: String -> State<Element>?, _ separator: String -> State<Separator>?) -> String -> State<[Element]>? {
|
||||
return Array.cons <^> (element <*> (separator *> element)*) <|> pure([])
|
||||
}
|
||||
|
||||
public func <*> <T, U> (left: String -> State<T>?, right: String -> State<U>?)(_ input: String) -> State<(T, U)>? {
|
||||
return left(input).flatMap { l in
|
||||
right(l.rest).map { r in
|
||||
State(rest: r.rest, value: (l.value, r.value))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func <* <T, U> (left: String -> State<T>?, right: String -> State<U>?) -> String -> State<T>? {
|
||||
return left >>- { const($0) <^> right }
|
||||
}
|
||||
|
||||
public func *> <T, U> (left: String -> State<T>?, right: String -> State<U>?) -> String -> State<U>? {
|
||||
return left >>- const(right)
|
||||
}
|
||||
|
||||
public func <|> <T> (left: String -> State<T>?, right: String -> State<T>?)(_ input: String) -> State<T>? {
|
||||
return left(input) ?? right(input)
|
||||
}
|
||||
|
||||
public func <^> <T, U> (left: T -> U, right: String -> State<T>?) -> String -> State<U>? {
|
||||
return right >>- { pure(left($0)) }
|
||||
}
|
||||
|
||||
public func >>- <T, U> (left: String -> State<T>?, right: T -> String -> State<U>?)(_ input: String) -> State<U>? {
|
||||
return left(input).flatMap { state in right(state.value)(state.rest) }
|
||||
}
|
||||
|
||||
public func pure<A>(value: A)(_ input: String) -> State<A>? {
|
||||
return State(rest: input, value: value)
|
||||
}
|
19
prototype/Doubt/Prelude.swift
Normal file
19
prototype/Doubt/Prelude.swift
Normal file
@ -0,0 +1,19 @@
|
||||
func fix<T, U>(f: (T -> U) -> T -> U) -> T -> U {
|
||||
return { f(fix(f))($0) }
|
||||
}
|
||||
|
||||
|
||||
func const<A, B>(a: A)(_ b: B) -> A {
|
||||
return a
|
||||
}
|
||||
|
||||
|
||||
infix operator >>> {
|
||||
associativity right
|
||||
precedence 170
|
||||
}
|
||||
|
||||
func >>> <T, U, V> (f: T -> U, g: U -> V) -> T -> V {
|
||||
return { g(f($0)) }
|
||||
}
|
||||
|
9
prototype/Doubt/String.swift
Normal file
9
prototype/Doubt/String.swift
Normal file
@ -0,0 +1,9 @@
|
||||
extension String {
|
||||
func from(offset: String.Index.Distance) -> String {
|
||||
return String(characters[startIndex.advancedBy(offset, limit: endIndex)..<endIndex])
|
||||
}
|
||||
|
||||
func to(offset: String.Index.Distance) -> String {
|
||||
return String(characters[startIndex..<startIndex.advancedBy(offset, limit: endIndex)])
|
||||
}
|
||||
}
|
9
prototype/Doubt/StringLiteralConvertible.swift
Normal file
9
prototype/Doubt/StringLiteralConvertible.swift
Normal file
@ -0,0 +1,9 @@
|
||||
extension StringLiteralConvertible {
|
||||
public init(unicodeScalarLiteral: Self.StringLiteralType) {
|
||||
self.init(stringLiteral: unicodeScalarLiteral)
|
||||
}
|
||||
|
||||
public init(extendedGraphemeClusterLiteral: Self.StringLiteralType) {
|
||||
self.init(stringLiteral: extendedGraphemeClusterLiteral)
|
||||
}
|
||||
}
|
107
prototype/Doubt/Syntax.swift
Normal file
107
prototype/Doubt/Syntax.swift
Normal file
@ -0,0 +1,107 @@
|
||||
public struct Fix: CustomDebugStringConvertible, CustomDocConvertible, CustomStringConvertible, Equatable, FixpointType {
|
||||
public init(_ roll: () -> Syntax<Fix>) {
|
||||
self.roll = roll
|
||||
}
|
||||
public init(_ out: Syntax<Fix>) {
|
||||
self.init { out }
|
||||
}
|
||||
|
||||
let roll: () -> Syntax<Fix>
|
||||
|
||||
public var out: Syntax<Fix> {
|
||||
return roll()
|
||||
}
|
||||
|
||||
public var debugDescription: String {
|
||||
return cata { String(reflecting: $0) } (self)
|
||||
}
|
||||
|
||||
public var doc: Doc<Pretty> {
|
||||
return cata { (syntax: Syntax<Doc<Pretty>>) in syntax.doc } (self)
|
||||
}
|
||||
|
||||
public var description: String {
|
||||
return cata { String($0) } (self)
|
||||
}
|
||||
}
|
||||
|
||||
public enum Syntax<Payload>: AlgebraicType, CustomDebugStringConvertible, CustomDocConvertible {
|
||||
case Apply(Payload, [Payload])
|
||||
case Abstract([Payload], Payload)
|
||||
case Assign(String, Payload)
|
||||
case Variable(String)
|
||||
case Literal(String)
|
||||
case Group(Payload, [Payload])
|
||||
|
||||
public func map<T>(@noescape transform: Payload -> T) -> Syntax<T> {
|
||||
switch self {
|
||||
case let .Apply(f, args):
|
||||
return .Apply(transform(f), args.map(transform))
|
||||
case let .Abstract(parameters, body):
|
||||
return .Abstract(parameters.map(transform), transform(body))
|
||||
case let .Assign(n, v):
|
||||
return .Assign(n, transform(v))
|
||||
case let .Variable(n):
|
||||
return .Variable(n)
|
||||
case let .Literal(v):
|
||||
return .Literal(v)
|
||||
case let .Group(n, v):
|
||||
return .Group(transform(n), v.map(transform))
|
||||
}
|
||||
}
|
||||
|
||||
public typealias Recur = Payload
|
||||
|
||||
public var debugDescription: String {
|
||||
switch self {
|
||||
case let .Apply(f, vs):
|
||||
let s = vs.map { String($0) }.joinWithSeparator(", ")
|
||||
return ".Apply(\(f), [ \(s) ])"
|
||||
case let .Abstract(parameters, body):
|
||||
let s = parameters.map { String($0) }.joinWithSeparator(", ")
|
||||
return ".Abstract([ \(s) ], \(body))"
|
||||
case let .Assign(n, v):
|
||||
return ".Assign(\(n), \(v))"
|
||||
case let .Variable(n):
|
||||
return ".Variable(\(n))"
|
||||
case let .Literal(s):
|
||||
return ".Literal(\(s))"
|
||||
case let .Group(n, vs):
|
||||
let s = vs.map { String($0) }.joinWithSeparator(", ")
|
||||
return ".Group(\(n), [ \(s) ])"
|
||||
}
|
||||
}
|
||||
|
||||
public var doc: Doc<Pretty> {
|
||||
switch self {
|
||||
case let .Apply(f, vs):
|
||||
return .Horizontal([
|
||||
Pretty(f),
|
||||
Pretty.Wrap(Pretty.Text("("), Pretty.Join(Pretty.Text(", "), vs.map(Pretty.init)), Pretty.Text(")"))
|
||||
])
|
||||
case let .Abstract(parameters, body):
|
||||
return .Horizontal([
|
||||
Pretty.Text("λ"),
|
||||
Pretty.Join(Pretty.Text(", "), parameters.map(Pretty.init)),
|
||||
Pretty.Text("."),
|
||||
Pretty(body)
|
||||
])
|
||||
case let .Assign(n, v):
|
||||
return .Horizontal([ .Text(n), .Text("="), Pretty(v) ])
|
||||
case let .Variable(n):
|
||||
return .Text(n)
|
||||
case let .Literal(s):
|
||||
return .Text(s)
|
||||
case let .Group(n, vs):
|
||||
return .Horizontal([
|
||||
Pretty(n),
|
||||
Pretty.Wrap(.Text("{"), Pretty.Vertical(vs.map(Pretty.init)), .Text("}"))
|
||||
])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func cata<T>(f: Syntax<T> -> T)(_ term: Fix) -> T {
|
||||
return (Fix.out >>> { $0.map(cata(f)) } >>> f)(term)
|
||||
}
|
3
prototype/DoubtTests/DoubtTests.swift
Normal file
3
prototype/DoubtTests/DoubtTests.swift
Normal file
@ -0,0 +1,3 @@
|
||||
final class DoubtTests: XCTestCase {}
|
||||
|
||||
import XCTest
|
24
prototype/DoubtTests/Info.plist
Normal file
24
prototype/DoubtTests/Info.plist
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
</dict>
|
||||
</plist>
|
Loading…
Reference in New Issue
Block a user