From 70e623f32e1b6b68855a90327b68192f30d33f88 Mon Sep 17 00:00:00 2001 From: Lucas Satabin Date: Tue, 26 Sep 2023 17:50:44 +0200 Subject: [PATCH] Clarify optmization parameter and pretty-print order --- .../shared/src/main/scala/fs2/data/esp/Tag.scala | 3 ++- .../main/scala/fs2/data/mft/query/QueryCompiler.scala | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/finite-state/shared/src/main/scala/fs2/data/esp/Tag.scala b/finite-state/shared/src/main/scala/fs2/data/esp/Tag.scala index 276f6ad00..195d046e9 100644 --- a/finite-state/shared/src/main/scala/fs2/data/esp/Tag.scala +++ b/finite-state/shared/src/main/scala/fs2/data/esp/Tag.scala @@ -67,7 +67,8 @@ object Tag { case Value(v) => show"$v" } - implicit def order[T: Order]: Order[Tag[T]] = Order.from { + // this is an arbitrary order used for pretty printing only for now + private[esp] implicit def order[T: Order]: Order[Tag[T]] = Order.from { case (Name(n1), Name(n2)) => Order[T].compare(n1, n2) case (Name(_), _) => -1 case (Open, Name(_)) => 1 diff --git a/finite-state/shared/src/main/scala/fs2/data/mft/query/QueryCompiler.scala b/finite-state/shared/src/main/scala/fs2/data/mft/query/QueryCompiler.scala index 55dbb5dbb..c58473014 100644 --- a/finite-state/shared/src/main/scala/fs2/data/mft/query/QueryCompiler.scala +++ b/finite-state/shared/src/main/scala/fs2/data/mft/query/QueryCompiler.scala @@ -58,6 +58,15 @@ private[fs2] abstract class QueryCompiler[Tag, Path] { /** Return the constructor tag of this pattern, or `None` if it is a wildcard. */ def tagOf(pattern: Pattern): Option[Tag] + /** Compiles the `query` into an [[MFT Macro Forest Transducer]]. + * The `credit` parameter defines the maximum number of optimization passes that + * are performed on the resulting MFT. + * Optimization passes allow to reduce the size of the generated MFT + * and used parameters, which improve the runtime characteristics of the + * results. + * + * If you do not want to perform any optimization, you can set this value to `0`. + */ def compile(query: Query[Tag, Path], credit: Int = 50): MFT[NonEmptyList[Guard], Tag, Tag] = { val mft = dsl[NonEmptyList[Guard], Tag, Tag] { implicit builder => val q0 = state(args = 0, initial = true)