serokell / coffer

Multi-backend password store with multiple frontends
4 stars 2 forks source link

Reuse existing megaparsec parsers #89

Closed dcastro closed 2 years ago

dcastro commented 2 years ago

Clarification and motivation

The Web API reimplements some parsing logic to parse things like Filter (see the instance FromHttpApiData Filter).

We should reuse the same parsers we used in the CLI modules.

Additionally, the logic to parse a QualifiedPath is duplicated in FromHttpApiData (QualifiedPath path) and in CLI.Parser.readQualifiedEntryPath. We should try to have a single mkQualifiedPath function that is reused in the FromHttpApiData instance and in the CLI parser.

Acceptance criteria

Kariel-Myrr commented 2 years ago

Where we should store mk.... functions? We just importing parsers From CLI.Parser into other pkg? Or we should make some upper logic file?

dcastro commented 2 years ago

Where we should store mk.... functions?

The mkQualifiedPath functions should live next to the QualifiedPath type (similar to how mkPath lives next to Path).

We just importing parsers From CLI.Parser into other pkg?

Preferably, yes.

Though we might run into some issues. For example, right now we have:

Reusing parseFilter to implement instance FromHttpApiData Filter would create a cyclic dependency between the two modules (CLI.Parser depends on CLI.Types, CLI.Types depends on CLI.Parser). To avoid this cyclic dep, we should move parseFilter to CLI.Types.