1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 22:31:36 +03:00

Take the first zero-error term, if any, before forcing the rest.

This commit is contained in:
Rob Rix 2017-08-03 21:04:38 -04:00
parent 42a22aad72
commit cbff2fee2d

View File

@ -35,10 +35,11 @@ import Control.Monad.Free.Freer
import Data.Amb import Data.Amb
import Data.Blob import Data.Blob
import qualified Data.ByteString as B import qualified Data.ByteString as B
import Data.Foldable (fold, for_) import Data.Foldable (find, fold, for_)
import Data.Functor.Both as Both hiding (snd) import Data.Functor.Both as Both hiding (snd)
import Data.Functor.Foldable (cata) import Data.Functor.Foldable (cata)
import Data.List (minimumBy) import Data.List (minimumBy)
import Data.Maybe (fromMaybe)
import Data.Ord (comparing) import Data.Ord (comparing)
import Data.Record import Data.Record
import Data.Semigroup ((<>)) import Data.Semigroup ((<>))
@ -204,7 +205,7 @@ runParser Options{..} blob@Blob{..} = go
writeLog Error (Assignment.formatErrorWithOptions optionsPrintSource (optionsIsTerminal && optionsEnableColour) blob err) blobFields writeLog Error (Assignment.formatErrorWithOptions optionsPrintSource (optionsIsTerminal && optionsEnableColour) blob err) blobFields
pure $ Right (Syntax.makeTerm (totalRange blobSource :. totalSpan blobSource :. Nil) (Syntax.Error (fmap show err) [])) pure $ Right (Syntax.makeTerm (totalRange blobSource :. totalSpan blobSource :. Nil) (Syntax.Error (fmap show err) []))
Some terms -> do Some terms -> do
let (term, _) = minimumBy (comparing (Assignment.stateErrorCounter . snd)) terms let (term, _) = fromMaybe (minimumBy (comparing (Assignment.stateErrorCounter . snd)) terms) (find ((== 0) . Assignment.stateErrorCounter . snd) terms)
for_ (errors term) $ \ err -> for_ (errors term) $ \ err ->
writeLog Warning (Assignment.formatErrorWithOptions optionsPrintSource optionsEnableColour blob err) blobFields writeLog Warning (Assignment.formatErrorWithOptions optionsPrintSource optionsEnableColour blob err) blobFields
pure $ Right term pure $ Right term