function format(location, text, args = undefined) {
  let i = 0;
  text = text.replace(/%./g, function(s) {
    switch (s) {
      case '%s':
        return args && args[i++];
      case '%%':
        return '%';
    }
    return s;
  });
  if (location)
    text = `${location}: ${text}`;
  return text;
}
Formats an error message.
@param  {SourcePosition} location If present the source position is
    prepended to the message. Use |null| to not include the source
    position.
@param  {string} text The text to output. %s and %% are the only supported
    place holders.
@param  {Array=} args Array values to populate the placeholders with.
@return {string} The text where the source position has been prepended and
    where the place holders have been replaced.