bskinn / pent

pent Extracts Numerical Text -- Mini-language driven parser for structured numerical data in text
MIT License
20 stars 3 forks source link

Add attrs validation to head, body, tail args on Parser #98

Open bskinn opened 4 years ago

bskinn commented 4 years ago

No real validation currently for head or tail.

The requirement for body being present currently relies on a ~hacky call to .pattern(), ultimately hitting this error.

Far better to just validate all three more consistently. An attrs validator won't work, because they could be instances of Parser, and that will be challenging to put into the main class body. Probably better to use instanceof(..., self.__class__) inside __attrs_post_init__.

head and tail could be None, str, Parser, or Iterable(? Collection? Sequence? Also, how to ensure str contents? Don't bother checking contents?); body is the same, save None is not allowed.