<commit_before>/**
 * escallmatch
 * 
 * https://github.com/twada/escallmatch
 *
 * Copyright (c) 2014 <NAME>
 * Licensed under the MIT license.
 *   http://twada.mit-license.org/
 */
'use strict';

var esprima = require('esprima'),
    estraverse = require('estraverse'),
    espurify = require('espurify'),
    syntax = estraverse.Syntax,
    deepEqual = require('deep-equal');

function createMatcher (pattern) {
    var ast = extractExpressionFrom(esprima.parse(pattern));
    return new Matcher(ast);
}

function Matcher (exampleAst) {
    this.exampleAst = exampleAst;
    this.numMaxArgs = this.exampleAst.arguments.length;
    this.numMinArgs = this.exampleAst.arguments.filter(identifiers).length;
}

Matcher.prototype.test = function (currentNode) {
    var calleeMatched = isCalleeMatched(this.exampleAst, currentNode),
        numArgs;
    if (calleeMatched) {
        numArgs = currentNode.arguments.length;
        return this.numMinArgs <= numArgs && numArgs <= this.numMaxArgs;
    }
    return false;
};

Matcher.prototype.matchArgument = function (currentNode, parentNode) {
    var indexOfCurrentArg, argExample;
    if (isCalleeOfParent(currentNode, parentNode)) {
        return null;
    }
    if (this.test(parentNode)) {
        indexOfCurrentArg = parentNode.arguments.indexOf(currentNode);
        if (indexOfCurrentArg !== -1 && indexOfCurrentArg < this.exampleAst.arguments.length) {
            argExample = this.exampleAst.arguments[indexOfCurrentArg];
            if (argExample.type === syntax.Identifier) {
                return {
                    name: argExample.name,
                    kind: 'mandatory'
                };
            } else if (argExample.type === syntax.ArrayExpression) {
                return {
                    name: argExample.elements[0].name,
                    kind: 'optional'
                };
            }
        }
    }
    return null;
};

function isCalleeMatched(callExp1, callExp2) {<commit_msg>refactor(escallmatch): extract argMatchResult function<commit_after>/**
 * escallmatch
 * 
 * https://github.com/twada/escallmatch
 *
 * Copyright (c) 2014 <NAME>
 * Licensed under the MIT license.
 *   http://twada.mit-license.org/
 */
'use strict';

var esprima = require('esprima'),
    estraverse = require('estraverse'),
    espurify = require('espurify'),
    syntax = estraverse.Syntax,
    deepEqual = require('deep-equal');

function createMatcher (pattern) {
    var ast = extractExpressionFrom(esprima.parse(pattern));
    return new Matcher(ast);
}

function Matcher (exampleAst) {
    this.exampleAst = exampleAst;
    this.numMaxArgs = this.exampleAst.arguments.length;
    this.numMinArgs = this.exampleAst.arguments.filter(identifiers).length;
}

Matcher.prototype.test = function (currentNode) {
    var calleeMatched = isCalleeMatched(this.exampleAst, currentNode),
        numArgs;
    if (calleeMatched) {
        numArgs = currentNode.arguments.length;
        return this.numMinArgs <= numArgs && numArgs <= this.numMaxArgs;
    }
    return false;
};

Matcher.prototype.matchArgument = function (currentNode, parentNode) {
    var indexOfCurrentArg, argExample;
    if (isCalleeOfParent(currentNode, parentNode)) {
        return null;
    }
    if (this.test(parentNode)) {
        indexOfCurrentArg = parentNode.arguments.indexOf(currentNode);
        if (indexOfCurrentArg < this.exampleAst.arguments.length) {
            argExample = this.exampleAst.arguments[indexOfCurrentArg];
            return argMatchResult(argExample);
        }
    }
    return null;
};

function argMatchResult (argExample) {
    switch(argExample.type) {
    case syntax.Identifier:
        return {
            name: argExample.name,
            kind: 'mandatory'
        };
    case syntax.ArrayExpression:
        return {
            name: argExample.elements[0].name,
            kind: 'optional'
        };
    default:
        return null;
    }
}

function isCalleeMatched(callExp1, callExp2) {
{'fraction_non_alphanumeric': 0.11412089290193128, 'fraction_numerical': 0.003762227238525207, 'mean_word_length': 2.7800947867298578, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '1927973', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1151, 'n_words': 223}