@@ -10,7 +10,7 @@ import parsley.Parsley.{atomic, empty, fresh}
10
10
import parsley .debug .internal .{DebugContext , DivergenceContext }
11
11
12
12
import parsley .internal .deepembedding .frontend .LazyParsley
13
- import parsley .internal .deepembedding .frontend .debug .{TaggedWith , Named }
13
+ import parsley .internal .deepembedding .frontend .debug .{TaggedWith , Named , RemoteBreak }
14
14
import parsley .internal .deepembedding .backend .debug .{CheckDivergence , Debugging }
15
15
16
16
/** This object contains the combinators for attaching debuggers to parsers.
@@ -74,8 +74,8 @@ object combinator {
74
74
* @tparam A Output type of original parser.
75
75
* @return A pair of the finalised tree, and the instrumented parser.
76
76
*/
77
- private [parsley] def attachDebugger [A ](parser : Parsley [A ], toStringRules : PartialFunction [Any , Boolean ]): DebuggedPair [A ] = {
78
- val context : DebugContext = new DebugContext (toStringRules)
77
+ private [parsley] def attachDebugger [A ](parser : Parsley [A ], toStringRules : PartialFunction [Any , Boolean ], view : DebugView ): DebuggedPair [A ] = {
78
+ val context : DebugContext = new DebugContext (toStringRules, view )
79
79
80
80
val attached : LazyParsley [A ] = TaggedWith .tagRecursively(parser.internal, new Debugging (context))
81
81
val resetter : Parsley [Unit ] = fresh(context.reset()).impure
@@ -107,7 +107,7 @@ object combinator {
107
107
* @tparam A Output type of original parser.
108
108
* @return A pair of the finalised tree, and the instrumented parser.
109
109
*/
110
- private [parsley] def attachDebugger [A ](parser : Parsley [A ]): DebuggedPair [A ] = attachDebugger[A ](parser, DefaultStringRules )
110
+ private [parsley] def attachDebugger [A ](parser : Parsley [A ]): DebuggedPair [A ] = attachDebugger[A ](parser, DefaultStringRules , SilentDebugView )
111
111
112
112
// $COVERAGE-OFF$
113
113
/* Create a closure that freshly attaches a debugger to a parser every time it is called.
@@ -168,7 +168,7 @@ object combinator {
168
168
* a call to [[Parsley.parse ]] is made.
169
169
*/
170
170
def attach [A ](parser : Parsley [A ], view : DebugView , toStringRules : PartialFunction [Any , Boolean ]): Parsley [A ] = {
171
- val (tree, attached) = attachDebugger(parser, toStringRules)
171
+ val (tree, attached) = attachDebugger(parser, toStringRules, view )
172
172
173
173
// Ideally, this should run 'attached', and render the tree regardless of the parser's success.
174
174
val renderer = fresh {
@@ -262,6 +262,16 @@ object combinator {
262
262
case _ => new Parsley (Named (parser.internal, name))
263
263
}
264
264
265
+ /** Set a breakpoint on a parser to be used by RemoteView
266
+ *
267
+ * @param parser The parser to debug.
268
+ * @param break Indicate whether to break on entry or exit to the parser.
269
+ * @tparam A Output type of original parser.
270
+ * @return A modified parser which will pause parsing and ask the view to render the produced
271
+ * debug tree after a call to [[Parsley.parse ]] is made.
272
+ */
273
+ def break [A ](parser : Parsley [A ], break : Breakpoint ): Parsley [A ] = new Parsley (new RemoteBreak (parser.internal, break))
274
+
265
275
/** Dot accessor versions of the combinators. */
266
276
implicit class DebuggerOps [A ](par : Parsley [A ]) {
267
277
// def attachDebugger(toStringRules: PartialFunction[Any, Boolean]): DebuggedPair[A] = combinator.attachDebugger(par, toStringRules)
@@ -276,6 +286,7 @@ object combinator {
276
286
def attachReusable (view : => DebugView .Reusable ): () => Parsley [A ] = combinator.attachReusable(par, view, DefaultStringRules )
277
287
// def attach(implicit view: DebugFrontend): Parsley[A] = combinator.attach(par, defaultRules)
278
288
def named (name : String ): Parsley [A ] = combinator.named(par, name)
289
+ def break (break : Breakpoint ): Parsley [A ] = combinator.break(par, break)
279
290
}
280
291
// $COVERAGE-ON$
281
292
0 commit comments