dev-cafe / parselglossy

Generic input parsing library, speaking in tongues.
https://parselglossy.readthedocs.io
MIT License
7 stars 2 forks source link

Circular dependencies in default and predicate callables? #73

Closed robertodr closed 4 years ago

robertodr commented 5 years ago

Can we have circular dependencies in default and predicate callables? If not, we need to document why. If yes, we need a way to stop parsing with a meaningful error message.

bast commented 5 years ago

I see two options:

My preference goes to detecting and stopping to avoid surprises.

robertodr commented 5 years ago

Agreed on detect-and-stop. Not so clear how you'd detect though.

bast commented 5 years ago

We can build a graph of dependencies as we go through the tokens and then we check whether the graph is circular.

robertodr commented 5 years ago

Sounds good, hopefully there's a library for that :smile:

bast commented 5 years ago

I am tempted to program this myself as a little challenge. There are codes and libraries but they seem to be not lightweight for this relatively simple task.

bast commented 5 years ago

I see a graph as a dictionary mapping a to List[a].

I thought about it some more and I see no difficulties detecting cycles in a graph - the difficulty that I see is to translate defaults (and predicates?) into a graph since we use eval there and don't directly have access to the nodes of the graph.

robertodr commented 4 years ago

Closed in favor of #76 which has an actual example of chained dependencies which might degenerate into being circular.