@@ -88,37 +88,44 @@ trait Parsers[Parser[+_]] { self => // so inner classes may call methods of trai
8888
8989 /**
9090 * Sequences two parsers, ignoring the result of the first.
91- * We wrap the ignored half in slice, since we don't care about its result. */
91+ * We wrap the ignored half in slice, since we don't care about its result.
92+ */
9293 def skipL [B ](p : Parser [Any ], p2 : => Parser [B ]): Parser [B ] =
9394 map2(slice(p), p2)((_, b) => b)
9495
9596 /**
9697 * Sequences two parsers, ignoring the result of the second.
97- * We wrap the ignored half in slice, since we don't care about its result. */
98+ * We wrap the ignored half in slice, since we don't care about its result.
99+ */
98100 def skipR [A ](p : Parser [A ], p2 : => Parser [Any ]): Parser [A ] =
99101 map2(p, slice(p2))((a, b) => a)
100102
101103 def opt [A ](p : Parser [A ]): Parser [Option [A ]] =
102104 p.map(Some (_)) or succeed(None )
103105
104106 /**
105- * Parser which consumes zero or more whitespace characters. */
107+ * Parser which consumes zero or more whitespace characters.
108+ */
106109 def whitespace : Parser [String ] = " \\ s*" .r
107110
108111 /**
109- * Parser which consumes 1 or more digits. */
112+ * Parser which consumes 1 or more digits.
113+ */
110114 def digits : Parser [String ] = " \\ d+" .r
111115
112116 /**
113- * Parser which consumes reluctantly until it encounters the given string. */
117+ * Parser which consumes reluctantly until it encounters the given string.
118+ */
114119 def thru (s : String ): Parser [String ] = (" .*?" + Pattern .quote(s)).r
115120
116121 /**
117- * Unescaped string literals, like "foo" or "bar". */
122+ * Unescaped string literals, like "foo" or "bar".
123+ */
118124 def quoted : Parser [String ] = string(" \" " ) *> thru(" \" " ).map(_.dropRight(1 ))
119125
120126 /**
121- * Unescaped or escaped string literals, like "An \n important \"Quotation\"" or "bar". */
127+ * Unescaped or escaped string literals, like "An \n important \"Quotation\"" or "bar".
128+ */
122129 def escapedQuoted : Parser [String ] =
123130 // rather annoying to write, left as an exercise
124131 // we'll just use quoted (unescaped literals) for now
@@ -132,45 +139,53 @@ trait Parsers[Parser[+_]] { self => // so inner classes may call methods of trai
132139 token(" [-+]?([0-9]*\\ .)?[0-9]+([eE][-+]?[0-9]+)?" .r)
133140
134141 /**
135- * Floating point literals, converted to a `Double`. */
142+ * Floating point literals, converted to a `Double`.
143+ */
136144 def double : Parser [Double ] =
137145 doubleString map (_.toDouble) label " double literal"
138146
139147 /**
140- * Attempts `p` and strips trailing whitespace, usually used for the tokens of a grammar. */
148+ * Attempts `p` and strips trailing whitespace, usually used for the tokens of a grammar.
149+ */
141150 def token [A ](p : Parser [A ]): Parser [A ] =
142151 attempt(p) <* whitespace
143152
144153 /**
145- * Zero or more repetitions of `p`, separated by `p2`, whose results are ignored. */
154+ * Zero or more repetitions of `p`, separated by `p2`, whose results are ignored.
155+ */
146156 def sep [A ](
147157 p : Parser [A ],
148158 p2 : Parser [Any ]
149159 ): Parser [List [A ]] = // use `Parser[Any]` since don't care about result type of separator
150160 sep1(p, p2) or succeed(List ())
151161
152162 /**
153- * One or more repetitions of `p`, separated by `p2`, whose results are ignored. */
163+ * One or more repetitions of `p`, separated by `p2`, whose results are ignored.
164+ */
154165 def sep1 [A ](p : Parser [A ], p2 : Parser [Any ]): Parser [List [A ]] =
155166 map2(p, many(p2 *> p))(_ :: _)
156167
157168 /**
158- * Parses a sequence of left-associative binary operators with the same precedence. */
169+ * Parses a sequence of left-associative binary operators with the same precedence.
170+ */
159171 def opL [A ](p : Parser [A ])(op : Parser [(A , A ) => A ]): Parser [A ] =
160172 map2(p, many(op ** p))((h, t) => t.foldLeft(h)((a, b) => b._1(a, b._2)))
161173
162174 /**
163- * Wraps `p` in start/stop delimiters. */
175+ * Wraps `p` in start/stop delimiters.
176+ */
164177 def surround [A ](start : Parser [Any ], stop : Parser [Any ])(p : => Parser [A ]) =
165178 start *> p <* stop
166179
167180 /**
168- * A parser that succeeds when given empty input. */
181+ * A parser that succeeds when given empty input.
182+ */
169183 def eof : Parser [String ] =
170184 regex(" \\ z" .r).label(" unexpected trailing characters" )
171185
172186 /**
173- * The root of the grammar, expects no further input following `p`. */
187+ * The root of the grammar, expects no further input following `p`.
188+ */
174189 def root [A ](p : Parser [A ]): Parser [A ] =
175190 p <* eof
176191
0 commit comments