Skip to content

Commit

Permalink
Support pipe operators
Browse files Browse the repository at this point in the history
  • Loading branch information
rhendric committed Jul 25, 2024
1 parent e819b2d commit 2c6f39e
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
| TPipeTo
| TPipeFrom
| 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 TPipeTo],
[Op InfixR TPipeFrom]
]

tokenText :: Token -> Text
Expand Down Expand Up @@ -519,4 +523,6 @@ tokenText TLess = "<"
tokenText TLessEqual = "<="
tokenText TNot = "!"
tokenText TUnequal = "!="
tokenText TPipeTo = "|>"
tokenText TPipeFrom = "<|"
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 2c6f39e

Please sign in to comment.