diff --git a/src/Nixfmt/Parser.hs b/src/Nixfmt/Parser.hs index f424876f..ddfb558d 100644 --- a/src/Nixfmt/Parser.hs +++ b/src/Nixfmt/Parser.hs @@ -17,7 +17,7 @@ import Data.Maybe (fromMaybe, mapMaybe, maybeToList) import Data.Text (Text) import qualified Data.Text as Text import Data.Void (Void) -import Nixfmt.Lexer (lexeme, pushTrivia, takeTrivia, whole) +import Nixfmt.Lexer (lexeme, takeTrivia, whole) import Nixfmt.Parser.Float (floatParse) import Nixfmt.Types ( Ann (..), @@ -38,7 +38,6 @@ import Nixfmt.Types ( StringPart (..), Term (..), Token (..), - Trivium (..), Whole (..), operators, tokenText, @@ -470,7 +469,7 @@ operator t = TMinus -> ">" TMul -> "/" TDiv -> "/*" - TLess -> "=" + TLess -> "=|" TGreater -> "=" TNot -> "=" _ -> "" diff --git a/src/Nixfmt/Types.hs b/src/Nixfmt/Types.hs index c41e5841..3429bd71 100644 --- a/src/Nixfmt/Types.hs +++ b/src/Nixfmt/Types.hs @@ -424,6 +424,8 @@ data Token | TLessEqual | TNot | TUnequal + | TPipeForward + | TPipeBackward | SOF deriving (Eq, Show) @@ -466,7 +468,9 @@ operators = ], [Op InfixL TAnd], [Op InfixL TOr], - [Op InfixL TImplies] + [Op InfixL TImplies], + [Op InfixL TPipeForward], + [Op InfixR TPipeBackward] ] tokenText :: Token -> Text @@ -519,4 +523,6 @@ tokenText TLess = "<" tokenText TLessEqual = "<=" tokenText TNot = "!" tokenText TUnequal = "!=" +tokenText TPipeForward = "|>" +tokenText TPipeBackward = "<|" tokenText SOF = "" diff --git a/test/diff/operation/in.nix b/test/diff/operation/in.nix index 44d3ba92..70ec4563 100644 --- a/test/diff/operation/in.nix +++ b/test/diff/operation/in.nix @@ -156,4 +156,17 @@ z = 30; } ) + + # Experimental pipe operators + ( + a // b + |> f "very long argument should justify splitting this over multiple lines" + |> g { } + ) + + ( + g { } <| + f "very long argument should justify splitting this over multiple lines" <| + a // b + ) ] diff --git a/test/diff/operation/out.nix b/test/diff/operation/out.nix index f094d0d2..f032b244 100644 --- a/test/diff/operation/out.nix +++ b/test/diff/operation/out.nix @@ -273,4 +273,17 @@ z = 30; } ) + + # Experimental pipe operators + ( + a // b + |> f "very long argument should justify splitting this over multiple lines" + |> g { } + ) + + ( + g { } + <| f "very long argument should justify splitting this over multiple lines" + <| a // b + ) ]