-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
99 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
parsley-debug/shared/src/main/scala/parsley/debugger/DebugView.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2020 Parsley Contributors <https://github.com/j-mie6/Parsley/graphs/contributors> | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
package parsley.debugger | ||
|
||
import parsley.debugger.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. | ||
* | ||
* Any compliant implementation that handles all nodes of a `parsley.debugger.DebugTree` can be | ||
* used in place of any other implementation (e.g. a serialiser to JSON, a GUI, etc.). | ||
* | ||
* If a view is reusable, one can implement it as either an `object` or a `class`, but an `object` | ||
* is recommended. Either way, it should inherit [[DebugView.Reusable]]. | ||
* | ||
* If a view is single-use (e.g. it has some non-reusable state), never implement it as an `object`. Always | ||
* implement single-use views as a `class` of some sort inheriting from [[DebugView.SingleUse]]. | ||
* | ||
* @since 5.0.0 | ||
*/ | ||
sealed trait DebugView { | ||
/** Render a debug tree. | ||
* | ||
* @param input The full input of the parse. | ||
* @param tree Debug tree to render. | ||
*/ | ||
private [debugger] def process(input: =>String, tree: =>DebugTree): Unit | ||
} | ||
object DebugView { | ||
/** Signifies that the debug view inheriting from this can be used multiple times. | ||
* | ||
* @see [[DebugView]] | ||
* @since 5.0.0 | ||
*/ | ||
trait Reusable extends DebugView | ||
|
||
/** Signifies that the debug view inheriting from this can only be run once. | ||
* | ||
* @see [[DebugView]] | ||
* @since 4.5.0 | ||
*/ | ||
trait SingleUse extends DebugView { | ||
private var hasBeenRun = false | ||
final override private[debugger] def process(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" | ||
// errors. Failing fast may be better for some frontends. | ||
throw new XIllegalStateException("Stateful frontend has already been run.").except // scalastyle:ignore throw | ||
} else { | ||
processImpl(input, tree) | ||
hasBeenRun = true | ||
} | ||
} | ||
/** The implementation of the process method above */ | ||
private[debugger] def processImpl(input: =>String, tree: =>DebugTree): Unit | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 0 additions & 64 deletions
64
parsley-debug/shared/src/main/scala/parsley/debugger/frontend/DebugFrontend.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters