1
1
mirror of https://github.com/github/semantic.git synced 2024-12-23 23:11:50 +03:00

Revert "Run assignments using iterLookahead."

This reverts commit 2a280ffb7dea2707e13bc518d93af9d6e0648bd0.
This commit is contained in:
Rob Rix 2017-08-03 15:38:17 -04:00
parent d3895a504e
commit dd8e283632

View File

@ -257,15 +257,14 @@ runAssignment :: forall grammar a ast. (Symbol grammar, Enum grammar, Eq grammar
runAssignment toNode source = (\ assignment state -> go assignment state >>= requireExhaustive)
-- Note: We explicitly bind toNode & source above in order to ensure that the where clause can close over them; they dont change through the course of the run, so holding one reference is sufficient. On the other hand, we dont want to accidentally capture the assignment and state in the where clause, since they change at every step—and capturing when you meant to shadow is an easy mistake to make, & results in hard-to-debug errors. Binding them in a lambda avoids that problem while also being easier to follow than a pointfree definition.
where go :: Assignment ast grammar result -> State ast grammar -> Either (Error grammar) (result, State ast grammar)
go assignment = iterLookahead run ((pure .) . (,) <$> assignment)
go assignment = iterFreer run ((pure .) . (,) <$> assignment)
{-# INLINE go #-}
run :: AssignmentF ast grammar x
-> Maybe (Assignment ast grammar y)
-> (x -> State ast grammar -> Either (Error grammar) (result, State ast grammar))
-> State ast grammar
-> Either (Error grammar) (result, State ast grammar)
run assignment _ yield initialState = maybe (anywhere Nothing) (atNode . F.project) (listToMaybe (stateNodes state))
run assignment yield initialState = maybe (anywhere Nothing) (atNode . F.project) (listToMaybe (stateNodes state))
where atNode node = case assignment of
Location -> yield (nodeLocation (toNode node)) state
Project projection -> yield (projection node) state