diff --git a/src/Nixfmt/Parser.hs b/src/Nixfmt/Parser.hs index 647283d9..92ca7622 100644 --- a/src/Nixfmt/Parser.hs +++ b/src/Nixfmt/Parser.hs @@ -342,12 +342,20 @@ list = List <$> symbol TBrackOpen <*> items term <*> symbol TBrackClose -- OPERATORS -opChars :: [Char] -opChars = "<>=+*/." - operator :: Token -> Parser Leaf operator t = label "operator" $ try $ lexeme $ - rawSymbol t <* notFollowedBy (oneOf opChars) + rawSymbol t <* notFollowedBy (oneOf ( + -- Resolve ambiguities between operators which are prefixes of others + case t of + TPlus -> "+" :: [Char] + TMinus -> ">" + TMul -> "/" + TDiv -> "/*" + TLess -> "=" + TGreater -> "=" + TNot -> "=" + _ -> "" + )) opCombiner :: Operator -> MPExpr.Operator Parser Expression opCombiner Apply = MPExpr.InfixL $ return Application diff --git a/test/correct/operator-after-operator.nix b/test/correct/operator-after-operator.nix new file mode 100644 index 00000000..d4ba6740 --- /dev/null +++ b/test/correct/operator-after-operator.nix @@ -0,0 +1,3 @@ +# https://github.com/NixOS/nixfmt/issues/122 +(1+/**/1) +(1+.4)