<commit_before>my class Grammar is Match {

    method parse(
      $orig is raw, :$rule = "TOP", :$args, Mu :$actions
    ) is raw {
        my $*LINEPOSCACHE;
        my $grammar := self.new(:$orig, |%_).set_actions($actions);

        nqp::decont(nqp::getlexcaller('$/') = nqp::if(
          (my $cursor := nqp::if(
            $args,
            $grammar."$rule"(|$args.Capture),
            $grammar."$rule"()
          )),
          nqp::stmts(
            (my $match := $cursor.MATCH),
            (my int $chars = nqp::chars($orig)),
            nqp::while(
              $match && nqp::isne_i(
                nqp::getattr_i(($match := $cursor.MATCH),Match,'$!pos'),
                $chars
              ),
              $match := ($cursor := $cursor.'!cursor_next'()).MATCH
            ),
            $match || Nil
          ),
          Nil
        ))
    }

    method subparse($orig is raw, :$rule = "TOP", :$args, :$actions) is raw {
        my $grammar := self.new(:$orig, |%_).set_actions($actions);
        nqp::decont(nqp::getlexcaller('$/') = nqp::if(
          $args,
          $grammar."$rule"(|$args.Capture).MATCH,
          $grammar."$rule"().MATCH,
        ))
      }

    method parsefile(Str(Cool) $filename, :$enc) is raw {
        nqp::decont(nqp::getlexcaller('$/') = nqp::if(
          nqp::elems(nqp::getattr(%_,Map,'$!storage')),
          self.parse($filename.IO.slurp(:$enc), :$filename, |%_),
          self.parse($filename.IO.slurp(:$enc), :$filename)
        ))
    }
}

# vim: expandtab sw=4<commit_msg>Simplify Grammar.parse further<commit_after>my class Grammar is Match {

    method parse(
      $orig is raw, :$rule = "TOP", :$args, Mu :$actions
    ) is raw {
        my $*LINEPOSCACHE;
        my $grammar := self.new(:$orig, |%_).set_actions($actions);

        nqp::decont(nqp::getlexcaller('$/') = nqp::if(
          (my $cursor := nqp::if(
            $args,
            $grammar."$rule"(|$args.Capture),
            $grammar."$rule"()
          )),
          nqp::stmts(
            (my int $chars = nqp::chars($orig)),
            nqp::while(
              $cursor
                && nqp::isne_i(nqp::getattr_i($cursor,Match,'$!pos'),$chars),
              $cursor := $cursor.'!cursor_next'()
            ),
            nqp::if(
              $cursor,
              $cursor.MATCH,
              Nil
            )
          ),
          Nil
        ))
    }

    method subparse($orig is raw, :$rule = "TOP", :$args, :$actions) is raw {
        my $grammar := self.new(:$orig, |%_).set_actions($actions);
        nqp::decont(nqp::getlexcaller('$/') = nqp::if(
          $args,
          $grammar."$rule"(|$args.Capture).MATCH,
          $grammar."$rule"().MATCH,
        ))
      }

    method parsefile(Str(Cool) $filename, :$enc) is raw {
        nqp::decont(nqp::getlexcaller('$/') = nqp::if(
          nqp::elems(nqp::getattr(%_,Map,'$!storage')),
          self.parse($filename.IO.slurp(:$enc), :$filename, |%_),
          self.parse($filename.IO.slurp(:$enc), :$filename)
        ))
    }
}

# vim: expandtab sw=4
{'fraction_non_alphanumeric': 0.198371335504886, 'fraction_numerical': 0.0006514657980456026, 'mean_word_length': 1.8514391829155061, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6681862', 'n_tokens_mistral': 1082, 'n_tokens_neox': 1040, 'n_words': 168}