Skip to content

Instantly share code, notes, and snippets.

@Xliff
Last active October 19, 2018 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xliff/12689c655f322126486f36e6fe10496b to your computer and use it in GitHub Desktop.
Save Xliff/12689c655f322126486f36e6fe10496b to your computer and use it in GitHub Desktop.

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?

@Xliff
Copy link
Author

Xliff commented Oct 19, 2018

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?

@Xliff
Copy link
Author

Xliff commented Oct 19, 2018

And now I am certain that the cursor is not advancing.

I've made the following change to the action class:

  method err_msg($/) {
    say "ERROR! ({$/.from} - {$/.to})" ~ $/.Str;
    exit if $++ > 2;
  }

And here's the output I get:

ERROR! (2059 - 2661)===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 67
stage
* FAIL
section
|  header
|  * FAIL
* FAIL
ERROR! (2059 - 2911)===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
  in method stage at scripts/parse-result-data.pl6 line 67
stage
* FAIL
section
|  header
|  * FAIL
* FAIL
ERROR! (2059 - 3164)===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
 === GTK::Compat::Raw::Rectangle ===
Stage start      :   0.000
Stage parse      :   1.107
Stage syntaxcheck:   0.000
Stage ast        :   0.000
Stage optimize   :   0.001
Stage mast       :   0.007
Stage mbc        :   0.000
Stage moar       :   0.000

@Xliff
Copy link
Author

Xliff commented Oct 19, 2018

So yes! The cursor was not being advanced. The solution? Make sure <stage> tried to grab a whitespace:

  regex stage {
    ^^ 'Stage ' <stage_type> \s* ': ' [
      (\s* <num> \s*)
      |
      \s* <err_msg> \s*
    ]
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment