<commit_before>import { AST, BooleanCB } from '../../../interfaces';
import { path, pipe } from 'rambda';

export default class BaseType {

    public parseAST(srcNode: AST, parsedFn: BooleanCB, field: string|null): AST {
        const getFieldValue = (obj: any) => {
            return path(field as string, obj);
        };

        let cb;

        if (!field) {
            cb = parsedFn;
        } else {
            cb = pipe(getFieldValue, parsedFn);
        }

        // @ts-ignore
        const resultingAST: AST = { type: '__parsed', callback: cb };

        if (srcNode.negated) resultingAST.negated = true;
        if (srcNode.or) resultingAST.or = true;
        return resultingAST;
    }

    // TODO: look to see if this can be combined with other walkAst method
    public walkAst(ast: AST, cb: Function) {

        function walk(ast: AST, _field?: string) {
            const topField = ast.field || _field;
            const node = cb(ast, topField);

            if (node.right) {
                node.right = walk(node.right, topField);
            }

            if (node.left) {
                node.left = walk(node.left, topField);
            }
            return node;
        }

        return walk(ast);
    }

    public processAst(ast: AST) {
        return ast;
    }
}<commit_msg>refactored parsed array node creation<commit_after>import { AST, BooleanCB } from '../../../interfaces';
import { path, pipe } from 'rambda';

export default class BaseType {

    public parseAST(srcNode: AST, parsedFn: BooleanCB, field: string|null): AST {
        const getFieldValue = (obj: any) => {
            return path(field as string, obj);
        };
        const type = '__parsed';
        let callback;

        if (!field) {
            callback = parsedFn;
        } else {
            callback = pipe(getFieldValue, parsedFn);
        }

        const resultingAST = {
            type,
            callback,
            ...srcNode.negated && { negated: true },
            ...srcNode.or && { or: true },
        };

        return resultingAST as AST;
    }

    // TODO: look to see if this can be combined with other walkAst method
    public walkAst(ast: AST, cb: Function) {

        function walk(ast: AST, _field?: string) {
            const topField = ast.field || _field;
            const node = cb(ast, topField);

            if (node.right) {
                node.right = walk(node.right, topField);
            }

            if (node.left) {
                node.left = walk(node.left, topField);
            }
            return node;
        }

        return walk(ast);
    }

    public processAst(ast: AST) {
        return ast;
    }
}
{'fraction_non_alphanumeric': 0.11611462597692594, 'fraction_numerical': 0.0, 'mean_word_length': 1.6404715127701375, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7592045', 'n_tokens_mistral': 787, 'n_tokens_neox': 744, 'n_words': 221}