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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .swift-version

This file was deleted.

6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
osx_image: xcode9
osx_image: xcode10.3
language: objective-c

install:
Expand All @@ -10,7 +10,7 @@ script:

- swiftlint

- xcodebuild test -project ParserCombinator.xcodeproj -scheme ParserCombinator-iOS -destination 'platform=iOS Simulator,OS=latest,name=iPhone 7'
- xcodebuild test -project ParserCombinator.xcodeproj -scheme ParserCombinator-iOS -destination 'platform=iOS Simulator,OS=latest,name=iPhone 8'
- xcodebuild test -project ParserCombinator.xcodeproj -scheme ParserCombinator-macOS -destination 'platform=macOS,arch=x86_64'
- xcodebuild test -project ParserCombinator.xcodeproj -scheme ParserCombinator-tvOS -destination 'platform=tvOS Simulator,name=Apple TV 1080p'
- xcodebuild test -project ParserCombinator.xcodeproj -scheme ParserCombinator-tvOS -destination 'platform=tvOS Simulator,OS=latest,name=Apple TV 4K'
- xcodebuild -project ParserCombinator.xcodeproj -scheme ParserCombinator-watchOS
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,13 @@
* Swift 4 and Xcode 9 updates.
* Swiftlint version update to 0.22.0
* Add failure messages to all XCFail test cases.

## Version 2.0.0

### *Released 2019-08-18*

* Swift 5 and Xcode 10.3 updates.
* Swiftlint version update to 0.34.0
* Remove string copies using Swift 5 string updates.
* Remove some typealiases masking Swift types for transparency.
* Increase unit test readability.
5 changes: 3 additions & 2 deletions ParserCombinator.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

Pod::Spec.new do |s|
s.name = 'ParserCombinator'
s.version = '1.1.0'
s.version = '2.0.0'
s.summary = 'Exquisitely simple functional parsing in Swift.'
s.description = <<-DESC
A simple parser combinator, created in Swift. Functional parser combinators can be extremely useful but can also be difficult to understand. ParserCombinator attempts to strip this back and create a simple and user friendly way to parse strings into other objects. Technical terms, like mooned, are avoided or explained if necessary and docs are provided in plain English, with examples.
A simple parser combinator, created in Swift. Functional parser combinators can be extremely useful but can also be difficult to understand. ParserCombinator attempts to strip this back and create a simple and user friendly way to parse complex strings into other objects. Technical terms, like 'monad', are avoided or explained if necessary and docs are provided in plain English, with examples.
DESC

s.homepage = 'https://github.com/tigerpixel/ParserCombinator'
Expand All @@ -22,6 +22,7 @@ A simple parser combinator, created in Swift. Functional parser combinators can
s.watchos.deployment_target = '2.0'
s.osx.deployment_target = '10.9'
s.tvos.deployment_target = '9.0'
s.swift_version = '5.0'

s.source_files = 'Source/**/*.swift'
end
83 changes: 34 additions & 49 deletions ParserCombinator.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
LastUpgradeVersion = "1030"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,7 +26,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -56,7 +55,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
LastUpgradeVersion = "1030"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,7 +26,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -56,7 +55,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
LastUpgradeVersion = "1030"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,7 +26,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -56,7 +55,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
LastUpgradeVersion = "1030"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,7 +26,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -56,7 +55,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
2 changes: 1 addition & 1 deletion ParserCombinator/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.1.0</string>
<string>2.0.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHumanReadableCopyright</key>
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ Pull requests for improvements are welcome.
There are no external requirements for this project, just Swift.

- iOS 8.0+ / macOS 10.9+ / tvOS 9.0+ / watchOS 2.0+
- Xcode 9.0+
- Swift 4.0+
- Xcode 10.3+
- Swift 5.0+

For previous versions of Xcode and Swift please see prior releases.

## Installation

### Cocoapods

