#lang scheme/base

;; Single assignment representation layer. This implements the name
;; handling logic in .f files, but in a simplified syntax.


;; The Forth style parser uses the threaded parser state to store
;; Forth style records instead of Scheme expressions as is done in the
;; anonymous RPN parser.

(require "../scat-tx.ss")


(define (single-next code state)
  (syntax-case code ()
    (()
     state)

    ;; add '(' to embed s-expressions
    
    ((thing . code+)
     (let ((next (lambda (state+)
                   (single-next #'code+ state+))))
       (syntax-case #'thing (quote)
         ((quote name)
          (next #`(name . #,state)))
         ((code ...)
          (next #`((code ...) . #,state)))
         (mode
          (syntax-case state ()
            ((name body . dictionary)
             (next #`((name mode #,(stx-srcloc #'name) body)
                      . dictionary))))))))))

(define (stx-srcloc stx)
  #`(list #,(syntax-source stx)
          #,(syntax-line stx)
          #,(syntax-column stx)
          #,(syntax-position stx)
          #,(syntax-span stx)))

