Skip to content

Commit

Permalink
Added description of AutomataMatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
kellegous committed Oct 31, 2024
1 parent 565ab64 commit 67297a2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,26 @@ $matcher = AutomataMatcher::build($owners->getRules());
$rule = $matcher->match($relative_path);
```

## TODO

- [x] Add comments to the structure
- [x] Complete phpdocs
- [x] Add error checking on `match` to normalize or reject impossible patterns (i.e. "" and "/...")
- [ ] Explain how `AutomataMatcher` works in this file.
- [x] Should I support whitespace escaping in patterns?
- [x] Add ability to turn `Owners` into string.
- [x] Test owners entries.
- [x] Test entries to string.
- [x] Test pattern escaping.
- [x] Test no-owners rules
- [x] Remove ext-json from requires.
- [x] Add ext-ctype to requires.
- [x] Convert json tests to PHP arrays.
- [ ] Add a command line tool for dot-renderer
- [x] Add tests for all entries.
#### What does the AutomataMatcher do?

Each of the patterns in a `CODEOWNERS` rule is a simplified regular expression and, thus, it could be represented as a
fininte automata. In fact, the `SimpleMatcher` turns each of the patterns into a regular expression and then iteratively
matches the path against those regular expressions. In other words, the `SimpleMatcher` executes the finite automata
of each rule independently. The `AutomataMatcher`, on the other hand, combines all of the patterns into a single finite
automata. For example, here is the state machine for Github's [exmaple CODEOWNERS](tests/CODEOWNERS.example).

![Automata for CODEOWNERS.example](tests/CODEOWNERS.example.png)

The image was rendered with the following command:

```bash
bin/render-nfa tests/CODEOWNERS.example | dot -Tpng -o tests/CODEOWNERS.example.png
```

## Acknowledgements

The code in `SimpleMatcher` that converts patterns to regular expressions owes a debt of gratitude
to https://github.com/hmarr/codeowners.

## Author(s)

Expand Down
File renamed without changes.
Binary file added tests/CODEOWNERS.example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 67297a2

Please sign in to comment.