publicsuffix / list

The Public Suffix List
https://publicsuffix.org/
Mozilla Public License 2.0
1.93k stars 1.18k forks source link

tools/internal/parser: refactor to separate text processing from parser main logic #1999

Closed danderson closed 3 weeks ago

danderson commented 4 weeks ago

This splits up the parser logic: a lower level helper breaks up the input bytes in useful ways and tracks source information for error reports. The main parser uses the helper, so that it can focus on the "business logic" of checking the format and linting, without being polluted with tracking offsets and partial state and stuff.

The PR is in 2 commits, each one is ~50% of the change: the first adds the new helper without using it, in text.go and text_test.go. The second commit updates parser.go to use the helper.

The helper has a bunch more unit tests, but the parser functionality is unchanged, and all pre-existing tests pass without modification. Later PRs (see todo) will add missing features, this is just a cleanup to prepare for that.