Skip to content

Commit ed528a5

Browse files
Merge pull request #96 from scala-exercises/update/scalafmt-core-2.6.1
Update scalafmt-core to 2.6.1
2 parents 96cafba + d78bc76 commit ed528a5

File tree

3 files changed

+35
-18
lines changed

3 files changed

+35
-18
lines changed

.scalafmt.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version=2.6.0
1+
version=2.6.1
22
style = defaultWithAlign
33
maxColumn = 100
44

src/main/scala/fpinscalalib/customlib/parsing/ParsersHelper.scala

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/main/scala/fpinscalalib/customlib/parsing/Reference.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import scala.util.matching.Regex
2828
object ReferenceTypes {
2929

3030
/**
31-
* A parser is a kind of state action that can fail. */
31+
* A parser is a kind of state action that can fail.
32+
*/
3233
type Parser[+A] = ParseState => Result[A]
3334

3435
/**
@@ -81,7 +82,8 @@ object ReferenceTypes {
8182
/**
8283
* Returns -1 if s1.startsWith(s2), otherwise returns the
8384
* first index where the two strings differed. If s2 is
84-
* longer than s1, returns s1.length. */
85+
* longer than s1, returns s1.length.
86+
*/
8587
def firstNonmatchingIndex(s1: String, s2: String, offset: Int): Int = {
8688
var i = 0
8789
while (

0 commit comments

Comments
 (0)