Skip to content

Commit

Permalink
refactor(debug)!: the debugger and debug packages are merged
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mie6 committed Dec 28, 2024
1 parent a0e4267 commit 595567b
Show file tree
Hide file tree
Showing 33 changed files with 73 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package parsley.debugger.util
package parsley.debug.util

// Sadly, no reflective capabilities exist in Scala.JS or Scala Native, so these
// methods don't do anything yet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package parsley.debugger.internal
package parsley.debug.internal

import scala.scalajs.js

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package parsley.debugger.internal
package parsley.debug.internal

import scala.scalajs.js
import scala.scalajs.js.annotation.JSGlobal

import org.typelevel.scalaccompat.annotation.unused
import parsley.debugger.util.XMutMap
import parsley.debug.util.XMutMap

private [parsley] final class XWeakMap[K <: Object, V] extends XMutMap[K, V] { //
import XWeakMap.WeakMap // scalastyle:ignore import.grouping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package parsley.debugger.internal
package parsley.debug.internal

// Cross platform wrapper around UnsupportedOperationException.
private [parsley] class XUnsupportedOperationException(msg: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package parsley.debugger.internal
package parsley.debug.internal

import scala.collection.mutable

import parsley.debugger.util.XMutMap
import parsley.debug.util.XMutMap

// Abstracts away the logic of XWeakMap so that only minimal interfaces are needed between Scala
// versions. This reduces code duplication, and makes further changes much easier to implement.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package parsley.debugger.util
package parsley.debug.util

import scala.annotation.nowarn
import scala.collection.mutable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package parsley.debugger.util
package parsley.debug.util

// TODO: Find a substitute for Java reflection for Scala 3.
private [parsley] object XCollector extends XDummyCollector
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package parsley.debugger.util
package parsley.debug.util

// This is used to give Scala 2.12 access to "removed" and "updated".
// In Scala 2.13 and up, this doesn't need any extra methods.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package parsley.debugger.util
package parsley.debug.util

import scala.collection.mutable

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private object debuggable {
// the idea is we inject a call to Collector.registerNames with a constructed
// map from these identifiers to their compile-time names
val listOfParsers = q"List(..${parsers.map(tr => q"${Ident(tr)} -> ${tr.toString}")})"
val registration = q"parsley.debugger.util.Collector.registerNames($listOfParsers.toMap)"
val registration = q"parsley.debug.util.Collector.registerNames($listOfParsers.toMap)"
// add the registration as the last statement in the object
// TODO: in future, we want to modify all `def`s with a top level `opaque` combinator
// that will require a bit more modification of the overall `body`, unfortunately
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import scala.quoted.*
val listOfParsers = Expr.ofList {
parsers.map(tr => Expr.ofTuple((Ident(tr).asExprOf[parsley.Parsley[?]], Expr(tr.name)))).toList
}
val registration = '{parsley.debugger.util.Collector.registerNames($listOfParsers.toMap)}.asTerm
val registration = '{parsley.debug.util.Collector.registerNames($listOfParsers.toMap)}.asTerm

// add the registration as the last statement in the object
// TODO: in future, we want to modify all `def`s with a top level `opaque` combinator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package parsley.debugger
package parsley.debug

/** The tree representing a parser's parse tree (its parser execution path).
*
Expand All @@ -20,7 +20,7 @@ package parsley.debugger
*
* @since 4.5.0
*/
private [debugger] abstract class DebugTree extends Iterable[DebugTree] {
private [debug] abstract class DebugTree extends Iterable[DebugTree] {
/** The name of the parser that made this node. */
def parserName: String

Expand Down Expand Up @@ -66,7 +66,7 @@ private [debugger] abstract class DebugTree extends Iterable[DebugTree] {
}
}

private [debugger] object DebugTree {
private [debug] object DebugTree {
def unapply(dt: DebugTree): Some[(String, String, Option[Long], String, Option[ParseAttempt], Map[String, DebugTree])] = {
Some((dt.parserName, dt.internalName, dt.childNumber, dt.fullInput, dt.parseResults, dt.nodeChildren))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package parsley.debugger
package parsley.debug

import parsley.debugger.internal.XIllegalStateException
import parsley.debug.internal.XIllegalStateException

/** A common interface for a rendering view for a debugger to present the debug tree. Inherit from
* one of the two provided subtraits to use.
Expand All @@ -27,7 +27,7 @@ sealed trait DebugView {
* @param input The full input of the parse.
* @param tree Debug tree to render.
*/
private [debugger] def render(input: =>String, tree: =>DebugTree): Unit
private [debug] def render(input: =>String, tree: =>DebugTree): Unit
}
object DebugView {
/** Signifies that the debug view inheriting from this can be used multiple times.
Expand All @@ -44,7 +44,7 @@ object DebugView {
*/
trait SingleUse extends DebugView {
private var hasBeenRun = false
final override private[debugger] def render(input: =>String, tree: =>DebugTree): Unit = {
final override private [debug] def render(input: =>String, tree: =>DebugTree): Unit = {
if (hasBeenRun) {
// XXX: There isn't really another way to enforce not running a stateful frontend more than once that isn't just "do nothing".
// Especially since doing nothing turns that action into a silent error, which is generally less preferable to "loud"
Expand All @@ -56,6 +56,6 @@ object DebugView {
}
}
/** The implementation of the render method above */
private[debugger] def renderImpl(input: =>String, tree: =>DebugTree): Unit
private [debug] def renderImpl(input: =>String, tree: =>DebugTree): Unit
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package parsley.debugger
package parsley.debug

import ParseAttempt._ // scalastyle:ignore underscore.import

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package parsley.debugger
package parsley.debug

import java.io.{OutputStream, PrintStream}

Expand Down Expand Up @@ -32,9 +32,9 @@ object PrintView extends DebugView.Reusable with PrintView {
}
}

private [debugger] sealed trait PrintView extends DebugView.Reusable {
private [debug] sealed trait PrintView extends DebugView.Reusable {
protected val out: PrintStream
override private [debugger] def render(input: =>String, tree: =>DebugTree): Unit = {
override private [debug] def render(input: =>String, tree: =>DebugTree): Unit = {
out.println(s"${tree.parserName}'s parse tree for input:\n\n$input\n\n")
pretty(tree)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package parsley.debugger
package parsley.debug

import parsley.Parsley
import parsley.Parsley.{atomic, empty, fresh}
import parsley.debugger.internal.{DebugContext, DivergenceContext}
import parsley.debug.internal.{DebugContext, DivergenceContext}

import parsley.internal.deepembedding.frontend.LazyParsley
import parsley.internal.deepembedding.frontend.debugger.{TaggedWith, Named}
import parsley.internal.deepembedding.backend.debugger.{CheckDivergence, Debugging}
import parsley.internal.deepembedding.frontend.debug.{TaggedWith, Named}
import parsley.internal.deepembedding.backend.debug.{CheckDivergence, Debugging}

/** This object contains the combinators for attaching debuggers to parsers.
*
Expand Down Expand Up @@ -143,12 +143,12 @@ object combinator {
// TODO: fix docs by incorporating some of the base stuff above
/** Attach a debugger to be rendered via a given view. This view will render whenever the parser produces debug content.
*
* You would normally obtain a [[parsley.debugger.DebugView]] from its
* You would normally obtain a [[parsley.debug.DebugView]] from its
* respective package as either a static object or an instance object depending on whether the
* renderer stores state. In the latter case, it is better to regenerate the frontend with
* every new debugged parser. The view can be reusable (i.e. inherits from
* [[parsley.debugger.DebugView.Reusable]]) or single-use (i.e. inherits from
* [[parsley.debugger.DebugView.SingleUse]]).
* [[parsley.debug.DebugView.Reusable]]) or single-use (i.e. inherits from
* [[parsley.debug.DebugView.SingleUse]]).
*
* The instrumented parser will automatically call the view to render the debug tree, so it
* may be recommended that you only use this with smaller parsers as large parsers may cause
Expand Down Expand Up @@ -188,7 +188,7 @@ object combinator {
* @note Do not run a parser through this combinator multiple times.
* @see
* The other overload of this method
* ([[parsley.debugger.combinator$.attach[A](parser:parsley\.Parsley[A],view:parsley\.debugger\.DebugView,toStringRules* attachDebugger]])
* ([[parsley.debug.combinator$.attach[A](parser:parsley\.Parsley[A],view:parsley\.debug\.DebugView,toStringRules* attachDebugger]])
* has more information on its usage.
* @param parser The parser to debug.
* @param view The debug view instance to render with.
Expand Down Expand Up @@ -219,7 +219,7 @@ object combinator {
* @note Do not run a parser through this combinator multiple times.
* @see
* The other overload of this method
* ([[parsley.debugger.combinator$.attachReusable[A](parser:parsley\.Parsley[A],view:=>parsley\.debugger\.DebugView\.Reusable,toStringRules* attachDebugger]])
* ([[parsley.debug.combinator$.attachReusable[A](parser:parsley\.Parsley[A],view:=>parsley\.debug\.DebugView\.Reusable,toStringRules* attachDebugger]])
* has more information on its usage.
* @return Generator closure for view-debugged versions of the input parser.
*/
Expand Down Expand Up @@ -252,7 +252,7 @@ object combinator {
//def attach[A](parser: Parsley[A])(implicit frontend: DebugFrontend): Parsley[A] = attach[A](parser, defaultRules)

/** Attach a name to a parser, for display within the debugger output.
* Names assigned here have a higher precedence than names collected with [[parsley.debugger.util.Collector]].
* Names assigned here have a higher precedence than names collected with [[parsley.debug.util.Collector]].
*
* Renaming the same parser multiple times simply overwrites its name to the most latest rename.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package parsley.debugger.internal
package parsley.debug.internal

import scala.collection.mutable

import org.typelevel.scalaccompat.annotation.unused
import parsley.XAssert
import parsley.debugger.ParseAttempt
import parsley.debug.ParseAttempt
import parsley.internal.deepembedding.frontend.LazyParsley

// Class used to hold details about a parser being debugged.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package parsley.debugger.internal
package parsley.debug.internal

import scala.annotation.nowarn
import scala.collection.mutable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package parsley.debugger.internal
package parsley.debug.internal

import parsley.internal.deepembedding.frontend.LazyParsley
import parsley.internal.deepembedding.frontend.debugger.TaggedWith
import parsley.internal.deepembedding.frontend.debug.TaggedWith

// An object with a single public apply method that allows the renaming of a
// debugged parser's name in order to increase the clarity of the debugger's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package parsley.debugger.internal
package parsley.debug.internal

import scala.collection.immutable.ListMap
import scala.collection.mutable

import parsley.debugger.{DebugTree, ParseAttempt}
import parsley.debugger.util.XMap
import parsley.debug.{DebugTree, ParseAttempt}
import parsley.debug.util.XMap

/** A mutable implementation of [[DebugTree]], used when constructing the tree as a parser is
* running.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package parsley.debugger.util
package parsley.debug.util

//import scala.annotation.nowarn

import parsley.Parsley
import parsley.debugger.internal.Renamer
import parsley.debug.internal.Renamer
import parsley.token.Lexer

import parsley.internal.deepembedding.frontend.LazyParsley
Expand Down Expand Up @@ -66,7 +66,7 @@ object Collector {
* automatically finding parsers in objects and getting their field names as written in your
* parser code?
*
* @note Manually named parsers using [[parsley.debugger.combinator.named]]
* @note Manually named parsers using [[parsley.debug.combinator.named]]
* will still work regardless if the platform is supported or not.
*/
@inline def isSupported: Boolean = XCollector.supported
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package parsley.debugger.util
package parsley.debug.util

import parsley.token.Lexer

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package parsley.internal.deepembedding.backend.debugger
package parsley.internal.deepembedding.backend.debug

import parsley.debugger.internal.{DebugContext, DivergenceContext}
import parsley.debug.internal.{DebugContext, DivergenceContext}

import parsley.internal.deepembedding.ContOps
import parsley.internal.deepembedding.ContOps.{suspend, ContAdapter}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package parsley.internal.deepembedding.frontend.debugger
package parsley.internal.deepembedding.frontend.debug

import parsley.XAssert

Expand Down
Loading

0 comments on commit 595567b

Please sign in to comment.