<commit_before>const constant = {
    whitespaceRegex: new RegExp('[\s]+', 'g'),
    commentRegex: new RegExp('\/\/.+', 'g'),
    emptyWord: '',
    newLine: '\n'
}

class Command {
    constructor({ line }) {
        this.line = line;
    }

    valid() {
        return true;
    }

    preprocess() {
        return this;
    }

    build() {
        return `error at line ${ this.line }`;
    }
}

class LabelCommand extends Command {
    constructor({ token, line }) {
        this.line = line;
        this.token = token;
    }

    preprocess(context) {
        context[this.line + 1] = this.token;
        return this;
    }

    valid() {
        return false;
    }
}

class ACommand extends Command {
    constructor({ token }) {
        this.token = token;
    }
}

class CCommand extends Command{
    constructor({ token }) {
        this.token = token;
    }
}

export class Parser {
    constructor(srcCode = constant.emptyWord) {
        this.srcCode = srcCode;

        this.tokenize = src => src.split(constant.newLine);
        this.normalize = token => token
            .replace(constant.whitespaceRegex, constant.emptyWord)
            .replace(constant.commentRegex, constant.emptyWord);

        this.commandRouter = {
            '@\w+': token => new ACommand(token),
            '[\w+=]*.*[;\w*]*': token => new CCommand(token),
            '.*': token => new Command(token)
        };
    }

    makeCommand(input) {
        return new Object.keys(this.commandRouter)
            .map(route => new RegExp(route, 'g'))
            .find(routeRegex => routeRegex.test(token))(input);
    }

    parse() {
        let context = {};
        return this.tokenize(this.srcCode)
            .map(token => this.normalize(token))
            .filter(token => token !== constant.emptyWord)
            .map((token, line) => this.makeCommand({ token, line }))
            .map(command => command.preprocess(context))
            .filter(command => command.valid())
            .map(command => context[command.token])
            .join(constant.newLine);
    }
}<commit_msg>Add label token to router<commit_after>const constant = {
    whitespaceRegex: new RegExp('[\s]+', 'g'),
    commentRegex: new RegExp('\/\/.+', 'g'),
    emptyWord: '',
    newLine: '\n'
}

class Command {
    constructor({ line }) {
        this.line = line;
    }

    valid() {
        return true;
    }

    preprocess() {
        return this;
    }
}

class LabelCommand extends Command {
    constructor({ token, line }) {
        this.line = line;
        this.token = token;
    }

    preprocess(context) {
        context[this.line + 1] = this.token;
        return this;
    }

    valid() {
        return false;
    }
}

class ACommand extends Command {
    constructor({ token }) {
        this.token = token;
    }
}

class CCommand extends Command{
    constructor({ token }) {
        this.token = token;
    }
}

export class Parser {
    constructor(srcCode = constant.emptyWord) {
        this.srcCode = srcCode;

        this.tokenize = src => src.split(constant.newLine);
        this.normalize = token => token
            .replace(constant.whitespaceRegex, constant.emptyWord)
            .replace(constant.commentRegex, constant.emptyWord);

        this.commandRouter = {
            '\(.*\)': token => new LabelCommand(token),
            '@\w+': token => new ACommand(token),
            '[\w+=]*.*[;\w*]*': token => new CCommand(token),
            '.*': token => new Command(token)
        };
    }

    makeCommand(input) {
        return new Object.keys(this.commandRouter)
            .map(route => new RegExp(route, 'g'))
            .find(routeRegex => routeRegex.test(token))(input);
    }

    parse() {
        let context = {};
        return this.tokenize(this.srcCode)
            .map(token => this.normalize(token))
            .filter(token => token !== constant.emptyWord)
            .map((token, line) => this.makeCommand({ token, line }))
            .map(command => command.process(context))
            .filter(command => command.valid())
            .map(command => context[command.token])
            .join(constant.newLine);
    }
}
{'fraction_non_alphanumeric': 0.15065868263473053, 'fraction_numerical': 0.00047904191616766467, 'mean_word_length': 1.980728051391863, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 30, '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': '4604054', 'n_tokens_mistral': 1237, 'n_tokens_neox': 1219, 'n_words': 257}