<commit_before>import query from './query.pegjs';

export function parseToAst (string) {
  return query.parse(string);
}

const opfunc = {
  '<=': function (x, y) {
    return x <= y;
  },

  '<': function (x, y) {
    return x < y;
  },

  '>=': function (x, y) {
    return x >= y;
  },

  '>': function (x, y) {
    return x > y;
  },

  '=': function (x, y) {
    return x === y;
  },

  '!=': function (x, y) {
    return x !== y;
  }
};

function checker (ast, include) {
  return function (row) {
    const data = row[ast.operands[0]];
    for (let i = 0; i < ast.operands[1].length; i++) {
      if (data === ast.operands[1][i]) {
        return include;
      }
    }

    return !include;
  };
}

export function astToFunction (ast) {
  switch (ast.operator) {
    case 'or':
      return function (row) {
        const f1 = astToFunction(ast.operands[0]);
        const f2 = astToFunction(ast.operands[1]);

        return f1(row) || f2(row);
      };

    case 'and':
      return function (row) {
        const f1 = astToFunction(ast.operands[0]);
        const f2 = astToFunction(ast.operands[1]);

        return f1(row) && f2(row);
      };

    case 'not':
      return function (row) {
        const f = astToFunction(ast.operands);
        return !f(row);
      };

    case 'in':
      return checker(ast, true);

    case 'not in':
      return checker(ast, false);

    case '<=':
    case '<':
    case '>=':
    case '>':
    case '=':
    case '!=':
      return function (row) {
        const data = row[ast.operands[0]];
        return opfunc[ast.operator](data, ast.operands[1]);
      };
  }
}

export function parseToFunction (string) {
  return astToFunction(parseToAst(string));
}
<commit_msg>Remove astToFunction from JavaScript code<commit_after>import query from './query.pegjs';

export function parseToAst (string) {
  return query.parse(string);
}

{'fraction_non_alphanumeric': 0.16967126193001061, 'fraction_numerical': 0.009544008483563097, 'mean_word_length': 2.393884892086331, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 9, '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': '1412410', 'n_tokens_mistral': 672, 'n_tokens_neox': 651, 'n_words': 162}