Skip to content

Update scalafmt-core to 2.6.1 #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 29, 2020
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
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=2.6.0
version=2.6.1
style = defaultWithAlign
maxColumn = 100

Expand Down
45 changes: 30 additions & 15 deletions src/main/scala/fpinscalalib/customlib/parsing/ParsersHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,37 +88,44 @@ trait Parsers[Parser[+_]] { self => // so inner classes may call methods of trai

/**
* Sequences two parsers, ignoring the result of the first.
* We wrap the ignored half in slice, since we don't care about its result. */
* We wrap the ignored half in slice, since we don't care about its result.
*/
def skipL[B](p: Parser[Any], p2: => Parser[B]): Parser[B] =
map2(slice(p), p2)((_, b) => b)

/**
* Sequences two parsers, ignoring the result of the second.
* We wrap the ignored half in slice, since we don't care about its result. */
* We wrap the ignored half in slice, since we don't care about its result.
*/
def skipR[A](p: Parser[A], p2: => Parser[Any]): Parser[A] =
map2(p, slice(p2))((a, b) => a)

def opt[A](p: Parser[A]): Parser[Option[A]] =
p.map(Some(_)) or succeed(None)

/**
* Parser which consumes zero or more whitespace characters. */
* Parser which consumes zero or more whitespace characters.
*/
def whitespace: Parser[String] = "\\s*".r

/**
* Parser which consumes 1 or more digits. */
* Parser which consumes 1 or more digits.
*/
def digits: Parser[String] = "\\d+".r

/**
* Parser which consumes reluctantly until it encounters the given string. */
* Parser which consumes reluctantly until it encounters the given string.
*/
def thru(s: String): Parser[String] = (".*?" + Pattern.quote(s)).r

/**
* Unescaped string literals, like "foo" or "bar". */
* Unescaped string literals, like "foo" or "bar".
*/
def quoted: Parser[String] = string("\"") *> thru("\"").map(_.dropRight(1))

/**
* Unescaped or escaped string literals, like "An \n important \"Quotation\"" or "bar". */
* Unescaped or escaped string literals, like "An \n important \"Quotation\"" or "bar".
*/
def escapedQuoted: Parser[String] =
// rather annoying to write, left as an exercise
// we'll just use quoted (unescaped literals) for now
Expand All @@ -132,45 +139,53 @@ trait Parsers[Parser[+_]] { self => // so inner classes may call methods of trai
token("[-+]?([0-9]*\\.)?[0-9]+([eE][-+]?[0-9]+)?".r)

/**
* Floating point literals, converted to a `Double`. */
* Floating point literals, converted to a `Double`.
*/
def double: Parser[Double] =
doubleString map (_.toDouble) label "double literal"

/**
* Attempts `p` and strips trailing whitespace, usually used for the tokens of a grammar. */
* Attempts `p` and strips trailing whitespace, usually used for the tokens of a grammar.
*/
def token[A](p: Parser[A]): Parser[A] =
attempt(p) <* whitespace

/**
* Zero or more repetitions of `p`, separated by `p2`, whose results are ignored. */
* Zero or more repetitions of `p`, separated by `p2`, whose results are ignored.
*/
def sep[A](
p: Parser[A],
p2: Parser[Any]
): Parser[List[A]] = // use `Parser[Any]` since don't care about result type of separator
sep1(p, p2) or succeed(List())

/**
* One or more repetitions of `p`, separated by `p2`, whose results are ignored. */
* One or more repetitions of `p`, separated by `p2`, whose results are ignored.
*/
def sep1[A](p: Parser[A], p2: Parser[Any]): Parser[List[A]] =
map2(p, many(p2 *> p))(_ :: _)

/**
* Parses a sequence of left-associative binary operators with the same precedence. */
* Parses a sequence of left-associative binary operators with the same precedence.
*/
def opL[A](p: Parser[A])(op: Parser[(A, A) => A]): Parser[A] =
map2(p, many(op ** p))((h, t) => t.foldLeft(h)((a, b) => b._1(a, b._2)))

/**
* Wraps `p` in start/stop delimiters. */
* Wraps `p` in start/stop delimiters.
*/
def surround[A](start: Parser[Any], stop: Parser[Any])(p: => Parser[A]) =
start *> p <* stop

/**
* A parser that succeeds when given empty input. */
* A parser that succeeds when given empty input.
*/
def eof: Parser[String] =
regex("\\z".r).label("unexpected trailing characters")

/**
* The root of the grammar, expects no further input following `p`. */
* The root of the grammar, expects no further input following `p`.
*/
def root[A](p: Parser[A]): Parser[A] =
p <* eof

Expand Down
6 changes: 4 additions & 2 deletions src/main/scala/fpinscalalib/customlib/parsing/Reference.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import scala.util.matching.Regex
object ReferenceTypes {

/**
* A parser is a kind of state action that can fail. */
* A parser is a kind of state action that can fail.
*/
type Parser[+A] = ParseState => Result[A]

/**
Expand Down Expand Up @@ -81,7 +82,8 @@ object ReferenceTypes {
/**
* Returns -1 if s1.startsWith(s2), otherwise returns the
* first index where the two strings differed. If s2 is
* longer than s1, returns s1.length. */
* longer than s1, returns s1.length.
*/
def firstNonmatchingIndex(s1: String, s2: String, offset: Int): Int = {
var i = 0
while (
Expand Down