never executed always true always false
    1 {-# LANGUAGE DataKinds #-}
    2 module Parse.Parse (parse, parseModule, parseDeclarations, parseExpressions) where
    3 
    4 import qualified Text.Parsec.Error as Parsec
    5 
    6 import AST.V0_16
    7 import AST.Module (Module)
    8 import AST.Structure
    9 import ElmVersion hiding (parse)
   10 import Parse.Comments (withEol)
   11 import qualified Parse.Declaration
   12 import qualified Parse.Expression
   13 import Parse.Helpers
   14 import qualified Parse.Module
   15 import Reporting.Annotation (Located)
   16 import qualified Reporting.Region as R
   17 import qualified Reporting.Error.Syntax as Error
   18 import qualified Reporting.Result as Result
   19 import Parse.IParser
   20 import Text.Parsec (eof)
   21 
   22 
   23 parseModule :: ElmVersion -> String -> Result.Result () Error.Error (Module [UppercaseIdentifier] (ASTNS Located [UppercaseIdentifier] 'TopLevelNK))
   24 parseModule elmVersion src =
   25     parse src (Parse.Module.elmModule elmVersion)
   26 
   27 
   28 parseDeclarations :: ElmVersion -> String -> Result.Result () Error.Error [TopLevelStructure (ASTNS Located [UppercaseIdentifier] 'TopLevelDeclarationNK)]
   29 parseDeclarations elmVersion src =
   30     parse src (Parse.Module.topLevel (Parse.Declaration.declaration elmVersion) <* eof)
   31 
   32 
   33 parseExpressions :: ElmVersion -> String -> Result.Result () Error.Error [TopLevelStructure (C0Eol (ASTNS Located [UppercaseIdentifier] 'ExpressionNK))]
   34 parseExpressions elmVersion src =
   35     parse src (Parse.Module.topLevel (withEol $ Parse.Expression.expr elmVersion) <* eof)
   36 
   37 
   38 -- RUN PARSERS
   39 
   40 parse :: String -> IParser a -> Result.Result wrn Error.Error a
   41 parse source parser =
   42   case iParse parser source of
   43     Right result ->
   44         return result
   45 
   46     Left err ->
   47         let pos = R.fromSourcePos (Parsec.errorPos err)
   48             msgs = Parsec.errorMessages err
   49         in
   50             Result.throw (R.Region pos pos) (Error.Parse msgs)