Skip to content

Commit

Permalink
add --noted flag on haskell-syntax-tree
Browse files Browse the repository at this point in the history
  • Loading branch information
german1608 committed Jun 6, 2020
1 parent 34faf94 commit 2e89db9
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 36 deletions.
1 change: 0 additions & 1 deletion dhall-docs/src/Dhall/Docs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import Options.Applicative (Parser, ParserInfo)
import qualified Options.Applicative



{-| To specify if the tool should generate a single HTML page with all the
package information or one for each file in your package
-}
Expand Down
87 changes: 52 additions & 35 deletions dhall/src/Dhall/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,49 @@ module Dhall.Main
, main
) where

import Control.Applicative (optional, (<|>))
import Control.Exception (Handler(..), SomeException)
import Control.Monad (when)
import Data.List.NonEmpty (NonEmpty(..))
import Data.Monoid ((<>))
import Data.Text (Text)
import Control.Applicative (optional, (<|>))
import Control.Exception (Handler (..), SomeException)
import Control.Monad (when)
import Data.List.NonEmpty (NonEmpty (..))
import Data.Monoid ((<>))
import Data.Text (Text)
import Data.Text.Prettyprint.Doc (Doc, Pretty)
import Data.Void (Void)
import Dhall.Freeze (Intent(..), Scope(..))
import Dhall.Import (Imported(..), Depends(..), SemanticCacheMode(..), _semanticCacheMode)
import Dhall.Parser (Src)
import Dhall.Pretty (Ann, CharacterSet(..), annToAnsiStyle)
import Dhall.TypeCheck (Censored(..), DetailedTypeError(..), TypeError)
import Dhall.Version (dhallVersionString)
import Options.Applicative (Parser, ParserInfo)
import System.Exit (ExitCode, exitFailure)
import System.IO (Handle)
import Text.Dot ((.->.))
import Data.Void (Void)
import Dhall.Freeze (Intent (..), Scope (..))
import Dhall.Import
( Depends (..)
, Imported (..)
, SemanticCacheMode (..)
, _semanticCacheMode
)
import Dhall.Parser (Src)
import Dhall.Pretty (Ann, CharacterSet (..), annToAnsiStyle)
import Dhall.TypeCheck
( Censored (..)
, DetailedTypeError (..)
, TypeError
)
import Dhall.Version (dhallVersionString)
import Options.Applicative (Parser, ParserInfo)
import System.Exit (ExitCode, exitFailure)
import System.IO (Handle)
import Text.Dot ((.->.))

import Dhall.Core
( Expr(Annot)
, Import(..)
, ImportHashed(..)
, ImportType(..)
, URL(..)
( Expr (Annot)
, Import (..)
, ImportHashed (..)
, ImportType (..)
, URL (..)
, pretty
)
import Dhall.Util
( Censor(..)
, CheckFailed(..)
( Censor (..)
, CheckFailed (..)
, Header (..)
, Input(..)
, OutputMode(..)
, Output(..)
, Input (..)
, Output (..)
, OutputMode (..)
)

import qualified Codec.CBOR.JSON
Expand Down Expand Up @@ -82,18 +91,18 @@ import qualified Dhall.Import
import qualified Dhall.Import.Types
import qualified Dhall.Lint
import qualified Dhall.Map
import qualified Dhall.Tags
import qualified Dhall.Pretty
import qualified Dhall.Repl
import qualified Dhall.Tags
import qualified Dhall.TypeCheck
import qualified Dhall.Util
import qualified GHC.IO.Encoding
import qualified Options.Applicative
import qualified System.AtomicWrite.Writer.LazyText as AtomicWrite.LazyText
import qualified System.Console.ANSI
import qualified System.Exit as Exit
import qualified System.IO
import qualified System.FilePath
import qualified System.IO
import qualified Text.Dot
import qualified Text.Pretty.Simple

Expand Down Expand Up @@ -150,7 +159,7 @@ data Mode
| Decode { file :: Input, json :: Bool, quiet :: Bool }
| Text { file :: Input }
| DirectoryTree { file :: Input, path :: FilePath }
| SyntaxTree { file :: Input }
| SyntaxTree { file :: Input, noted :: Bool }

data ResolveMode
= Dot
Expand Down Expand Up @@ -291,7 +300,7 @@ parseMode =
Debugging
"haskell-syntax-tree"
"Output the parsed syntax tree (for debugging)"
(SyntaxTree <$> parseFile)
(SyntaxTree <$> parseFile <*> parseNoted)
<|> ( Default
<$> parseFile
<*> parseOutput
Expand Down Expand Up @@ -468,6 +477,12 @@ parseMode =
<> Options.Applicative.metavar "PATH"
)

parseNoted =
Options.Applicative.switch
( Options.Applicative.long "noted"
<> Options.Applicative.help "Print `Note` constructors"
)

-- | `ParserInfo` for the `Options` type
parserInfoOptions :: ParserInfo Options
parserInfoOptions =
Expand Down Expand Up @@ -867,10 +882,12 @@ command (Options {..}) = do
SyntaxTree {..} -> do
expression <- getExpression file

let denoted :: Expr Void Import
denoted = Dhall.Core.denote expression

Text.Pretty.Simple.pPrintNoColor denoted
if noted then
Text.Pretty.Simple.pPrintNoColor expression
else
let denoted :: Expr Void Import
denoted = Dhall.Core.denote expression
in Text.Pretty.Simple.pPrintNoColor denoted

-- | Entry point for the @dhall@ executable
main :: IO ()
Expand Down

0 comments on commit 2e89db9

Please sign in to comment.