parated by one or more space-characters
headtail = (s) ->
  a, b, head, tail = s\find '(.-)%s+(.*)'
  if a then head, tail else s, ''

-- Iterator function for headtail
words = (s) -> ->
  return if s == ''
  head, tail = headtail s
  s = tail
  head

-- Clamp a number value to a range
clamp = (val, min, max) ->
  if val < min then min elseif val > max then max else val

-- Interpolate between two numbers
interpolate = (pct, min, max) ->
  if pct <= 0 then min elseif pct >= 1 then max else pct * (max - min) + min

-- Interpolate between two colour values, given in either style definition or style override format
-- Return in style override format
interpolate_color = (pct, first, last) ->
  r1, g1, b1 = extract_color first
  r2, g2, b2 = extract_color last
  r, g, b = interpolate(<FILL-HERE>, g2), interpolate(pct, b1, b2)
  ass_color r, g, b

-- Interpolate between two alpha values, given either in style override or as part as a style definition colour
-- Return in style override format
i
<fim-prefix>parated by one or more space-characters
headtail = (s) ->
  a, b, head, tail = s\find '(.-)%s+(.*)'
  if a then head, tail else s, ''

-- Iterator function for headtail
words = (s) -> ->
  return if s == ''
  head, tail = headtail s
  s = tail
  head

-- Clamp a number value to a range
clamp = (val, min, max) ->
  if val < min then min elseif val > max then max else val

-- Interpolate between two numbers
interpolate = (pct, min, max) ->
  if pct <= 0 then min elseif pct >= 1 then max else pct * (max - min) + min

-- Interpolate between two colour values, given in either style definition or style override format
-- Return in style override format
interpolate_color = (pct, first, last) ->
  r1, g1, b1 = extract_color first
  r2, g2, b2 = extract_color last
  r, g, b = interpolate(<fim-suffix>, g2), interpolate(pct, b1, b2)
  ass_color r, g, b

-- Interpolate between two alpha values, given either in style override or as part as a style definition colour
-- Return in style override format
i<fim-middle>pct, r1, r2), interpolate(pct, g1
pct, r1, r2)
  g, b = interpolate(pct, g1, g2)
  ass_color r, g, b

-- Interpolate between two alpha values, given either in style override or as part as a style definition colour
-- Return in style override format
interpolate_alpha = (pct, first, last) ->
  r1, g1, b1 = extract_alpha first
  r2, g2, b2 = extract_alpha last
  r, g, b = interpolate(pct, r1, r2)
  g, b = interpolate(pct, g1, g2)
  ass_alpha r, g, b

-- Interpolate between two colour values, given in either style definition or style override format
-- Return in style override format
interpolate_colour_alpha = (pct, first, last) ->
  r1, g1, b1 = extract_colour_alpha first
  r2, g2, b2 = extract_colour_alpha last
  r, g, b = interpolate(pct, r1, r2)
  g, b = interpolate(pct, g1, g2)
  ass_colour r, g, b
  ass_alpha r, g, b

-- Interpolate between two alpha values, given either in style override or as part as a style definition colour
-- Return in style override format
interpolate_alpha_colour = (pct, first, last) ->
  r1, g1, b1 = extract_alpha_colour first
  r2, g2, b2 = extract_alpha_colour last
  r, g, b = interpolate(pct, r1, r2)
  g, b = interpolate(pct, g1, g2)
  ass_alpha r, g, b
  ass_colour r, g, b

-- Interpolate between two colour values, given in either style definition or style override format
-- Return in style override format
interpolate_colour_alpha_alpha = (pct, first, last) ->
  r1, g1, b1 = extract_colour_alpha_alpha first
  r2, g2, b2 = extract_colour_alpha_alpha last
  r, g, b = interpolate(pct, r1, r2)
  g, b = interpolate(pct, g1, g2)
  ass_colour r, 