Skip to content

Commit

Permalink
FormatTokensRewrite: token index in Replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Mar 27, 2024
1 parent e4d8ba7 commit bcbc17e
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ object FormatTokensRewrite {
claimed.get(ftIdx) match {
case Some(x) =>
val repl = tokens(x)
val ok = (repl eq null) || repl.ft.meta.idx == ftIdx
val ok = (repl eq null) || repl.idx == ftIdx
if (ok) Some((x, repl)) else None
case _ => None
}
Expand All @@ -330,9 +330,8 @@ object FormatTokensRewrite {
val ok = orepl != null && (orepl.rule eq repl.rule) &&
orepl.isRemove
if (ok) {
tokens(oldidx) =
repl.copy(ft = repl.ft.withIdx(orepl.ft.meta.idx))
Some(repl.copy(ft = orepl.ft.withIdx(repl.ft.meta.idx)))
tokens(oldidx) = repl.copy(ft = repl.ft.withIdx(orepl.idx))
Some(repl.copy(ft = orepl.ft.withIdx(repl.idx)))
} else None
}
case _ => None
Expand Down Expand Up @@ -376,7 +375,7 @@ object FormatTokensRewrite {

private[rewrite] def isRemovedOnLeftOpt(x: FormatToken): Option[Boolean] = {
val ftIdx = x.meta.idx - 1
claimedRule(ftIdx).filter(_.ft.meta.idx == ftIdx).map(_.isRemove)
claimedRule(ftIdx).filter(_.idx == ftIdx).map(_.isRemove)
}

private[rewrite] def isRemovedOnLeft(x: FormatToken, ok: Boolean): Boolean =
Expand All @@ -393,6 +392,7 @@ object FormatTokensRewrite {
claim: Iterable[Int] = Nil
) {
@inline def isRemove: Boolean = how eq ReplacementType.Remove
@inline def idx: Int = ft.meta.idx
}

private[rewrite] sealed trait ReplacementType
Expand Down

0 comments on commit bcbc17e

Please sign in to comment.