// SOURCE: ARCHITECTURE/32-LANGUAGE-OFFICIAL-13-IMPLEMENTATION-5.md
// AUTO-EXTRACTED - Do not edit directly. Edit the source document.

import type { Datum } from "./datum";
import { isSym, isChar } from "./datum";
import type { Syntax } from "../syntax/syntax";

export function datumToSyntax(d: Datum): Syntax {
  if (isSym(d)) {
    return { tag: "Ident", name: d.sym, scopes: [] };
  }
  if (isChar(d)) {
    // Character literals are atoms with a special marker
    return { tag: "Atom", value: { $char: d.char }, scopes: [] };
  }
  if (Array.isArray(d)) {
    return { tag: "List", items: d.map(datumToSyntax), scopes: [] };
  }
  // atoms
  return { tag: "Atom", value: d, scopes: [] };
}