Skip to content

Commit

Permalink
feat(debug)!: removed some unneeded methods
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mie6 committed Dec 28, 2024
1 parent a59d1d2 commit 9f4989f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,13 @@ private [parsley] final class DivergenceContext {
s"""
|Left-recursion has been detected in the given parser; however, there is not
|enough information to determine the cycle. To get the full cycle diagnostic,
|please use `parsley.debugger.util.Collector` to populate the name information
|(this is ${if (parsley.debugger.util.Collector.isSupported) "supported" else "not supported"} on your platform).
|please use `parsley.debuggable` annotation to populate the name information.
|
|For example, if your parsers are exposed (publically) in an object called
|`foo`, you should run:
|`foo`, you should write:
|
|> parsley.debugger.util.Collector.names(foo)
|> @parsley.debuggable object foo { ... }
|
|Do this before running the `detectDivergence(foo.[...]).parse([...])` call.
|Alternatively, you can give individual parser fragments names by using the
|`named` combinator, which will cause them to appear along the path.
|""".stripMargin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,91 +5,87 @@
*/
package parsley.debugger.util

import scala.annotation.nowarn
//import scala.annotation.nowarn

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

import parsley.internal.deepembedding.frontend.LazyParsley

/** Attempt to collect all the fields in a class or object that contain a
* parser of type [[parsley.Parsley]], or from a [[parsley.token.Lexer]].
*
* This information is used later in the debug tree-building process to rename certain parsers
* so that they do not end up being named things like "packageanon".
*
* You only need to run this once per parser-holding object.
/** This is an internal class that is used by `parsley.debuggable` annotation to
* perform the naming for the parsers. Until the lexer has proper naming built into
* parsley itself, you might want to use [[Collector.lexer]] to extract meaningful
* names for your lexer combinators; however, this will be removed in future.
*
* @since 4.5.0
*/
object Collector {
/** Collect names of parsers from an object.
/* Collect names of parsers from an object.
*
* @note For Scala 3 on the JVM, it is advised that all parsers in objects being introspected are
* marked `public`, as otherwise, a semi-deprecated call to `setAccessible` will be called on
* a private object, which may be restricted or removed in a future version of the JVM. It may
* be advised to manually name one's parsers (to be debugged) using [[assignName]] or
* be advised to manually name one's parsers (to be debugged) using
* [[parsley.debugger.combinator.named]] if that warning is not desirable.
*/
@deprecated("The functionality of this class has been subsumed by the `parsley.debuggable` annotation", "5.0.0-M7")
/*
def names(obj: Any): Unit = {
collectDefault() // Runs only once, ever, for a program execution.
//collectDefault()
Renamer.addNames(XCollector.collectNames(obj))
}
}*/

/** This is an internal method used by the `parsley.debuggable` annotation */
def registerNames(names: Map[Parsley[_], String]): Unit = {
Renamer.addNames(names.map {
case (k, v) => k.internal -> v
})
Renamer.addNames(names.map { case (k, v) => k.internal -> v })
}

/** Collect names of parsers from a [[parsley.token.Lexer]].
*
* @note For Scala 3 on the JVM, this may trigger a warning about `setAccessible` for private members
* being deprecated.
* @see [[names]] for more information regarding the warning.
*/
//@deprecated("This functionality has been absorbed into parsley itself", "5.0.0-M7")
def lexer(lexer: Lexer): Unit = {
collectDefault()
//collectDefault()
Renamer.addNames(XCollector.collectLexer(lexer))
}

// $COVERAGE-OFF$
/** Manually add a name for a parser by reference.
/* Manually add a name for a parser by reference.
*
* Can also be used if a more informative name for a parser is wanted.
* In this case, use this method after using [[names]] or [[lexer]] to override the automatically
* collected / found name.
*
* @note Names assigned using this will take precedence over names assigned using [[parsley.debugger.combinator.named]].
*/
def assignName(par: Parsley[_], name: String): Unit = Renamer.addName(par.internal, name)
//def assignName(par: Parsley[_], name: String): Unit = Renamer.addName(par.internal, name)

/** Does the implementation of the collector for the current Scala platform actually work in
* automatically finding parsers in objects and getting their field names as written in your
* parser code?
*
* @note Manually named parsers using [[assignName]] or [[parsley.debugger.combinator.named]]
* @note Manually named parsers using [[parsley.debugger.combinator.named]]
* will still work regardless if the platform is supported or not.
*/
@inline def isSupported: Boolean = XCollector.supported

/** Collect the names of Parsley's various default singleton parsers. */
private var defaultCollected: Boolean = false
/* Collect the names of Parsley's various default singleton parsers. */
// this is now done via uo()
/*private var defaultCollected: Boolean = false
private def collectDefault(): Unit = if (isSupported) {
this.synchronized {
if (!defaultCollected) {
defaultCollected = true
names(parsley.character): @nowarn
names(parsley.combinator): @nowarn
names(parsley.Parsley): @nowarn
names(parsley.position): @nowarn
names(parsley.character)//: @nowarn
names(parsley.combinator)//: @nowarn
names(parsley.Parsley)//: @nowarn
names(parsley.position)//: @nowarn
}
}
}
}*/
// $COVERAGE-ON$
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import scala.annotation.experimental

import org.scalatest.Assertions.fail
import parsley.ParsleyTest
import parsley.debugger.DebuggerUsageSpec
import parsley.debugger.internal.{DebugContext, Renamer}
import parsley.debugger.util.Collector
import parsley.internal.deepembedding.backend.StrictParsley
Expand Down Expand Up @@ -52,15 +51,15 @@ class RenameSpec extends ParsleyTest {
Renamer.nameOf(Some("knownName"), exampleParser) shouldBe "knownName"
}

"the Collector implementations" should "collect names of parsers from objects (on supported platforms)" in {
/*"the Collector implementations" should "collect names of parsers from objects (on supported platforms)" in {
if (Collector.isSupported) {
Renamer.nameOf(None, DebuggerUsageSpec.Arithmetic.prog.internal) shouldBe "prog"
info("it should also allow overriding the name")
Collector.assignName(DebuggerUsageSpec.Arithmetic.prog, "foo")
Renamer.nameOf(None, DebuggerUsageSpec.Arithmetic.prog.internal) shouldBe "foo"
} else alert("the current platform does not support Collector")
}
}*/

it should "collect names of parsers from lexers (on supported platforms)" in {
val lexer = new Lexer(LexicalDesc.plain)
Expand Down

0 comments on commit 9f4989f

Please sign in to comment.