<commit_before>const {stream, F, N, C, X} = require('parser-combinator');


function day() {
     const x = new X()
    return x.stringIn(['MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY', 'SUNDAY']);
    //return C.string('MONDAY').or(C.string('TUESDAY')).or(C.string('WEDNESDAY'));
}


/* Idiomatic recursive expression */
function terminal() {
    return day();
}

function subexpr() {
    return terminal()//.or(expr());
}

function expr() {

    return C.char('(').then(subexpr()).then(')').or(subexpr())//.or(expr());

}

function AND() {
    return expr().debug('here').then(C.string(' AND ').debug('and').drop()).then(expr()).map(([day1, day2]) => day1 + day2);
}

function OR() {
    return expr().then(C.string(' OR ').drop()).then(expr()).debug('there').map( ([day1, day2]) => day1);
}

const tryAnd = () => F.try(AND());
const tryOr = () => F.try(OR());

function combinator() {
    return tryAnd().or(tryOr()).or(expr());
}


const string = 'TUESDAY OR WEDNESDAY';

let myStream = stream.ofString(string);
let parsing = combinator().parse(myStream);

console.log(parsing);

<commit_msg>Integration Test; Operation: fail recursion // Implementing basic solution : //exp   = sexp (op exp)? //sexp = number | '(' exp ')'<commit_after>const {stream, F, N, C, X} = require('parser-combinator');


function day() {
     const x = new X()
    return x.stringIn(['MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY', 'SUNDAY']);
    //return C.string('MONDAY').or(C.string('TUESDAY')).or(C.string('WEDNESDAY'));
}


/* Idiomatic recursive expression */
function terminal() {
    return day();
}



function operation(){
        return F.try(C.string(' AND ')).or(C.string(' OR '))
}



function parenthesis(par){
    return C.char(' ').optrep().drop().then(C.char(par)).then(C.char(' ').optrep().drop());
}

function parenthesisExpr(){
    return parenthesis('(').drop().then(expr()).then(parenthesis(')').drop());
}


// Implementing basic solution :
//exp   = sexp (op exp)?
//sexp = number | '(' exp ')'

function subexpr(){
    return terminal().or(parenthesisExpr());
}

function operationThenExpression(){
    return operation().then(expr());
}



function expr() {

    return subexpr().then(operationThenExpression().opt());

}



function combinator() {
    return expr();
}


const string = 'TUESDAY OR WEDNESDAY';

let myStream = stream.ofString(string);
let parsing = combinator().parse(myStream);

console.log(parsing);


{'fraction_non_alphanumeric': 0.22177256171590448, 'fraction_numerical': 0.0028328611898017, 'mean_word_length': 4.304721030042918, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1860807', 'n_tokens_mistral': 870, 'n_tokens_neox': 841, 'n_words': 178}