import { isString } from 'lodash-es';
import { createToken } from 'chevrotain';
import { KEYWORD, NAME, namePattern } from './shared-tokens.js';
export default function createTokenFromConfig(config) {
    if (!config) {
        throw new Error("Can't create a token without the proper config.");
    }
    if (isString(config.pattern) && namePattern.test(config.pattern)) {
        config.longer_alt = NAME;
        if (!config.categories) {
            config.categories = [];
        }
        if (!Array.isArray(config.categories)) {
            config.categories = [config.categories];
        }
        config.categories.push(KEYWORD);
    }
    if (isString(config.pattern) && !config.label) {
        config.label = `'${config.pattern}'`;
    }
    return createToken(config);
}
