Skip to content

Commit

Permalink
PolicyOps: use Policy.Delay for decideNewlineXxx
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Nov 23, 2024
1 parent af0a598 commit 4cd3d62
Showing 1 changed file with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ object PolicyOps {
)
}

final class DecideNewlinesOnlyBeforeToken(
final class DecideNewlinesOnlyBeforeToken private (
val token: FT,
split: Option[Split],
val rank: Int = 0,
ifAny: Boolean = false,
val rank: Int,
ifAny: Boolean,
)(implicit fileLine: FileLine)
extends Policy.Clause {
override val endPolicy: Policy.End.WithPos = Policy.End <= token
Expand All @@ -124,11 +124,21 @@ object PolicyOps {
}
}

final class DecideNewlinesOnlyAfterToken(
object DecideNewlinesOnlyBeforeToken {
def apply(
token: FT,
split: Option[Split],
rank: Int = 0,
ifAny: Boolean = false,
)(implicit fileLine: FileLine): Policy = Policy.End < token ==>
new DecideNewlinesOnlyBeforeToken(token, split, rank, ifAny)
}

final class DecideNewlinesOnlyAfterToken private (
val token: FT,
split: Option[Split],
val rank: Int = 0,
ifAny: Boolean = false,
val rank: Int,
ifAny: Boolean,
)(implicit fileLine: FileLine)
extends Policy.Clause {
override val endPolicy: Policy.End.WithPos = Policy.End >= token
Expand All @@ -149,6 +159,16 @@ object PolicyOps {
}
}

object DecideNewlinesOnlyAfterToken {
def apply(
token: FT,
split: Option[Split],
rank: Int = 0,
ifAny: Boolean = false,
)(implicit fileLine: FileLine): Policy = Policy.End <= token ==>
new DecideNewlinesOnlyAfterToken(token, split, rank, ifAny)
}

def policyWithExclude(
exclude: TokenRanges,
endLt: FT => Policy.End.WithPos,
Expand Down Expand Up @@ -185,7 +205,7 @@ object PolicyOps {

def decideNewlinesOnlyBeforeClose(split: Split, rank: Int = 0)(close: FT)(
implicit fileLine: FileLine,
): Policy = new DecideNewlinesOnlyBeforeToken(close, Option(split), rank)
): Policy = DecideNewlinesOnlyBeforeToken(close, Option(split), rank)

def decideNewlinesOnlyBeforeCloseOnBreak(close: FT)(implicit
fileLine: FileLine,
Expand All @@ -202,7 +222,7 @@ object PolicyOps {
def decideNewlinesOnlyBeforeToken(rank: Int, ifAny: Boolean = false)(
token: FT,
)(implicit fileLine: FileLine): Policy =
new DecideNewlinesOnlyBeforeToken(token, None, rank = rank, ifAny = ifAny)
DecideNewlinesOnlyBeforeToken(token, None, rank = rank, ifAny = ifAny)

def decideNewlinesOnlyAfterClose(close: FT)(implicit
fileLine: FileLine,
Expand All @@ -214,7 +234,7 @@ object PolicyOps {

def decideNewlinesOnlyAfterClose(split: Split, rank: Int = 0)(close: FT)(
implicit fileLine: FileLine,
): Policy = new DecideNewlinesOnlyAfterToken(close, Option(split), rank)
): Policy = DecideNewlinesOnlyAfterToken(close, Option(split), rank)

def decideNewlinesOnlyAfterToken(token: FT)(implicit
fileLine: FileLine,
Expand All @@ -223,7 +243,7 @@ object PolicyOps {
def decideNewlinesOnlyAfterToken(rank: Int, ifAny: Boolean = false)(
token: FT,
)(implicit fileLine: FileLine): Policy =
new DecideNewlinesOnlyAfterToken(token, None, rank = rank, ifAny = ifAny)
DecideNewlinesOnlyAfterToken(token, None, rank = rank, ifAny = ifAny)

def unindentAtExclude(exclude: TokenRanges, indent: Length): Policy = exclude
.ranges.foldLeft(Policy.noPolicy) { case (policy, range) =>
Expand Down

0 comments on commit 4cd3d62

Please sign in to comment.