Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Policy: keep token in Policy.End, not just offset #4458

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2894,7 +2894,7 @@ class FormatOps(
def policyWithDelay(policy: Policy) = {
val beforeDelimsEnd = beforeDelims.right.end
// force break if multiline and if there's no other break
delayedBreakPolicy(Policy.End == beforeDelimsEnd, exclude)(
delayedBreakPolicy(Policy.End == beforeDelims.right, exclude)(
Policy.RelayOnSplit { case (s, nextft) =>
s.isNL && nextft.right.end > beforeDelimsEnd // don't need anymore
}(policy, NoPolicy),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,40 +416,34 @@ object Policy {
}

sealed trait End extends (Token => End.WithPos) {
def apply(endPos: Int): End.WithPos
final def apply(token: Token): End.WithPos = apply(token.end)
def apply(token: Token): End.WithPos
}
object End {
def <(endPos: Int): End.WithPos = Before(endPos)
def <(token: Token): End.WithPos = this < token.end

def >(endPos: Int): End.WithPos = After(endPos)
def >(token: Token): End.WithPos = this > token.end

def ==(endPos: Int): End.WithPos = On(endPos)
def ==(token: Token): End.WithPos = this == token.end
def <(token: Token): End.WithPos = Before(token)
def >(token: Token): End.WithPos = After(token)
def ==(token: Token): End.WithPos = On(token)

sealed trait WithPos {
def notExpiredBy(ft: FormatToken): Boolean
def ==>(policy: Policy): Policy =
if (policy.isEmpty) NoPolicy else new Policy.Delay(policy, this)
}
case object After extends End {
def apply(endPos: Int): WithPos = new End.WithPos {
def notExpiredBy(ft: FormatToken): Boolean = ft.left.end <= endPos
override def toString: String = s">$endPos"
def apply(token: Token): WithPos = new End.WithPos {
def notExpiredBy(ft: FormatToken): Boolean = ft.left.end <= token.end
override def toString: String = s">${token.structure}"
}
}
case object Before extends End {
def apply(endPos: Int): WithPos = new End.WithPos {
def notExpiredBy(ft: FormatToken): Boolean = ft.right.end < endPos
override def toString: String = s"<$endPos"
def apply(token: Token): WithPos = new End.WithPos {
def notExpiredBy(ft: FormatToken): Boolean = ft.right.end < token.end
override def toString: String = s"<${token.structure}"
}
}
case object On extends End {
def apply(endPos: Int): WithPos = new End.WithPos {
def notExpiredBy(ft: FormatToken): Boolean = ft.right.end <= endPos
override def toString: String = s"@$endPos"
def apply(token: Token): WithPos = new End.WithPos {
def notExpiredBy(ft: FormatToken): Boolean = ft.right.end <= token.end
override def toString: String = s"@${token.structure}"
}
}
}
Expand Down
Loading