SOLVED -- See full gist.
So I have this excerpt of a file I am trying to parse:
=== GTK::Compat::Raw::GSList ===
Stage start : 0.000
Stage parse : 2.238
Stage syntaxcheck: 0.000
Stage ast : 0.000
Stage optimize : 0.002
Stage mast : 0.008
Stage mbc : 0.000
Stage moar : 0.000
=== GTK::Compat::Raw::MenuModel ===
Stage start : 0.000
Stage parse : ===SORRY!=== Error while compiling /home/cbwood/Projects/p6-GtkPlus/lib/GTK/Compat/Raw/MenuModel.pm6 (GTK::Compat::Raw::MenuModel)
Invalid typename 'GMenuLinkIter' in parameter declaration.
at /home/cbwood/Projects/p6-GtkPlus/lib/GTK/Compat/Raw/MenuModel.pm6 (GTK::Compat::Raw::MenuModel):28
------> g_menu_link_iter_get_name (GMenuLinkIter⏏ $iter)
=== GTK::Compat::Raw::Permission ===
Stage start : 0.000
Stage parse : 1.394
Stage syntaxcheck: 0.000
Stage ast : 0.000
Stage optimize : 0.002
Stage mast : 0.007
Stage mbc : 0.000
Stage moar : 0.000
=== GTK::Compat::Raw::Pixbuf ===
Stage start : 0.000
Stage parse : 3.338
Stage syntaxcheck: 0.000
Stage ast : 0.000
Stage optimize : 0.002
Stage mast : 0.008
Stage mbc : 0.000
Stage moar : 0.000
And I am using the following grammar:
grammar ParseBuildResults {
regex TOP {
<section>*
}
regex section {
<header> \s+ <stage>*
}
regex header {
^^ \s '=== ' <module> ' ===' $$
}
regex stage {
^^ 'Stage ' <stage_type> \s* ': ' [
(\s* <num> \s*)
|
\s* <err_msg>
]
}
regex err_msg {
'===SORRY!===' .+? <?before \v ' ==='> $$
}
token module {
(\w+)+ % '::'
}
token num {
\d+ '.' \d+
}
token stage_type {
'start' | 'parse' | 'syntaxcheck' | 'ast' |
'optimize' | 'mast' | 'mbc' | 'moar'
}
}
The problem here is that I want the error found in the GTK::Compat::Raw::MenuModel section to not stop parsing and to continue on to the GTK::Compat::Raw::Permission part. However, when I encounter the error, it seems to stick, so the rest of the file does not parse.
If I have the following action class:
class ResultsBuilder {
method err_msg($/) {
say "ERROR!: " ~ $/.Str;
}
}
I keep getting the following output:
section
| header
| | module
Found GTK::Compat::Raw::MenuModel section
| | * MATCH "GTK::Compat::Raw::MenuModel"
| * MATCH " === GTK::Compat::Raw::MenuModel ==="
| stage
| | stage_type
| | * MATCH "start"
| | num
| | * MATCH "0.000"
Use of Nil in string context
in method stage at scripts/parse-result-data.pl6 line 66
| * MATCH "Stage start : 0.000\n"
| stage
| | stage_type
| | * MATCH "parse"
| | err_msg
ERROR!: ===SORRY!=== Error while compiling /home/cbwood/Projects/p6-GtkPlus/lib/GTK/Compat/Raw/MenuModel.pm6 (GTK::Compat::Raw::MenuModel)
Invalid typename 'GMenuLinkIter' in parameter declaration.
at /home/cbwood/Projects/p6-GtkPlus/lib/GTK/Compat/Raw/MenuModel.pm6 (GTK::Compat::Raw::MenuModel):28
------> g_menu_link_iter_get_name (GMenuLinkIter⏏ $iter)
| | * MATCH "===SORRY!=== Error while compiling /home/cbwood/Projec"
Use of Nil in string context
in method stage at scripts/parse-result-data.pl6 line 66
| * MATCH "Stage parse : ===SORRY!=== Error while compiling /ho"
| stage
| * FAIL
* MATCH " === GTK::Compat::Raw::MenuModel ===\nStage start : 0."
section
| header
| * FAIL
* FAIL
ERROR!: ===SORRY!=== Error while compiling /home/cbwood/Projects/p6-GtkPlus/lib/GTK/Compat/Raw/MenuModel.pm6 (GTK::Compat::Raw::MenuModel)
Invalid typename 'GMenuLinkIter' in parameter declaration.
at /home/cbwood/Projects/p6-GtkPlus/lib/GTK/Compat/Raw/MenuModel.pm6 (GTK::Compat::Raw::MenuModel):28
------> g_menu_link_iter_get_name (GMenuLinkIter⏏ $iter)
=== GTK::Compat::Raw::Permission ===
Stage start : 0.000
Stage parse : 1.394
Stage syntaxcheck: 0.000
Stage ast : 0.000
Stage optimize : 0.002
Stage mast : 0.007
Stage mbc : 0.000
Stage moar : 0.000
Use of Nil in string context
in method stage at scripts/parse-result-data.pl6 line 66
stage
* FAIL
section
| header
| * FAIL
* FAIL
ERROR!: ===SORRY!=== Error while compiling /home/cbwood/Projects/p6-GtkPlus/lib/GTK/Compat/Raw/MenuModel.pm6 (GTK::Compat::Raw::MenuModel)
Invalid typename 'GMenuLinkIter' in parameter declaration.
at /home/cbwood/Projects/p6-GtkPlus/lib/GTK/Compat/Raw/MenuModel.pm6 (GTK::Compat::Raw::MenuModel):28
------> g_menu_link_iter_get_name (GMenuLinkIter⏏ $iter)
=== GTK::Compat::Raw::Permission ===
Stage start : 0.000
Stage parse : 1.394
Stage syntaxcheck: 0.000
Stage ast : 0.000
Stage optimize : 0.002
Stage mast : 0.007
Stage mbc : 0.000
Stage moar : 0.000
=== GTK::Compat::Raw::Pixbuf ===
Stage start : 0.000
Stage parse : 3.338
Stage syntaxcheck: 0.000
Stage ast : 0.000
Stage optimize : 0.002
Stage mast : 0.008
Stage mbc : 0.000
Stage moar : 0.000
Use of Nil in string context
As you can see, the error text keeps growing, even though I am trying to grab only the text that occurs from the error to the next section.
What am I doing wrong?
Addendum: Ideally, <err_msg> should advance the grammar cursor to the position where <section> should pick up it's next match, and that should be the the text " === GTK::Compat::Raw::Permission ===", however that is not matching. Is this due to the fact that there is another attempt to match <stage>, that fails?