{"action":"closed","issue":{"url":"https://api.github.com/repos/lihaoyi/fastparse/issues/88","repository_url":"https://api.github.com/repos/lihaoyi/fastparse","labels_url":"https://api.github.com/repos/lihaoyi/fastparse/issues/88/labels{/name}","comments_url":"https://api.github.com/repos/lihaoyi/fastparse/issues/88/comments","events_url":"https://api.github.com/repos/lihaoyi/fastparse/issues/88/events","html_url":"https://github.com/lihaoyi/fastparse/issues/88","id":154889335,"node_id":"MDU6SXNzdWUxNTQ4ODkzMzU=","number":88,"title":"Should flatMap intersperse whitespace when using WhitespaceApi ?","user":{"login":"denisrosset","id":93707,"node_id":"MDQ6VXNlcjkzNzA3","avatar_url":"https://avatars0.githubusercontent.com/u/93707?v=4","gravatar_id":"","url":"https://api.github.com/users/denisrosset","html_url":"https://github.com/denisrosset","followers_url":"https://api.github.com/users/denisrosset/followers","following_url":"https://api.github.com/users/denisrosset/following{/other_user}","gists_url":"https://api.github.com/users/denisrosset/gists{/gist_id}","starred_url":"https://api.github.com/users/denisrosset/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/denisrosset/subscriptions","organizations_url":"https://api.github.com/users/denisrosset/orgs","repos_url":"https://api.github.com/users/denisrosset/repos","events_url":"https://api.github.com/users/denisrosset/events{/privacy}","received_events_url":"https://api.github.com/users/denisrosset/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-05-15T04:15:47Z","updated_at":"2018-10-18T05:58:06Z","closed_at":"2018-10-18T05:58:05Z","author_association":"NONE","body":"We want to parse the following: the first line contains the size, the second line an integer sequence of that size. We use WhitespaceApi to define spaces and tabs as whitespace; line endings are considered significant and have their own parser.\n\nWe first parse the size, then the repeated sequence of integers using `flatMap`. However, `flatMap` does not eat whitespace between the first parser and the second parser. Written without an explicit whitespace token (see Scala code below), the following will parse:\n\n```\n2\n3 4\n```\n\nbut not the following:\n\n```\n2\n  3 4\n```\n\nCode below:\n\n``` scala\nimport fastparse.WhitespaceApi\n\nobject Test extends App {\n\n  // whitespace contains spaces and tabs\n  val White = WhitespaceApi.Wrapper{\n    import fastparse.all._\n    NoTrace(CharsWhile(\" \\t\".contains(_)).?)\n  }\n\n  import White._\n  import fastparse.noApi._\n\n  // line endings\n\n  val lineEnding: P[Unit] = P(\"\\r\".? ~ \"\\n\")\n\n  // non-negative integer\n  val nnInt: P[Int] = P( CharIn('0'to'9').repX(1).!.map(_.toInt) )\n\n  // sized sequence of integers, separated by whitespace\n  def seqInt(n: Int): P[Seq[Int]] = nnInt.rep(min=n, max=n)\n\n  // size followed by sized sequence\n  val sizeAndSeqInt: P[Seq[Int]] = (nnInt ~ lineEnding).flatMap( n => seqInt(n) )\n\n  val sizeAndSeqInt1: P[Seq[Int]] = (nnInt ~ lineEnding).flatMap( n => Pass ~ seqInt(n) )\n\n  sizeAndSeqInt.parse(\"2\\n3 4\").get // Success\n\n  sizeAndSeqInt1.parse(\"2\\n 3 4\").get // Success\n\n  sizeAndSeqInt.parse(\"2\\n 3 4\").get // Failure\n\n}\n```\n\nThe behavior is different from the Scala parser combinators and should be documented (or the `flatMap` semantics changed, if it makes sense).\n"}}
{"actor":{"display_login":"lihaoyi"}}