update-nix-fetchgit-0.2.3: A program to update fetchgit values in Nix expressions
Safe HaskellNone
LanguageHaskell2010

Nix.Comments

Synopsis

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")]