<commit_before>'use strict';
const isOperator = require('../enums/io-file-operators').isOperator;

module.exports = (options, utils) => function * identifySimpleCommandNames(tokens) {
	for (const tk of tokens) {
		if (tk._.maybeStartOfSimpleCommand) {
			if (tk.is('WORD') && utils.isValidName(tk.value)) {
				tk._.maybeSimpleCommandName = true;
				yield tk;
				continue;
			}

			yield tk;

			let lastToken = tk;
			let commandNameFound = false;
			let item = tokens.next();
			while (!item.done) {
				const scTk = item.value;
				if (!commandNameFound && !isOperator(lastToken) && scTk.is('WORD') && utils.isValidName(scTk.value)) {
					scTk._.maybeSimpleCommandName = true;
					// scTk.maybeSimpleCommandName = true;
					commandNameFound = true;
				}

				yield scTk;

				if (scTk.is('SEPARATOR_OP') || scTk.is('NEWLINE') || scTk.is('NEWLINE_LIST') || scTk.value === ';' ||
					scTk.is('PIPE') || scTk.is('OR_IF') || scTk.is('PIPE') || scTk.is('AND_IF')) {
					break;
				}

				lastToken = scTk;
				item = tokens.next();
			}
		} else {
			yield tk;
		}
	}
};<commit_msg>refactored simple command names<commit_after>'use strict';
const lookahead = require('iterable-lookahead');
const compose = require('compose-function');
const map = require('map-iterable');
const isOperator = require('../enums/io-file-operators').isOperator;
const isValidName = require('../../../utils/is-valid-name');

function couldEndSimpleCommand(scTk) {
	return scTk && (
		scTk.is('SEPARATOR_OP') ||
		scTk.is('NEWLINE') ||
		scTk.is('NEWLINE_LIST') ||
		scTk.value === ';' ||
		scTk.is('PIPE') ||
		scTk.is('OR_IF') ||
		scTk.is('PIPE') ||
		scTk.is('AND_IF')
	);
}

function couldBeCommandName(tk) {
	return tk && tk.is('WORD') && isValidName(tk.value);
}

module.exports = () => compose(
	map((tk, idx, iterable) => {
		if (tk._.maybeStartOfSimpleCommand) {
			if (couldBeCommandName(tk)) {
				tk._.maybeSimpleCommandName = true;
			} else {
				const next = iterable.ahead(1);
				if (next && !couldEndSimpleCommand(next)) {
					next._.commandNameNotFoundYet = true;
				}
			}
		}

		if (tk._.commandNameNotFoundYet) {
			const last = iterable.behind(1);

			if (!isOperator(last) && couldBeCommandName(tk)) {
				tk._.maybeSimpleCommandName = true;
			} else {
				const next = iterable.ahead(1);
				if (next && !couldEndSimpleCommand(next)) {
					next._.commandNameNotFoundYet = true;
				}
			}
			delete tk._.commandNameNotFoundYet;
		}

		return tk;
	}),
	lookahead
);
{'fraction_non_alphanumeric': 0.17521194993944286, 'fraction_numerical': 0.0012111425111021397, 'mean_word_length': 3.4972776769509983, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '3753045', 'n_tokens_mistral': 1062, 'n_tokens_neox': 907, 'n_words': 153}