///|
/// Editor input may be broken while a translator is typing. Preserve Junk and
/// continue exposing valid entries; convert scalar spans to LSP UTF-16 positions.
fn main {
  let source = "# 😀\nbad = { $ }\nvalid = Welcome\n"
  let root = @ftl.parse(source)
  let map = @ftl.SourceMap::new(source)
  let visits = match root.walk() {
    Ok(v) => v
    Err(_) => abort("traversal failed")
  }
  let mut errors = 0
  for visit in visits {
    match visit.node.kind {
      Annotation(code, _, message) => {
        let position = map.position(visit.node.span.start) catch {
          _ => abort("invalid diagnostic span")
        }
        println("\{code} at \{position.line}:\{position.character}: \{message}")
        errors += 1
      }
      _ => ()
    }
  }
  let catalog = match @ftl.Catalog::build(root) {
    Ok(c) => c
    Err(_) => abort("catalog failed")
  }
  if errors != 1 ||
    catalog.definitions().length() != 1 ||
    catalog.find(@ftl.MessageSymbol, "valid").length() != 1 {
    abort("recovery regression")
  }
  println("editor: 1 diagnostic, valid message preserved")
}