<commit_before>'use strict';

var parser = require( './parser' ).parser,
    ast    = require( './ast' ),
    _      = require( 'lodash' );

// Set correct scope to parser
parser.yy = ast;

/**
 * Identifier
 * @param {ast.Expression|ast.Function|ast.Identifier|String|Number|Boolean|null} type
 * @returns {*}
 */
function identifier( type ) {
    if (type instanceof ast.Expression) {
        return expression( type );
    } else if (type instanceof ast.Function) {
        console.warn( 'Functions are not supported at the moment' );
        return true;
    } else if (type instanceof ast.Identifier) {
        return type.id;
    } else {
        return type;
    }
}

/**
 * Handle expression
 * @param {Object} expr
 * @param {String} expr.left
 * @param {String} expr.op
 * @param {String} expr.right
 * @returns {*}
 */
function expression( expr ) {
    var lft = identifier( expr.left ),
        rgt = identifier( expr.right ),
        e;

    switch (expr.operator) {
        // Logical operators
        case 'and':
            return {$and: [lft, rgt]};
        case 'or':
            return {$or: [lft, rgt]};
        case 'not':
            throw 'Operator not implemented';
        case 'eq':
            e = {};
            e[lft] = rgt;
            return e;
        case 'ne':
            e = {};
            e[lft] = {$ne: rgt};
            return e;
        case 'gt':
            e = {};
            e[lft] = {$gt: rgt};
            return e;
        case 'ge':
            e = {};
            e[lft] = {$gte: rgt};
            return e;
        case 'lt':
            e = {};
            e[lft] = {$lt: rgt};
            return e;
        case 'le':
            e = {};
            e[lft] = {$lte: rgt};
            return e;
        // Search operators
        case 'lk':
            e = {};
            e[lft] = new RegExp( rgt, 'i' );
            return e;
    }
}

/**
 * Filter
 * @param expr
 * @constructor
 */
var Filter = function( query ) {
    this.q = query;
};

/**
 * Get expression
 * @returns {Object}
 */
Filter.prototype.toObject = function() {
    if (!this.q) {<commit_msg>fix: latedef issue with expression/identifier function<commit_after>'use strict';

var parser = require( './parser' ).parser,
    ast    = require( './ast' ),
    _      = require( 'lodash' ),
    identifier,
    expression;

// Set correct scope to parser
parser.yy = ast;

/**
 * Identifier
 * @param {ast.Expression|ast.Function|ast.Identifier|String|Number|Boolean|null} type
 * @param {*} type.id
 * @returns {*}
 */
identifier = function identifier( type ) {
    if (type instanceof ast.Expression) {
        return expression( type );
    } else if (type instanceof ast.Function) {
        console.warn( 'Functions are not supported at the moment' );
        return true;
    } else if (type instanceof ast.Identifier) {
        return type.id;
    } else {
        return type;
    }
}

/**
 * Handle expression
 * @param {Object} expr
 * @param {String} expr.left
 * @param {String} expr.op
 * @param {String} expr.right
 * @returns {*}
 */
expression = function expression( expr ) {
    var lft = identifier( expr.left ),
        rgt = identifier( expr.right ),
        e;

    switch (expr.operator) {
        // Logical operators
        case 'and':
            return {$and: [lft, rgt]};
        case 'or':
            return {$or: [lft, rgt]};
        case 'not':
            throw 'Operator not implemented';
        case 'eq':
            e = {};
            e[lft] = rgt;
            return e;
        case 'ne':
            e = {};
            e[lft] = {$ne: rgt};
            return e;
        case 'gt':
            e = {};
            e[lft] = {$gt: rgt};
            return e;
        case 'ge':
            e = {};
            e[lft] = {$gte: rgt};
            return e;
        case 'lt':
            e = {};
            e[lft] = {$lt: rgt};
            return e;
        case 'le':
            e = {};
            e[lft] = {$lte: rgt};
            return e;
        // Search operators
        case 'lk':
            e = {};
            e[lft] = new RegExp( rgt, 'i' );
            return e;
    }
}

/**
 * Filter
 * @param {String} [query]
 * @constructor
 */
var Filter = function( query ) {
    this.q = query || '';
};

/**
 * Get expression
 * @returns {Object}
 */
Filter.prototype.toObject = function() {
    if (!this.q) {
{'fraction_non_alphanumeric': 0.15229819345986736, 'fraction_numerical': 0.0, 'mean_word_length': 1.594306049822064, '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': '4519538', 'n_tokens_mistral': 1340, 'n_tokens_neox': 1335, 'n_words': 380}