ParserCombinator is available through [CocoaPods](http://cocoapods.org). To install it, simply add the following line to your Podfile:
ParserCombinator is available through [CocoaPods](https://cocoapods.org/pods/ParserCombinator). To install it, simply add the following line to your Podfile:

```ruby
pod "ParserCombinator"
Expand Down
11 changes: 7 additions & 4 deletions Source/CharacterParsers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ public func character(condition: @escaping (Character) -> Bool) -> Parser<Charac

guard condition(character) else {

return .failure(details: .unexpectedToken(token: character.tokenized(), tail: tail))
let failure: ParseFailure = .unexpectedToken(token: character,
tail: tail)

return .failure(details: failure)
}

// Drop first element so that the parser moves on from the current character.
Expand Down Expand Up @@ -82,7 +85,7 @@ public func character(isEqualTo token: Character) -> Parser<Character> {
- returns: The parser which will only allow the given characters to pass, all others will fail.
*/
public func character(isInString string: String) -> Parser<Character> {
return character { string.characters.contains($0) }
return character { string.contains($0) }
}

// MARK: Pre-made pasers using the character parser function for common sets of characters.
Expand Down Expand Up @@ -117,7 +120,7 @@ public let whitespaceOrNewline = character(isInCharacterSet: .whitespacesAndNewl
// MARK: Pre-made pasers using the character parser function for single everyday characters.

/// Only the comma character will pass, all others will fail.
public let comma = character(isEqualTo:",")
public let comma = character(isEqualTo: ",")

/// Only the full-stop character will pass, all others will fail.
public let fullstop = character(isEqualTo:".")
public let fullstop = character(isEqualTo: ".")
7 changes: 3 additions & 4 deletions Source/ParseResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

public enum ParseResult<Output> {

case success(result: Output, tail: TokenStream)
case success(result: Output, tail: Substring)
case failure(details: ParseFailure)

}
Expand Down Expand Up @@ -55,9 +55,8 @@ public extension ParseResult {
public enum ParseFailure: Equatable {

case insufficiantTokens
case unexpectedToken(token: TokenStream, tail: TokenStream)
case unexpectedToken(token: Character, tail: Substring)
case custom(message: String)

}

/**
Expand All @@ -73,7 +72,7 @@ public func == (left: ParseFailure, right: ParseFailure) -> Bool {
case (.insufficiantTokens, .insufficiantTokens):
return true
case (.unexpectedToken(let leftToken, let leftTail), .unexpectedToken(let rightToken, let rightTail)):
return String(leftToken) == String(rightToken) && String(leftTail) == String(rightTail)
return leftToken == rightToken && leftTail == rightTail
case (.custom(let leftMesage), .custom(let rightMessage)):
return leftMesage == rightMessage
default:
Expand Down
4 changes: 2 additions & 2 deletions Source/Parser+Run.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public extension Parser {
*/

func run(withInput input: String) -> ParseResult<Output> {
return parse(input.characters)
return parse(Substring(input))
}

/**
Expand All @@ -39,7 +39,7 @@ public extension Parser {

func runAndResolve(withInput input: String) -> Output? {

guard case .success(let result, _) = parse(input.characters) else {
guard case .success(let result, _) = parse(Substring(input)) else {
return nil
}

Expand Down
5 changes: 2 additions & 3 deletions Source/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
public struct Parser<Output> {

///A function that specifices the consuming of zero or more tokens and resolving them into a result.
let parse: (TokenStream) -> ParseResult<Output>

let parse: (Substring) -> ParseResult<Output>
}

public extension Parser {
Expand Down Expand Up @@ -54,5 +53,5 @@ public extension Parser {

public func pure<Output>(_ input: Output) -> Parser<Output> {

return Parser { .success(result: input, tail: $0) }
return Parser { ParseResult<Output>.success(result: input, tail: $0) }
}
25 changes: 0 additions & 25 deletions Source/TokenStream.swift

This file was deleted.

Loading