never executed always true always false
    1 {-# LANGUAGE DataKinds #-}
    2 module ElmFormat.Parse where
    3 
    4 import Elm.Utils ((|>))
    5 import AST.V0_16
    6 
    7 import AST.Module (Module)
    8 import AST.Structure ( ASTNS )
    9 import Data.Coapplicative
   10 import qualified Data.Text as Text
   11 import ElmVersion ( ElmVersion )
   12 import qualified Parse.Literal
   13 import qualified Parse.Parse as Parse
   14 import qualified Reporting.Error.Syntax as Syntax
   15 import qualified Reporting.Result as Result
   16 import Reporting.Annotation (Located)
   17 import qualified AST.Module as Module
   18 import qualified Parse.Module
   19 import Data.Text (Text)
   20 
   21 
   22 parse :: ElmVersion -> Text -> Result.Result () Syntax.Error (Module [UppercaseIdentifier] (ASTNS Located [UppercaseIdentifier] 'TopLevelNK))
   23 parse elmVersion input =
   24     Text.unpack input
   25         |> Parse.parseModule elmVersion
   26 
   27 
   28 toMaybe :: Result.Result a b c -> Maybe c
   29 toMaybe res =
   30     case res of
   31         Result.Result _ (Result.Ok c) ->
   32             Just c
   33         _ ->
   34             Nothing
   35 
   36 
   37 toEither :: Result.Result a b c -> Either [b] c
   38 toEither res =
   39     case res of
   40         Result.Result _ (Result.Ok c) ->
   41             Right c
   42         Result.Result _ (Result.Err b) ->
   43             Left $ map extract b
   44 
   45 
   46 import' :: ElmVersion -> Text -> Either [Syntax.Error] Module.UserImport
   47 import' elmVersion text =
   48     toEither $ Parse.parse (Text.unpack text) (Parse.Module.import' elmVersion)
   49 
   50 
   51 -- TODO: can this be removed?
   52 parseLiteral :: Text -> Result.Result () Syntax.Error LiteralValue
   53 parseLiteral input =
   54      Parse.parse (Text.unpack input) Parse.Literal.literal