Skip to content

Commit

Permalink
Merge pull request #227 from rhendric/rhendric/pipe-operators
Browse files Browse the repository at this point in the history
Support pipe operators
  • Loading branch information
infinisil authored Aug 6, 2024
2 parents e819b2d + 55feeb5 commit 08144b4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/Nixfmt/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (..),
Expand All @@ -38,7 +38,6 @@ import Nixfmt.Types (
StringPart (..),
Term (..),
Token (..),
Trivium (..),
Whole (..),
operators,
tokenText,
Expand Down Expand Up @@ -470,7 +469,7 @@ operator t =
TMinus -> ">"
TMul -> "/"
TDiv -> "/*"
TLess -> "="
TLess -> "=|"
TGreater -> "="
TNot -> "="
_ -> ""
Expand Down
8 changes: 7 additions & 1 deletion src/Nixfmt/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ data Token
| TLessEqual
| TNot
| TUnequal
| TPipeForward
| TPipeBackward
| SOF
deriving (Eq, Show)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -519,4 +523,6 @@ tokenText TLess = "<"
tokenText TLessEqual = "<="
tokenText TNot = "!"
tokenText TUnequal = "!="
tokenText TPipeForward = "|>"
tokenText TPipeBackward = "<|"
tokenText SOF = ""
13 changes: 13 additions & 0 deletions test/diff/operation/in.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
]
13 changes: 13 additions & 0 deletions test/diff/operation/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
]

0 comments on commit 08144b4

Please sign in to comment.