<commit_before># nqp

# This file compiled to pir and used in tests.

Q:PIR{
    # We want Test::More features for testing. Not NQP's builtin.
    .include "test_more.pir"
    load_bytecode "pir.pbc"
};

sub parse($c, $code) {
    my $res := 0;
    try {
        $c.compile(:target('parse'), $code);
        $res := 1;
    }
    $res;
}<commit_msg>Add simple grammar to move tests into datafiles.<commit_after># nqp

# This file compiled to pir and used in tests.

Q:PIR{
    # We want Test::More features for testing. Not NQP's builtin.
    .include "test_more.pir"
    load_bytecode "pir.pbc"
};

sub parse($c, $code) {
    my $res := 0;
    try {
        $c.compile(:target('parse'), $code);
        $res := 1;
    }
    $res;
}
#
# Helper grammar to parse test data

grammar Test {
    rule TOP {
        ^
        <testcase>+
        $ || <.panic: "Can't parse test data">
    };

    token testcase {
        <start> <name> \n
        <body>
    }

    token start { ^^ '# TEST ' }
    regex name  { \N+ }

    token body  { <line>+ }
    token line  { <!before <start> > .*? \n }
};


our sub parse_tests($file)
{
    my $data  := slurp($file);
    my $match := Test.parse($data);
    $match<testcase>;
}

# vim: ft=perl6
{'fraction_non_alphanumeric': 0.15798045602605862, 'fraction_numerical': 0.004071661237785016, 'mean_word_length': 2.192207792207792, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '4838572', 'n_tokens_mistral': 472, 'n_tokens_neox': 448, 'n_words': 129}