Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- annotateWithComments :: Vector Text -> NExprLoc -> NExprComments
- type Comment = Text
- type NExprCommentsF = AnnF (Maybe Comment) NExprLocF
- type NExprComments = Fix NExprCommentsF
Documentation
annotateWithComments :: Vector Text -> NExprLoc -> NExprComments Source #
A comment will be added to an expression if it occurs immediately after the expression in the source, i.e. on the same line with only space and ';' in between.
>>>
import Nix.Parser
>>>
import Nix.Pretty
>>>
import Data.Vector
>>>
import Data.Foldable
>>>
lines = T.pack <$> ["1 # foo", "+ {a=2; # bar","} # baz"]
>>>
str = T.unlines $ lines
>>>
Success nix = parseNixTextLoc str
>>>
ann = annotateWithComments (fromList lines) nix
>>>
fixUniverse e = e : (fixUniverse =<< Data.Foldable.toList (unFix e))
>>>
pretty e@(Fix (Compose (Ann comment _)))= (prettyNix (stripAnnotation (stripAnnotation e)), comment)
>>>
pretty <$> fixUniverse ann
[(1 + { a = 2; },Just "baz"),(1,Just "foo"),({ a = 2; },Just "baz"),(2,Just "bar")]
type NExprComments = Fix NExprCommentsF Source #