Skip to content
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

Extremely slow parsing #67

Closed
vigoo opened this issue Apr 22, 2022 · 0 comments · Fixed by #68
Closed

Extremely slow parsing #67

vigoo opened this issue Apr 22, 2022 · 0 comments · Fixed by #68
Labels
bug Something isn't working

Comments

@vigoo
Copy link
Collaborator

vigoo commented Apr 22, 2022

As we discovered on Zymposium on 22th of April, this example:

import zio.Chunk
import zio.parser._
import zio.parser.internal.Debug

object Example extends App {


  case class ChessCoord(row: Char, col: Byte)
  case class ChessMove(from: ChessCoord, to: ChessCoord)

  val chessCoord =
    (Syntax.charIn("ABCDEFGH") ~ Syntax.digit.transform(
      _.toString.toByte,
      (byte: Byte) => byte.toString.head
    )).transform(
      { case (r, c) => ChessCoord(r, c) },
      (cc: ChessCoord) => (cc.row, cc.col)
    )

  val whitespaces = Syntax.whitespace.repeat.unit(Chunk(' '))

  val chessMove =
    (chessCoord ~ whitespaces ~ Syntax.string("->", ()) ~ whitespaces ~ chessCoord).transform(
      { case (from ,to) => ChessMove(from, to) },
      (cm: ChessMove) => (cm.from, cm.to)
    )

  Debug.printParserTree(chessMove.asParser.optimized)

  val parsed = chessMove.parseString("""E1  -> A4""")
  val printed = chessMove.printString(parsed.toOption.get)

  println(parsed)
  println(printed)
}

runs very slowly.

@vigoo vigoo added the bug Something isn't working label Apr 22, 2022
vigoo added a commit to vigoo/zio-parser that referenced this issue Apr 22, 2022
@vigoo vigoo closed this as completed in #68 Apr 22, 2022
vigoo added a commit that referenced this issue Apr 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant