9
9
import ParserCombinator
10
10
import Currier
11
11
12
- /** */
12
+ /**
13
+ Creates a parser to parse a description a draughts game in portable game notation to DraughtsMove objects.
14
+ */
13
15
struct DraughtsNotationParser {
14
16
15
- /** A function to create a parser which handles the parseing of portable game notation for draughts. */
17
+ /**
18
+ Create a parser which performs the parseing of portable game notation for draughts.
19
+
20
+ Once created the parser can be called multiple times for multiple input game strings.
21
+
22
+ - returns: A parser which creates a list of draughts moves from a string in the correct type.
23
+ */
16
24
static func portableGameNotation( ) -> Parser < [ DraughtsMove ] > {
17
25
18
- let lowercaseXIsTrue = character ( isEqualTo: " x " ) . map ( ) { _ in return true }
19
- let hyphenIsFalse = character ( isEqualTo: " - " ) . map ( ) { _ in return false }
20
- let fullStop = character ( isEqualTo: " . " )
21
-
22
- let numberWithPoint = whitespace. zeroOneOrMany *> digit. oneOrMany *> fullStop
23
-
24
26
let singlePieceMove = curry ( DraughtsPieceMove . init) <^> integerNumber
25
27
<*> lowercaseXIsTrue <|> hyphenIsFalse
26
28
<*> integerNumber
@@ -30,7 +32,25 @@ struct DraughtsNotationParser {
30
32
return moveRound. oneOrMany
31
33
}
32
34
33
- /** */
35
+ /// A parser which resolves lowercase x to a boolean true and fails on all other input strings.
36
+ private static let lowercaseXIsTrue = character ( isEqualTo: " x " ) . map ( ) { _ in return true }
37
+
38
+ /// A parser which resolves a hyphen to a boolean false and fails on all other input strings.
39
+ private static let hyphenIsFalse = character ( isEqualTo: " - " ) . map ( ) { _ in return false }
40
+
41
+ /// A parser which resolves a full stop to a success and fails on all other input strings.
42
+ private static let fullStop = character ( isEqualTo: " . " )
43
+
44
+ /// A parser which resolves numbers followed by a fullStop and fails on all other input strings.
45
+ private static let numberWithPoint = whitespace. zeroOneOrMany *> digit. oneOrMany *> fullStop
46
+
47
+ /**
48
+ Combine a description of a single player turn into a full move with up to two player turns.
49
+
50
+ - parameter turn: A parser for a single turn performed by one player.
51
+
52
+ - returns: A parser for a draughts move object describing both playes turn for a move.
53
+ */
34
54
private static func twoPlayerTurn( _ turn: Parser < DraughtsPieceMove > ) -> Parser < DraughtsMove > {
35
55
36
56
let singleMove = whitespace. zeroOneOrMany *> turn
0 commit comments