Grammar::Debugger

Simple tracing and debugging support for Perl 6 grammars

NAME

Grammer::Debugger - interactive debugger for Perl 6 grammars

SYNOPSIS

In the file that has your grammar definition, merely load the module in the same lexical scope:

use Grammar::Debugger;
grammar Some::Grammar { ... }

DESCRIPTION

Grammar::Debugger is an interactive debugger for Perl 6 grammars. It applies to all grammars in its lexical scope. When you run the your program and start to parse a grammar, you should get an interactive prompt. Type h to get a list of commands:

$ perl6 my-grammar-program.p6
	TOP
	> h
		r              run (until breakpoint, if any)
		<enter>        single step
		rf             run until a match fails
		r <name>       run until rule <name> is reached
		bp add <name>  add a rule name breakpoint
		bp list        list all active rule name breakpoints
		bp rm <name>   remove a rule name breakpoint
		bp rm          removes all breakpoints
		q              quit
	>

If you are debugging a grammar and want to set up breakpoints in code rather than entering them manually at the debug prompt, you can apply the breakpoint trait to any rule:

token name is breakpoint { \w+ [\h+ \w+]* }

If you want to conditionally break, you can also do something like:

token name will break { $^m eq 'Russia' } { \w+ [\h+ \w+]* }

Which will only break after the name rule has matched "Russia".

On Windows, you might have to do something to interpret the ANSI codes:

$ perl6 MyGrammar.pm | perl -e "use Win32::Console::ANSI; print while (<>)"
$ perl6 MyGrammar.pm | perl -e "print s/\e\[[0-9;]+m//gr while (<>)"

AUTHOR

Jonathan Worthington, < <[email protected]> >

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.