Skip to content

Commit

Permalink
FormatOps: simplify functionExpire
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Mar 16, 2024
1 parent 7460512 commit adf6c79
Showing 1 changed file with 2 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -921,29 +921,13 @@ class FormatOps(
maxPrecedence
}

def functionExpire(function: Term.FunctionTerm): (T, ExpiresOn) = {
def dropWS(rtoks: Seq[T]): Seq[T] =
rtoks.dropWhile(_.is[T.Whitespace])
def orElse(rtoks: Seq[T]) = {
val last = rtoks.head
if (last.is[T.RightParen] && matchingOpt(last).contains(rtoks.last))
rtoks.tail.find(!_.is[T.Whitespace]).get -> ExpiresOn.After
else
last -> ExpiresOn.After
}
def dropComment(rtoks: Seq[T]) =
if (rtoks.head.is[T.Comment]) dropWS(rtoks.tail) else rtoks

def getRToks = dropWS(function.tokens.reverse)
def functionExpire(function: Term.FunctionTerm): (T, ExpiresOn) =
function.parent match {
case Some(SingleArgInBraces.OrBlock(_, _, e)) =>
e.left -> ExpiresOn.Before
case Some(Case(_, _, `function`)) =>
orElse(dropComment(getRToks))
case _ =>
orElse(getRToks)
tokens.getLastExceptParen(function).left -> ExpiresOn.After
}
}

def noOptimizationZones(): Set[T] = {
val result = Set.newBuilder[T]
Expand Down

0 comments on commit adf6c79

Please sign in to comment.