step _ sh@(S [] (s:ss) oo ru) = case s of
  Leaf _             -> S [] ss (apply s oo) Application
  Branch _           -> S [] ss (apply s oo) Application
  Part y | end y && rightOpen y && stackedOp ru ->
    rule sh (failure $ MissingSubAfter $ symbol y)
    -- The infix or prefix operator has all its parts.
    -- The postfix/closed is handled in the first equation.
       | end y ->
    S [] ss (apply s oo) ApplyOp
       | otherwise ->
    -- The operator is not complete.
    rule sh (failure $
      next y `MissingAfter` current y)

-- The applicator/operator stack is empty.
step _ sh@(S [] (s:ss) oo ru) = case s of
  Leaf _             -> S [] ss (apply s oo) Application
  Branch _           -> S [] ss (apply s oo) Application
  Part y | end y && rightOpen y && stackedOp ru ->
    rule sh (failure $ MissingSubAfter $ symbol y)
    -- The infix or prefix operator has all its parts.
    -- The postfix/closed is handled in the first equation.
       | end y ->
    S [] ss (apply s oo) ApplyOp
       | otherwise ->
    -- The operator is not complete.
    rule sh (failure $
      next y `MissingAfter` current y)

-- The applicator/operator stack is empty.
step _ sh@(S [] (s:ss) oo ru) = case s of
  Leaf _             -> S [] ss (apply s oo) Application
  Branch _           -> S [] ss (apply s oo) Application
  Part y | end y && rightOpen y && stackedOp ru ->
    rule sh (failure $ MissingSubAfter $ symbol y)
    -- The infix or prefix operator has all its parts.
    -- The postfix/closed is handled in the first equation.
       | end y ->
    S [] ss (apply s oo) ApplyOp
       | otherwise ->
    -- The operator is not complete.
    rule sh (failure $
      next y `MissingAfter` current y)

-- The applicator/operator stack is empty.