This repository has been archived by the owner on Dec 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Update Madness to master #11
Open
ghost
wants to merge
2
commits into
Carthage:master
Choose a base branch
from
unknown repository
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
github "robrix/Madness" "significant-indentation" | ||
github "robrix/Either" ~> 1.1 | ||
github "robrix/Box" ~> 1.0.1 | ||
github "robrix/Prelude" ~> 1.4 | ||
github "robrix/Madness" "master" | ||
github "robrix/Either" ~> 1.2.2 | ||
github "robrix/Box" ~> 1.2.2 | ||
github "robrix/Prelude" ~> 1.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
github "jspahrsummers/xcconfigs" | ||
github "Quick/Quick" ~> 0.2.2 | ||
github "Quick/Nimble" ~> 0.2 | ||
github "Quick/Quick" ~> 0.3.1 | ||
github "Quick/Nimble" ~> 1.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
github "robrix/Box" "1.0.1" | ||
github "robrix/Either" "1.1" | ||
github "robrix/Madness" "b5e2882e924b2377da83adcdb59592ba7fdab52a" | ||
github "Quick/Nimble" "v0.2.0" | ||
github "robrix/Prelude" "1.4" | ||
github "Quick/Quick" "v0.2.2" | ||
github "jspahrsummers/xcconfigs" "0.7.1" | ||
github "robrix/Box" "1.2.2" | ||
github "Quick/Nimble" "v1.0.0" | ||
github "robrix/Prelude" "1.5.0" | ||
github "Quick/Quick" "v0.3.1" | ||
github "jspahrsummers/xcconfigs" "0.8.1" | ||
github "robrix/Either" "1.2.2" | ||
github "robrix/Madness" "fa440dd21e7341f687f748afd98ccb12574e1bd0" |
Submodule Box
updated
8 files
+249 −18 | Box.xcodeproj/project.pbxproj | |
+9 −9 | Box.xcodeproj/xcshareddata/xcschemes/Box-Mac.xcscheme | |
+110 −0 | Box.xcodeproj/xcshareddata/xcschemes/Box-iOS.xcscheme | |
+8 −1 | Box/Box.swift | |
+1 −1 | Box/BoxType.swift | |
+1 −1 | Box/Info.plist | |
+1 −1 | Box/MutableBox.swift | |
+4 −4 | README.md |
Submodule Either
updated
18 files
+2 −0 | .gitignore | |
+4 −4 | .gitmodules | |
+2 −0 | Cartfile | |
+2 −0 | Cartfile.resolved | |
+1 −0 | Carthage/Checkouts/Box | |
+1 −0 | Carthage/Checkouts/Prelude | |
+273 −26 | Either.xcodeproj/project.pbxproj | |
+9 −9 | Either.xcodeproj/xcshareddata/xcschemes/Either-Mac.xcscheme | |
+110 −0 | Either.xcodeproj/xcshareddata/xcschemes/Either-iOS.xcscheme | |
+2 −2 | Either.xcworkspace/contents.xcworkspacedata | |
+21 −0 | Either/Disjunction.swift | |
+35 −14 | Either/Either.swift | |
+6 −4 | Either/EitherType.swift | |
+27 −0 | EitherTests/DisjunctionTests.swift | |
+6 −6 | EitherTests/EitherTests.swift | |
+0 −1 | External/Box | |
+0 −1 | External/Prelude | |
+4 −4 | README.md |
Submodule Madness
updated
55 files
Submodule Nimble
updated
88 files
Submodule Prelude
updated
14 files
Submodule Quick
updated
37 files
Submodule xcconfigs
updated
from b09b4b to 99624a
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,30 +12,27 @@ import Madness | |
import Prelude | ||
|
||
/// Returns a parser which parses one character from the given set. | ||
internal prefix func % (characterSet: NSCharacterSet) -> Parser<String>.Function { | ||
return { string in | ||
let scalars = string.unicodeScalars | ||
|
||
if let scalar = first(scalars) { | ||
if characterSet.longCharacterIsMember(scalar.value) { | ||
return (String(scalar), String(dropFirst(scalars))) | ||
internal prefix func % <C: CollectionType where C.Generator.Element == Character>(characterSet: NSCharacterSet) -> Parser<C, String>.Function { | ||
return { collection, index in | ||
if index != collection.endIndex { | ||
if let scalar = first(String(collection[index]).unicodeScalars) where characterSet.longCharacterIsMember(scalar.value) { | ||
return .right(String(scalar), index.successor()) | ||
} | ||
} | ||
|
||
return nil | ||
return .left(.leaf("Character is not present in NSCharacterSet", index)) | ||
} | ||
} | ||
|
||
/// Removes the characters in the given string from the character set. | ||
internal func - (characterSet: NSCharacterSet, characters: String) -> NSCharacterSet { | ||
let mutableSet = characterSet.mutableCopy() as NSMutableCharacterSet | ||
let mutableSet = characterSet.mutableCopy() as! NSMutableCharacterSet | ||
mutableSet.removeCharactersInString(characters) | ||
return mutableSet | ||
} | ||
|
||
/// Removes characters in the latter set from the former. | ||
internal func - (characterSet: NSCharacterSet, subtrahend: NSCharacterSet) -> NSCharacterSet { | ||
let mutableSet = characterSet.mutableCopy() as NSMutableCharacterSet | ||
let mutableSet = characterSet.mutableCopy() as! NSMutableCharacterSet | ||
mutableSet.formIntersectionWithCharacterSet(subtrahend.invertedSet) | ||
return mutableSet | ||
} | ||
|
@@ -44,8 +41,8 @@ internal func - (characterSet: NSCharacterSet, subtrahend: NSCharacterSet) -> NS | |
postfix operator |? {} | ||
|
||
/// Matches zero or one occurrence of the given parser. | ||
internal postfix func |? <T>(parser: Parser<T>.Function) -> Parser<T?>.Function { | ||
return (parser * (0..<2)) --> first | ||
internal postfix func |? <C: CollectionType, T where C.Generator.Element: Equatable>(parser: Parser<C, T>.Function) -> Parser<C, T?>.Function { | ||
return first <^> (parser * (0..<2)) | ||
} | ||
|
||
private let char_control = NSCharacterSet.controlCharacterSet() | ||
|
@@ -57,43 +54,46 @@ private let char_break = NSCharacterSet.newlineCharacterSet() | |
// TODO: Use this somewhere. | ||
private let char_end = char_control - NSCharacterSet.whitespaceAndNewlineCharacterSet() | ||
|
||
private let wordStart: Parser<String>.Function = %(char_word - "#'\"") | ||
private let wordChars: Parser<String>.Function = (%(char_word - "'\""))* --> { strings in join("", strings) } | ||
private let word: Parser<String>.Function = wordStart ++ wordChars --> (+) | ||
private let br: Parser<()>.Function = ignore(%char_break) | ||
private let eof: Parser<()>.Function = { $0 == "" ? ((), "") : nil } | ||
private let comment: Parser<()>.Function = ignore(%"#" ++ (%char_text)+ ++ (br | eof)) | ||
private let wordStart: Parser<String, String>.Function = %(char_word - "#'\"") | ||
private let wordChars: Parser<String, String>.Function = { join("", $0) } <^> (%(char_word - "'\""))* | ||
private let word: Parser<String, String>.Function = (+) <^> wordStart ++ wordChars | ||
private let br: Parser<String, Ignore>.Function = ignore(%char_break) | ||
private let eof: Parser<String, Ignore>.Function = ignore("")//{ $0 == "" ? ((), "") : nil } | ||
|
||
private let br_eof = br | eof | ||
private let comment: Parser<String, Ignore>.Function = ignore(%"#" ++ (%char_text)+ ++ br_eof) | ||
|
||
// TODO: Escape sequences. | ||
private let singleQuotedChars: Parser<String>.Function = (%(char_text - "'"))* --> { strings in join("", strings) } | ||
private let singleQuoted: Parser<String>.Function = ignore(%"'") ++ singleQuotedChars ++ ignore(%"'") | ||
private let doubleQuotedChars: Parser<String>.Function = (%(char_text - "\""))* --> { strings in join("", strings) } | ||
private let doubleQuoted: Parser<String>.Function = ignore(%"\"") ++ doubleQuotedChars ++ ignore(%"\"") | ||
private let quoted: Parser<String>.Function = singleQuoted | doubleQuoted | ||
private let requiredSpace: Parser<()>.Function = ignore((comment | %char_space)+) | ||
private let optionalSpace: Parser<()>.Function = ignore((comment | %char_space)*) | ||
private let separator: Parser<()>.Function = ignore(optionalSpace ++ %"," ++ optionalSpace) | ||
private let singleQuotedChars: Parser<String, String>.Function = { join("", $0) } <^> (%(char_text - "'"))* | ||
private let singleQuoted: Parser<String, String>.Function = ignore(%"'") ++ singleQuotedChars ++ ignore(%"'") | ||
private let doubleQuotedChars: Parser<String, String>.Function = { join("", $0) } <^> (%(char_text - "\""))* | ||
private let doubleQuoted: Parser<String, String>.Function = ignore(%"\"") ++ doubleQuotedChars ++ ignore(%"\"") | ||
private let quoted: Parser<String, String>.Function = singleQuoted | doubleQuoted | ||
private let requiredSpace: Parser<String, Ignore>.Function = ignore((comment | %char_space)+) | ||
private let optionalSpace: Parser<String, Ignore>.Function = ignore((comment | %char_space)*) | ||
private let separator: Parser<String, Ignore>.Function = ignore(optionalSpace ++ %"," ++ optionalSpace) | ||
|
||
private let value: Parser<String>.Function = word | quoted | ||
private let value: Parser<String, String>.Function = word | quoted | ||
|
||
/// A function taking an Int and returning a parser which parses at least that many | ||
/// indentation characters. | ||
func indentation(n: Int) -> Parser<Int>.Function { | ||
return (%char_space * (n..<Int.max)) --> { $0.count } | ||
func indentation(n: Int) -> Parser<String, Int>.Function { | ||
return count <^> (%char_space * (n..<Int.max)) | ||
} | ||
|
||
// MARK: Generic combinators | ||
// FIXME: move these into Madness. | ||
|
||
/// Delays the evaluation of a parser so that it can be used in a recursive grammar without deadlocking Swift at runtime. | ||
private func lazy<T>(parser: () -> Parser<T>.Function) -> Parser<T>.Function { | ||
private func lazy<C: CollectionType, T where C.Generator.Element: Equatable>(parser: () -> Parser<C, T>.Function) -> Parser<C, T>.Function { | ||
return { parser()($0) } | ||
} | ||
|
||
/// Returns a parser which produces an array of parse trees produced by `parser` interleaved with ignored parses of `separator`. | ||
/// | ||
/// This is convenient for e.g. comma-separated lists. | ||
private func interleave<T, U>(separator: Parser<U>.Function, parser: Parser<T>.Function) -> Parser<[T]>.Function { | ||
return (parser ++ (ignore(separator) ++ parser)*) --> { [$0] + $1 } | ||
private func interleave<C: CollectionType, T, U where C.Generator.Element: Equatable>(separator: Parser<C, U>.Function, parser: Parser<C, T>.Function) -> Parser<C, [T]>.Function { | ||
return { [$0] + $1 } <^> (parser ++ (ignore(separator) ++ parser)*) | ||
} | ||
|
||
private func foldr<S: SequenceType, Result>(sequence: S, initial: Result, combine: (S.Generator.Element, Result) -> Result) -> Result { | ||
|
@@ -105,12 +105,12 @@ private func foldr<G: GeneratorType, Result>(inout generator: G, initial: Result | |
return generator.next().map { combine($0, foldr(&generator, initial, combine)) } ?? initial | ||
} | ||
|
||
private func | <T, U> (left: Parser<T>.Function, right: String -> U) -> Parser<Either<T, U>>.Function { | ||
return left | { (right($0), $0) } | ||
private func | <C: CollectionType, T, U where C.Generator.Element: Equatable>(left: Parser<C, T>.Function, right: () -> U) -> Parser<C, Either<T, U>>.Function { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know it would be better if the type of right was: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, let’s not sweat it. |
||
return left | { .right(right(), $1 == $0.endIndex ? $1 : $1.successor()) } | ||
} | ||
|
||
private func | <T> (left: Parser<T>.Function, right: String -> T) -> Parser<T>.Function { | ||
return left | { (right($0), $0) } | ||
private func | <C: CollectionType, T where C.Generator.Element: Equatable>(left: Parser<C, T>.Function, right: () -> T) -> Parser<C, T>.Function { | ||
return left | { .right(right(), $1 == $0.endIndex ? $1 : $1.successor()) } | ||
} | ||
|
||
private func flatMap<T, U>(x: [T], f: T -> [U]) -> [U] { | ||
|
@@ -119,45 +119,46 @@ private func flatMap<T, U>(x: [T], f: T -> [U]) -> [U] { | |
|
||
// MARK: OGDL | ||
|
||
private let children: Parser<[Node]>.Function = lazy { group | (element --> { elem in [ elem ] }) } | ||
private let children: Parser<String, [Node]>.Function = lazy { group | ({ elem in [ elem ] } <^> element) } | ||
|
||
private let element = lazy { value ++ (optionalSpace ++ children)|? --> { value, children in Node(value: value, children: children ?? []) } } | ||
private let element = lazy { { Node(value: $0, children: $1 ?? []) } <^> value ++ (optionalSpace ++ children)|? } | ||
|
||
// TODO: See Carthage/ogdl-swift#3. | ||
private let block: Int -> Parser<()>.Function = { n in const(nil) } | ||
private let block: Int -> Parser<String, Ignore>.Function = { _ in ignore(any) } | ||
|
||
/// Parses a single descendent element. | ||
/// | ||
/// This is an element which may be an in-line descendent, and which may further have in-line descendents of its own. | ||
private let descendent = value --> { Node(value: $0) } | ||
private let descendent = { Node(value: $0) } <^> value | ||
|
||
/// Parses a sequence of hierarchically descending elements, e.g.: | ||
/// | ||
/// x y z # => Node(x, [Node(y, Node(z))]) | ||
public let descendents: Parser<Node>.Function = interleave(requiredSpace, descendent) --> { | ||
foldr(dropLast($0), last($0)!) { $0.nodeByAppendingChildren([ $1 ]) } | ||
} | ||
public let descendents: Parser<String, Node>.Function = | ||
{ foldr(dropLast($0), last($0)!) { $0.nodeByAppendingChildren([ $1 ]) } } | ||
<^> interleave(requiredSpace, descendent) | ||
|
||
/// Parses a chain of descendents, optionally ending in a group. | ||
/// | ||
/// x y (u, v) # => Node(x, [ Node(y, [ Node(u), Node(v) ]) ]) | ||
private let descendentChain: Parser<Node>.Function = (descendents ++ ((optionalSpace ++ group) | const([]))) --> uncurry(Node.nodeByAppendingChildren) | ||
private let descendentChain: Parser<String, Node>.Function = | ||
uncurry(Node.nodeByAppendingChildren) <^> (descendents ++ ((optionalSpace ++ group) | const([]))) | ||
|
||
/// Parses a sequence of adjacent sibling elements, e.g.: | ||
/// | ||
/// x, y z, w (u, v) # => [ Node(x), Node(y, Node(z)), Node(w, [ Node(u), Node(v) ]) ] | ||
public let adjacent: Parser<[Node]>.Function = lazy { interleave(separator, descendentChain) } | ||
public let adjacent: Parser<String, [Node]>.Function = lazy { interleave(separator, descendentChain) } | ||
|
||
/// Parses a parenthesized sequence of sibling elements, e.g.: | ||
/// | ||
/// (x, y z, w) # => [ Node(x), Node(y, Node(z)), Node(w) ] | ||
private let group = lazy { ignore(%"(") ++ optionalSpace ++ adjacent ++ optionalSpace ++ ignore(%")") } | ||
|
||
private let subgraph: Int -> Parser<[Node]>.Function = { n in | ||
(descendents ++ lines(n + 1) --> { [ $0.nodeByAppendingChildren($1) ] }) | adjacent | ||
private let subgraph: Int -> Parser<String, [Node]>.Function = { n in | ||
({ [ $0.nodeByAppendingChildren($1) ] } <^> descendents ++ lines(n + 1)) | adjacent | ||
} | ||
|
||
private let line: Int -> Parser<[Node]>.Function = fix { line in | ||
private let line: Int -> Parser<String, [Node]>.Function = fix { line in | ||
{ n in | ||
// TODO: block parsing: ignore(%char_space+ ++ block(n))|?) ++ | ||
// See Carthage/ogdl-swift#3. | ||
|
@@ -167,14 +168,14 @@ private let line: Int -> Parser<[Node]>.Function = fix { line in | |
} | ||
} | ||
|
||
private let followingLine: Int -> Parser<[Node]>.Function = { n in (ignore(comment | br)+ ++ line(n)) } | ||
private let lines: Int -> Parser<[Node]>.Function = { n in | ||
(line(n)|? ++ followingLine(n)*) --> { ($0 ?? []) + flatMap($1, id) } | ||
private let followingLine: Int -> Parser<String, [Node]>.Function = { n in (ignore(comment | br)+ ++ line(n)) } | ||
private let lines: Int -> Parser<String, [Node]>.Function = { n in | ||
{ ($0 ?? []) + flatMap($1, id) } <^> (line(n)|? ++ followingLine(n)*) | ||
} | ||
|
||
/// Parses a textual OGDL graph into a list of nodes (and their descendants). | ||
/// | ||
/// Example: | ||
/// | ||
/// let nodes = parse(graph, "foo (bar, buzz baz)") | ||
public let graph: Parser<[Node]>.Function = ignore(comment | br)* ++ (lines(0) | adjacent) ++ ignore(comment | br)* | ||
public let graph: Parser<String, [Node]>.Function = ignore(comment | br)* ++ (lines(0) | adjacent) ++ ignore(comment | br)* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mixing tabs & spaces here, incidentally.