Skip to content

Applicative yields SOE where Monad does not #26

@dashkal16

Description

@dashkal16

Current import: "org.tpolecat" %% "atto-core" % "0.4.2"

Example code:

lazy val exprBad: Parser[Int] = eParensBad | eLiteralInt
lazy val eParensBad: Parser[Int] = char('(') *> many(whitespace) *> exprBad <* many(whitespace) <* char(')')

lazy val exprGood: Parser[Int] = eParensGood | eLiteralInt
lazy val eParensGood: Parser[Int] = {
  for {
    _ <- char('(')
    _ <- many(whitespace)
    e <- exprGood
    _ <- many(whitespace)
    _ <- char(')')
  } yield (e)
}

lazy val eLiteralInt: Parser[Int] = int

def makeItCrash = exprBad.parse("5").done
def worksFine = exprGood.parse("5").done

scala> worksFine
res0: atto.ParseResult[Int] = Done(,5)
scala> makeItCrash
java.lang.StackOverflowError
  <stacktrace bouncing between exprBad and eParensBad>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions