<commit_before>library petitparser.core.characters.pattern;

import 'package:petitparser/src/core/characters/char.dart';
import 'package:petitparser/src/core/characters/code.dart';
import 'package:petitparser/src/core/characters/not.dart';
import 'package:petitparser/src/core/characters/optimize.dart';
import 'package:petitparser/src/core/characters/parser.dart';
import 'package:petitparser/src/core/characters/range.dart';
import 'package:petitparser/src/core/parser.dart';
import 'package:petitparser/src/core/predicates/any.dart';

/// Returns a parser that accepts the given character class pattern.
Parser pattern(String element, [String message]) {
  return new CharacterParser(_patternParser.parse(element).value,
      message ?? '[${toReadableString(element)}] expected');
}

Parser _createPatternParser() {
  var single = any().map((String element) {
    return new RangeCharPredicate(toCharCode(element), toCharCode(element));
  });
  var range = any().seq(char('-')).seq(any()).map((List elements) {
    return new RangeCharPredicate(
        toCharCode(elements[0]), toCharCode(elements[2]));
  });
  var positive =
      range.or(single).plus().map((List predicates) {
    return optimizedRanges(predicates.cast<RangeCharPredicate>());
  });
  return char('^')
      .optional()
      .seq(positive)
      .map((List predicates) {
    return predicates[0] == null
        ? predicates[1]
        : new NotCharacterPredicate(predicates[1]);
  });
}

final _patternParser = _createPatternParser();<commit_msg>Use List.from instead of cast<commit_after>library petitparser.core.characters.pattern;

import 'package:petitparser/src/core/characters/char.dart';
import 'package:petitparser/src/core/characters/code.dart';
import 'package:petitparser/src/core/characters/not.dart';
import 'package:petitparser/src/core/characters/optimize.dart';
import 'package:petitparser/src/core/characters/parser.dart';
import 'package:petitparser/src/core/characters/range.dart';
import 'package:petitparser/src/core/parser.dart';
import 'package:petitparser/src/core/predicates/any.dart';

/// Returns a parser that accepts the given character class pattern.
Parser pattern(String element, [String message]) {
  return new CharacterParser(_patternParser.parse(element).value,
      message ?? '[${toReadableString(element)}] expected');
}

Parser _createPatternParser() {
  var single = any().map((String element) {
    return new RangeCharPredicate(toCharCode(element), toCharCode(element));
  });
  var range = any().seq(char('-')).seq(any()).map((List elements) {
    return new RangeCharPredicate(
        toCharCode(elements[0]), toCharCode(elements[2]));
  });
  var positive =
      range.or(single).plus().map((List predicates) {
    return optimizedRanges(new List<RangeCharPredicate>.from(predicates, growable: false));
  });
  return char('^')
      .optional()
      .seq(positive)
      .map((List predicates) {
    return predicates[0] == null
        ? predicates[1]
        : new NotCharacterPredicate(predicates[1]);
  });
}

final _patternParser = _createPatternParser();
{'fraction_non_alphanumeric': 0.14729685982518614, 'fraction_numerical': 0.0032372936225315637, 'mean_word_length': 5.046966731898239, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '913274', 'n_tokens_mistral': 950, 'n_tokens_neox': 949, 'n_words': 164}