<commit_before>part of dherkin;

final _NOTFOUND = new RegExp("###");

class StepdefProvider {
  static final _log = LoggerFactory.getLoggerFor(GherkinParser);

  Map _stepRunners = { _NOTFOUND : (ctx, params) => throw new StepDefUndefined()};

  Future<StepdefProvider> scan() {

    Completer comp = new Completer();
    Future.forEach(currentMirrorSystem().libraries.values, (LibraryMirror lib) {
      return new Future.sync(() {
        Future.forEach(lib.functions.values, (MethodMirror mm) {
          return new Future.sync(() {
            var filteredMetadata = mm.metadata.where((InstanceMirror im) => im.reflectee is StepDef);
            Future.forEach(filteredMetadata, (InstanceMirror im) {
              _log.debug(mm.simpleName.toString());
              _log.debug(im.reflectee.verbiage);

              _stepRunners[new RegExp(im.reflectee.verbiage)] = (ctx, params) {
                lib.invoke(mm.simpleName, [ctx, params]);
              };
            });
          });
        });
      });
    }).whenComplete(() => comp.complete(this));

    return comp.future;
  }

  Function locate(step) {
    var found = _stepRunners.keys.firstWhere((key) => key.hasMatch(step), orElse: () => _NOTFOUND);
    return () {
      var match = found.firstMatch(step);

      var params = [];
      var ctx = {};
      if (match != null) {
        for (var i = 1;i <= match.groupCount;i++) {
          params.add(match.group(i));
        }
      }

      _stepRunners[found](ctx,params);
    };
  }
}<commit_msg>changed group access on matcher to []<commit_after>part of dherkin;

final _NOTFOUND = new RegExp("###");

class StepdefProvider {
  static final _log = LoggerFactory.getLoggerFor(GherkinParser);

  Map _stepRunners = { _NOTFOUND : (ctx, params) => throw new StepDefUndefined()};

  Future<StepdefProvider> scan() {

    Completer comp = new Completer();
    Future.forEach(currentMirrorSystem().libraries.values, (LibraryMirror lib) {
      return new Future.sync(() {
        Future.forEach(lib.functions.values, (MethodMirror mm) {
          return new Future.sync(() {
            var filteredMetadata = mm.metadata.where((InstanceMirror im) => im.reflectee is StepDef);
            Future.forEach(filteredMetadata, (InstanceMirror im) {
              _log.debug(mm.simpleName.toString());
              _log.debug(im.reflectee.verbiage);

              _stepRunners[new RegExp(im.reflectee.verbiage)] = (ctx, params) {
                lib.invoke(mm.simpleName, [ctx, params]);
              };
            });
          });
        });
      });
    }).whenComplete(() => comp.complete(this));

    return comp.future;
  }

  Function locate(step) {
    var found = _stepRunners.keys.firstWhere((key) => key.hasMatch(step), orElse: () => _NOTFOUND);
    return () {
      var match = found.firstMatch(step);

      var params = [];
      var ctx = {};
      if (match != null) {
        for (var i = 1;i <= match.groupCount;i++) {
          params.add(match[i]);
        }
      }

      _stepRunners[found](ctx,params);
    };
  }
}
{'fraction_non_alphanumeric': 0.14551994767822107, 'fraction_numerical': 0.0006540222367560497, 'mean_word_length': 2.4920091324200913, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '3195369', 'n_tokens_mistral': 944, 'n_tokens_neox': 908, 'n_words': 182}