Skip to content

Commit

Permalink
Removing .? postfix operator
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdsupremacist committed May 6, 2019
1 parent 5af4179 commit 08f2155
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ import Foundation

postfix operator .?

/// Make the value optional. If the value cannot be parsed it will return nil and not consume any tokens
public postfix func .?<P: Parser>(_ p: P) -> AnyParser<P.Token, P.Output?> {
return p.optional()
}
extension TokenProtocol {

public func optional() -> AnyParser<Self, Void> {
return parser.optional().map { _ in () }
}

public postfix func .?<T: TokenProtocol>(_ t: T) -> AnyParser<T, Void> {
return t.parser.optional().map { _ in () }
}

extension Parser {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extension Parser {
if allowsTrailingSeparator {
return separated(by: separator,
allowsTrailingSeparator: false,
allowsEmpty: allowsEmpty) && separator.?
allowsEmpty: allowsEmpty) && separator.optional()
}

if allowsEmpty {
Expand Down
2 changes: 1 addition & 1 deletion Ogma/Classes/Parser/Parsable/Optional+Parsable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ extension Optional: Parsable where Wrapped: Parsable {
public typealias Token = Wrapped.Token

public static var parser: AnyParser<Token, Wrapped?> {
return Wrapped.parser.?
return Wrapped.parser.optional()
}
}

0 comments on commit 08f2155

Please sign in to comment.