<commit_before>import {Parser, Either, State, ParserError, createParser} from '../base';
import {startsWith} from '../utils';

export function symbol(symbol: string): Parser<any, string> {
  return createParser((state: State<any>) => {
    if (startsWith(state.str, symbol)) {
      const newState = new State(
        state.str.substr(symbol.length),
        symbol,
        state.row,
        state.col + symbol.length
      );

      return Either.point(newState);
    }

    return Either.left(new ParserError(`Couldn't parse symbol '${symbol}'`, state));
  });
}
<commit_msg><improvement>(symbol): implement symbol using State.consumeText<commit_after>import {Parser, Either, State, ParserError, createParser} from '../base';
import {startsWith} from '../utils';

export function symbol(symbol: string): Parser<any, string> {
  return createParser((state: State<any>) => {
    if (startsWith(state.str, symbol)) {
      const newState = state.consumeText(symbol);

      return Either.point(newState);
    }

    return Either.left(new ParserError(`Couldn't parse symbol '${symbol}'`, state));
  });
}

{'fraction_non_alphanumeric': 0.15266485998193316, 'fraction_numerical': 0.0, 'mean_word_length': 3.881057268722467, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 10, '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': '2184082', 'n_tokens_mistral': 329, 'n_tokens_neox': 325, 'n_words': 82}