Home > Perl6 > Parsing Nothing

Parsing Nothing

In Git::Config I made the assumption that when there is nothing to parse there is nothing to do. The code looked as follows.

my $parsed = Config.parse($cfg-text);

for $parsed.Hash<section>.list -> $section {
    # [...]

A recent change in Rakudo broke that assumption. Parsing an empty file with a grammar that isn’t prepared to return nothing will return Failure instead of Nil now. As it turns out for doesn’t like to loop over an instance of Failure. There is an easy fix because Failures are undefined.

my $parsed = Config.parse($cfg-text) // [];

For your use cases it may make more sense to use // Nil instead to get the old behaviour back. In any case I would like to ask you check your modules for assumptions reguarding .parse or help travis to help you.

Categories: Perl6
  1. liztormato
    August 21, 2017 at 16:21

    Please note that after careful deliberation and an attempt to make this only available in v6.d.PREVIEW, it was decided to revert this commit for exactly this reason. Until we find a better way to introduce this change in API without breaking existing modules.

  2. Brad Gilbert
    August 22, 2017 at 01:26

    The thing is the for loop always ran at least once, so the code was at least slightly broken already.

  1. August 21, 2017 at 23:06

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: