;; lib/guest/pratt.sx — operator-table format + lookup for Pratt-style
;; precedence climbing.
;;
;; The climbing loop stays per-language because the two canaries use
;; opposite conventions (Lua: higher prec = tighter; Prolog: lower prec =
;; tighter, with xfx/xfy/yfx assoc tags). Forcing a single loop adds
;; callback indirection that obscures more than it shares.
;;
;; What IS shared and gets extracted: the operator-table format and lookup.
;; "Grammar is a dict, not hardcoded cond."
;;
;; Entry shape: (NAME PREC ASSOC).
;;   NAME   — string, the operator's source token.
;;   PREC   — integer, in the host's own convention.
;;   ASSOC  — :left | :right | :none for languages with traditional
;;            associativity, or "xfx" / "xfy" / "yfx" for Prolog-style.

(define
  pratt-op-lookup
  (fn (table name)
    (cond
      ((empty? table) nil)
      ((= (first (first table)) name) (first table))
      (:else (pratt-op-lookup (rest table) name)))))

(define pratt-op-name  (fn (entry) (first entry)))
(define pratt-op-prec  (fn (entry) (nth entry 1)))
(define pratt-op-assoc (fn (entry) (nth entry 2)))
