Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 48 lines (39 sloc) 1.527 kb
4689eef @jnthn Initial commit of modules, a README and META.info.
authored
1 use Term::ANSIColor;
2
b25b90c @meisl + add comment explaining how to get colored output on Windows
meisl authored
3 # On Windows you can use perl 5 to get proper output:
4 # - send through Win32::Console::ANSI: perl6 MyGrammar.pm | perl -e "use Win32::Console::ANSI; print while (<>)"
5 # - to strip all the escape codes: perl6 MyGrammar.pm | perl -e "print s/\e\[[0-9;]+m//gr while (<>)"
6
f8e7e1f @jnthn Don't need to explicitly inherit from Mu any more.
authored
7 my class TracedGrammarHOW is Metamodel::GrammarHOW {
4689eef @jnthn Initial commit of modules, a README and META.info.
authored
8 my $indent = 0;
9
10 method find_method($obj, $name) {
11 my $meth := callsame;
c6f7a5d @meisl * same for Tracer as for Debugger: only hook on Regexes rather than t…
meisl authored
12 return $meth unless $meth ~~ Regex;
13 return -> $c, |args {
14 # Method name.
15 say ('| ' x $indent) ~ BOLD() ~ $name ~ RESET();
16
17 # Call rule.
18 $indent++;
19 my $result := $meth($obj, |args);
20 $indent--;
21
22 # Dump result.
23 my $match := $result.MATCH;
24 say ('| ' x $indent) ~ '* ' ~
25 ($result.MATCH ??
26 colored('MATCH', 'white on_green') ~ summary($match) !!
27 colored('FAIL', 'white on_red'));
28 $result
29 }
4689eef @jnthn Initial commit of modules, a README and META.info.
authored
30 }
31
32 sub summary($match) {
33 my $snippet = $match.Str;
34 my $sniplen = 60 - (3 * $indent);
35 $sniplen > 0 ??
36 colored(' ' ~ $snippet.substr(0, $sniplen).perl, 'white') !!
37 ''
38 }
39
40 method publish_method_cache($obj) {
41 # Suppress this, so we always hit find_method.
42 }
43 }
44
45 # Export this as the meta-class for the "grammar" package declarator.
46 my module EXPORTHOW { }
cdc2a7b @jnthn Don't need funky .WHO shenanigans now.
authored
47 EXPORTHOW::<grammar> = TracedGrammarHOW;
Something went wrong with that request. Please try again.