git » blacktide.git » master » tree

[master] / test / com / tailrecursion / nanopass / fixtures.clj

(ns com.tailrecursion.nanopass.fixtures
  "Small languages exercising recursive derivation without a compiler client."
  (:require [com.tailrecursion.nanopass :as np]
            [typed.clojure :as-alias t]))

(np/deflanguage Source
  {Expr (t/U (t/HMap :mandatory {:op ':literal :value t/Any} :complete? true)
             (t/HMap :mandatory {:op ':read :name t/Sym} :complete? true)
             (t/HMap :mandatory {:op ':assign :binding Binding :value Expr} :complete? true)
             (t/HMap :mandatory {:op ':group :bindings (t/Vec Binding) :body Expr} :complete? true)
             (t/HMap :mandatory {:op ':many :items (t/Map t/Keyword (t/Vec Expr))
                                 :pair (t/HVec [Expr (t/Option Expr)]) :unique (t/Set Expr)}
                     :optional {:note t/Str :child Expr :maybe (t/Option Expr)} :complete? true))
   Binding (t/HMap :mandatory {:op ':binding :name t/Sym :value Expr} :complete? true)
   Envelope (t/HMap :optional {:child Expr :maybe (t/Option Expr)} :complete? true)})

(np/derive-language Core Source
  {:remove {Expr #{:assign}}
   :add {Expr [(t/HMap :mandatory {:op ':write :name t/Sym :value Expr} :complete? true)]}})

(np/derive-language Literals Core
  {:replace {Expr (t/HMap :mandatory {:op ':literal :value t/Any} :complete? true)}})

(np/deflanguage Mutual
  {A (t/HMap :mandatory {:op ':a :next (t/Option B)} :complete? true)
   B (t/HMap :mandatory {:op ':b :next (t/Option A)} :complete? true)})

(np/derive-language Stopped Mutual
  {:replace {B (t/HMap :mandatory {:op ':stop} :complete? true)}})