css.ss
(module css mzscheme

  (require "private/require.ss")
  (require-contracts)
  (require-parameters)

  ;; text/c : FlatContract
  ;; Recognizes text fields in CSS.
  (define text/c (or/c symbol? string?))

  ;; css/c : FlatContract
  ;; Recognizes representations of Cascading Style Sheets.
  (define css/c (listof (cons/c text/c (listof (list/c text/c text/c)))))

  (provide/contract
   [css/c flat-contract?]
   [css? predicate/c]
   [write-css ([css/c] [output-port?] . opt-> . void?)])

  ;; A Cascading Style Sheet (CSS) is a (Listof StyleDefn)
  ;; A Style Definition (StyleDefn) is a (cons Selectors (Listof PropDefn))
  ;; A Selectors is a Selector or a (NonEmptyListof Selector)
  ;; A Selector is a Symbol or String
  ;; A Property Definition (PropDefn) is a (list PropName PropVal)
  ;; A Property Name (PropName) is a Symbol or String
  ;; A Property Value (PropVal) is a Symbol or String

  ;; css? : Any -> Boolean
  ;; Reports whether a value is a CSS.
  (define css? (predicate-of css/c))

  ;; write-css : CSS [OutputPort] -> Void
  ;; Writes a CSS datastructure as a proper text Cascading Style Sheet.
  (define write-css
    (param-lambda (css [output => current-output-port])
      (for-each write-style-defn css)))

  ;; write-style-defn : StyleDefn [OutputPort] -> Void
  ;; Writes a style definition to a Cascading Style Sheet.
  (define write-style-defn
    (param-lambda (style-defn [output => current-output-port])
      (write-selector (car style-defn))
      (display " {")
      (for-each write-prop-defn (cdr style-defn))
      (display " }\n")))

  ;; write-text : Text [OutputPort] -> Void
  ;; Writes a text field to a Cascading Style Sheet.
  (define write-text display)

  ;; write-selector : Selector [OutputPort] -> Void
  ;; Writes a selector to a Cascading Style Sheet.
  (define write-selector write-text)

  ;; write-prop-defn : PropDefn [OutputPort] -> Void
  ;; Writes a property definition to a Cascading Style Sheet.
  (define write-prop-defn
    (param-lambda (prop-defn [output => current-output-port])
      (display " ")
      (write-prop-name (car prop-defn))
      (display " : ")
      (write-prop-val (cadr prop-defn))
      (display ";")))

  ;; write-prop-name : PropName [OutputPort] -> Void
  ;; Writes a property name to a Cascading Style Sheet.
  (define write-prop-name write-text)

  ;; write-prop-val : PropVal [OutputPort] -> Void
  ;; Writes a property value to a Cascading Style Sheet.
  (define write-prop-val write-text)

  )