<commit_before># XXX comment about method signatures
# XXX prevent other methods from getting added
class REPL is export { # XXX no need for is export later
    method interactive(Mu \adverbs) {
    }

    method readline(Mu \SELF, Mu \super, Mu \stdin, Mu \stdout, Mu \prompt) {
        super.(SELF, stdin, stdout, prompt);
    }

    method eval(Mu \SELF, Mu \super, Mu \code, Mu \args, Mu \adverbs) {
        super.(SELF, code, |@(args), |%(adverbs));
    }
}<commit_msg>REPL6: Implement loading of alternative readline backends<commit_after>use nqp;

my role ReadlineBehavior[$WHO] {
    method readline(Mu \SELF, Mu \super, Mu \stdin, Mu \stdout, Mu \prompt) {
        say 'readline';
        nqp::null_s();
    }
}

my role LinenoiseBehavior[$WHO] {
    my &linenoise           = $WHO<&linenoise>;
    my &linenoiseHistoryAdd = $WHO<&linenoiseHistoryAdd>;

    method readline(Mu \SELF, Mu \super, Mu \stdin, Mu \stdout, Mu \prompt) {
        linenoise(prompt) // nqp::null_s()
    }
}

my role FallbackBehavior {
    method readline(Mu \SELF, Mu \super, Mu \stdin, Mu \stdout, Mu \prompt) {
        super.(SELF, stdin, stdout, prompt);
    }
}

# XXX print warning when we can't load this file
# XXX comment about method signatures
# XXX prevent other methods from getting added
class REPL is export { # XXX no need for is export later
    # XXX print fallback messages
    method !load-line-editor() {
        my $readline = try require Readline;

        if $readline.HOW ~~ Metamodel::ModuleHOW {
            self does ReadlineBehavior[$readline.WHO];
            return;
        }

        my $linenoise = try require Linenoise;

        if $linenoise.HOW ~~ Metamodel::ModuleHOW {
            self does LinenoiseBehavior[$linenoise.WHO];
            return;
        }

        self does FallbackBehavior;
    }

    method interactive(Mu \adverbs) {
        self!load-line-editor();
    }

    method eval(Mu \SELF, Mu \super, Mu \code, Mu \args, Mu \adverbs) {
        super.(SELF, code, |@(args), |%(adverbs));
    }
}
{'fraction_non_alphanumeric': 0.11958661417322834, 'fraction_numerical': 0.0004921259842519685, 'mean_word_length': 2.554195804195804, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4071558', 'n_tokens_mistral': 676, 'n_tokens_neox': 650, 'n_words': 206}