-
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.
doc: added page for PrintView and attachment
- Loading branch information
Showing
9 changed files
with
110 additions
and
9 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
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,43 @@ | ||
{% | ||
laika.versioned = true | ||
laika.site.metadata.description = "How attachment works for debug views." | ||
%} | ||
|
||
# Attaching Debugger Views | ||
The new functionality in `parsley-debug` involves attaching a debugger to a parser | ||
that will be ran. There are two combinators to do this found in `parsley.debug.combinator`: | ||
`attach`, and `attachReusable`. Before we see these, it will be useful to understand how | ||
`DebugView`s work. | ||
|
||
@:callout(info) | ||
By importing `parsley.debug.combinator.DebuggerOps`, you will have access to the | ||
method-style implementation of these combinators. | ||
@:@ | ||
|
||
## `DebugView` | ||
The `DebugView.SingleUse` and `DebugView.Reusable` traits represent renderers for debug information. | ||
By default, `parsley-debug` includes `PrintView`, which can be used to "render" debug information | ||
out onto the console, or perhaps to a file (or any `PrintStream`/`OutputStream`). The reusability | ||
aspect refers to whether or not multiple such views can work simultaneously: see `attachReusable` | ||
below. | ||
|
||
The views themselves do not necessarily have to directly render the debugging content themselves, | ||
they could be remote connections, for instance; but the point is that they are what is attached | ||
to a specific parser. When the parser is ran, the debug combinator collects the information, and | ||
the view processes that information in some way. This process is done via *attachment*. | ||
|
||
## `attach` and `attachReusable` | ||
The `attach` combinator takes a `DebugView` (reusable or otherwise) and optionally a "string rules" | ||
function, which determines whether or not a value is eagerly turned into a string or preserved in | ||
its original form within the internal "`DebugTree`". In return, you get a new parser, which will | ||
feed debugging information to the provided `DebugView`. | ||
|
||
@:callout(warning) | ||
You should only use the parser returned by `attach` in one place! If you want to debug a parser | ||
that appears in more than one place, you must use `attachReusable`. | ||
@:@ | ||
|
||
In contrast, `attachReusable` is similar, but takes a *by-name* `DebugView`, which may be recreated | ||
each use, and returns a function that produces new `Parsley` values. The idea is that if you need | ||
to use the parser in more than one place, you call the function more than once to produce independently | ||
bound parsers. |
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,47 @@ | ||
{% | ||
laika.versioned = true | ||
laika.title = "`PrintView`" | ||
laika.site.metadata.description = "The built-in view for plain console debugging" | ||
%} | ||
|
||
# `PrintView` (`parsley-debug`) | ||
The core `parsley-debug` library contains one view, namely `PrintView`. This can be | ||
used in place of more advanced functionality present in the other "companion" libraries. | ||
It is perhaps less featureful than the "vanilla" `.debug` combinator, which supports breakpoints, | ||
but does work cross platform and across all Scala versions. The advantage over `.debug`, of course, | ||
is that for large-scale debugging, `@debuggable` is far more ergonomic to apply to a whole parser, | ||
and gives more intermediate information. With no internal state, this view is reusable, however, | ||
concurrent executions within a parser (if used with `attachReusable`) may interleave and be confusing. | ||
|
||
@:callout(info) | ||
Please see the [`@parsley.debuggable`](../debuggable.md) page first, as this is used | ||
to provide meaningful names for this functionality. | ||
@:@ | ||
|
||
## Configuration | ||
The `PrintView` configuration is very simple. By default, the `PrintView` object will print the | ||
debug trace directly to `Console.out`. It is possible to use the `PrintView.apply` methods to | ||
produce new views that print their output elsewhere: for instance to a file. | ||
|
||
## What does it look like? | ||
As an example, here is the trace without `@debuggable`: | ||
|
||
```scala mdoc:to-string | ||
import parsley.quick.* | ||
import parsley.debug.combinator.* | ||
import parsley.debug.PrintView | ||
|
||
val hello = ( atomic(string("hello")) | ||
| (string("hey") | ||
| string("hi")) | ||
) | ||
|
||
hello.attach(PrintView).parse("hey") | ||
|
||
hello.attach(PrintView).parse("hi") | ||
``` | ||
|
||
As you can see, without an `@debuggable` annotation, this just prints the names of the combinators | ||
used to construct the parser, which is ok here, but would be undecipherable for more complex parsers. | ||
The rendering style is slightly different to the vanilla combinator as well, rendering in a tree | ||
shape as opposed to using explicit entry/exit markers. |
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,4 @@ | ||
laika.title = "Debug Views" | ||
laika.navigationOrder = [ | ||
PrintView.md | ||
] |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
laika.title = "parsley-debug" | ||
laika.navigationOrder = [ | ||
debuggable.md | ||
attachment.md | ||
debug-views | ||
recursion-detection.md | ||
] |
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
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
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
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