Skip to content

Update scalafmt-core to 2.6.0 #88

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 17, 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.5.3
version=2.6.0
style = defaultWithAlign
maxColumn = 100

Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/fpinscalalib/ErrorHandlingSection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import org.scalatest.matchers.should.Matchers

import scala.util.{Success, Try}

/** @param name handling_error_without_exceptions
/**
* @param name handling_error_without_exceptions
*/
object ErrorHandlingSection
extends AnyFlatSpec
Expand Down Expand Up @@ -164,7 +165,6 @@ object ErrorHandlingSection
* mean(xs) flatMap (m => mean(xs.map(x => math.pow(x - m, 2))))
* }}}
*
*
* <b>Exercise 4.3:</b>
*
* Let's write a generic function to combine two `Option` values , so that if any of those values is `None`, the
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/fpinscalalib/FPinScalaLibrary.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ package fpinscalalib

import org.scalaexercises.definitions._

/** Exercises based on Manning's "Functional Programming in Scala" book by Paul Chiusano and Rúnar Bjarnason.
/**
* Exercises based on Manning's "Functional Programming in Scala" book by Paul Chiusano and Rúnar Bjarnason.
*
* @param name fp_in_scala
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import fpinscalalib.customlib.functionaldatastructures._
import fpinscalalib.customlib.functionaldatastructures.List._
import Tree._

/** @param name functional_data_structures
/**
* @param name functional_data_structures
*/
object FunctionalDataStructuresSection
extends AnyFlatSpec
Expand All @@ -42,11 +43,11 @@ object FunctionalDataStructuresSection
* = Singly linked lists =
*
* Assume the following functions are available for your reference:
*{{{
* {{{
* sealed trait List[+A]
* case object Nil extends List[Nothing]
* case class Cons[+A](head: A, tail: List[A]) extends List[A]
*}}}
* }}}
* <b>Exercise 3.1:</b>
*
* Examine the next complex match expression. What will be the result?
Expand Down Expand Up @@ -160,7 +161,6 @@ object FunctionalDataStructuresSection
* <b>Exercise 3.x:</b>
*
* Let's run through the steps that `foldRight` will follow in our new implementation of `sum2`:
*
*/
def listFoldRightSumAssert(
res0: Int,
Expand Down Expand Up @@ -355,7 +355,6 @@ object FunctionalDataStructuresSection
* def filterViaFlatMap[A](l: List[A])(f: A => Boolean): List[A] =
* flatMap(l)(a => if (f(a)) List(a) else Nil)
* }}}
*
*/
/**
* <b>Exercise 3.22:</b>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import java.util.concurrent.Executors

/** @param name purely_functional_parallelism
/**
* @param name purely_functional_parallelism
*/
object FunctionalParallelismSection
extends AnyFlatSpec
Expand Down Expand Up @@ -105,7 +106,7 @@ object FunctionalParallelismSection
* map(sequence(pars))(_.flatten)
* }
* }}}
**/
*/
def parFilterAssert(res0: List[Int]): Unit = {
def parFilter[A](l: List[A])(f: A => Boolean): Par[List[A]] = {
val pars: List[Par[List[A]]] =
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/fpinscalalib/FunctionalStateSection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import fpinscalalib.customlib.state._

/** @param name pure_functional_state
/**
* @param name pure_functional_state
*/
object FunctionalStateSection
extends AnyFlatSpec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ package fpinscalalib
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers

/** @param name getting_started_with_functional_programming
/**
* @param name getting_started_with_functional_programming
*/
object GettingStartedWithFPSection
extends AnyFlatSpec
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/fpinscalalib/ParserCombinatorsSection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import fpinscalalib.customlib.parsing.ReferenceTypes._
import Reference._
import scala.util.matching.Regex

/** @param name parser_combinatorss
/**
* @param name parser_combinatorss
*/
object ParserCombinatorsSection
extends AnyFlatSpec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import fpinscalalib.customlib.testing.{Gen, SGen}
import fpinscalalib.customlib.testing.Gen._
import fpinscalalib.customlib.testing.Prop._

/** @param name property_based_testing
/**
* @param name property_based_testing
*/
object PropertyBasedTestingSection
extends AnyFlatSpec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import fpinscalalib.customlib.laziness.Stream._
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers

/** @param name strictness_and_laziness
/**
* @param name strictness_and_laziness
*/
object StrictnessAndLazinessSection
extends AnyFlatSpec
Expand Down
70 changes: 43 additions & 27 deletions src/main/scala/fpinscalalib/customlib/parsing/ParsersHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,75 +86,91 @@ trait Parsers[Parser[+_]] { self => // so inner classes may call methods of trai

def attempt[A](p: Parser[A]): Parser[A]

/** Sequences two parsers, ignoring the result of the first.
/**
* Sequences two parsers, ignoring the result of the first.
* 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.
/**
* Sequences two parsers, ignoring the result of the second.
* 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
token(quoted label "string literal")

/** C/Java style floating point literals, e.g .1, -1.0, 1e9, 1E-23, etc.
/**
* C/Java style floating point literals, e.g .1, -1.0, 1e9, 1E-23, etc.
* Result is left as a string to keep full precision
*/
def doubleString: Parser[String] =
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 Expand Up @@ -235,17 +251,17 @@ case class ParseError(stack: List[(Location, String)] = List()) {
latest map (_._1)

/**
Display collapsed error stack - any adjacent stack elements with the
same location are combined on one line. For the bottommost error, we
display the full line, with a caret pointing to the column of the error.
Example:

1.1 file 'companies.json'; array
5.1 object
5.2 key-value
5.10 ':'

{ "MSFT" ; 24,
* Display collapsed error stack - any adjacent stack elements with the
* same location are combined on one line. For the bottommost error, we
* display the full line, with a caret pointing to the column of the error.
* Example:
*
* 1.1 file 'companies.json'; array
* 5.1 object
* 5.2 key-value
* 5.10 ':'
*
* { "MSFT" ; 24,
*/
override def toString =
if (stack.isEmpty) "no error message"
Expand Down
9 changes: 6 additions & 3 deletions src/main/scala/fpinscalalib/customlib/parsing/Reference.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ 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]

/** `ParseState` wraps a `Location` and provides some extra
/**
* `ParseState` wraps a `Location` and provides some extra
* convenience functions. The sliceable parsers defined
* in `Sliceable.scala` add an `isSliced` `Boolean` flag
* to `ParseState`.
Expand Down Expand Up @@ -76,7 +78,8 @@ object ReferenceTypes {
case class Success[+A](get: A, length: Int) extends Result[A]
case class Failure(get: ParseError, isCommitted: Boolean) extends Result[Nothing]

/** Returns -1 if s1.startsWith(s2), otherwise returns the
/**
* 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. */
def firstNonmatchingIndex(s1: String, s2: String, offset: Int): Int = {
Expand Down