2014-09-03 18:48:37 +02:00
|
|
|
#|
|
|
|
|
This file is a part of LASS
|
|
|
|
(c) 2014 TymoonNET/NexT http://tymoon.eu (shinmera@tymoon.eu)
|
|
|
|
Author: Nicolas Hafner <shinmera@tymoon.eu>
|
|
|
|
|#
|
|
|
|
|
|
|
|
(in-package #:org.tymoonnext.lass)
|
|
|
|
|
|
|
|
(defvar *pretty* T)
|
2014-09-03 20:18:34 +02:00
|
|
|
(defvar *indent-level* 0)
|
2014-09-03 18:48:37 +02:00
|
|
|
|
2014-09-05 10:48:27 +02:00
|
|
|
;; SHEET ::= (BLOCK*)
|
|
|
|
;; BLOCK ::= (:BLOCK SELECTOR PROPERTY*)
|
|
|
|
;; SELECTOR ::= (string*)
|
|
|
|
;; PROPERTY ::= (:PROPERTY string string)
|
2014-09-03 18:48:37 +02:00
|
|
|
|
2014-09-03 20:18:34 +02:00
|
|
|
(defun indent ()
|
|
|
|
(make-string (if *pretty* *indent-level* 0) :initial-element #\Space))
|
|
|
|
|
|
|
|
(defgeneric write-sheet-object (type object stream)
|
|
|
|
(:method ((type (eql :block)) block stream)
|
|
|
|
(when (and block (cdr block))
|
|
|
|
(let ((true-format (format NIL "~a~~{~~a~~^,~@[~* ~]~~}{~:*~@[~*~%~]~~{~~/lass::write-sheet-part/~~^~:*~@[~*~%~]~~}~:*~@[~*~%~]~:*~:*~a~*}"
|
|
|
|
(indent) *pretty*))
|
|
|
|
(*indent-level* (+ *indent-level* 4)))
|
|
|
|
(format stream true-format
|
|
|
|
(car block) (cdr block)))))
|
2014-09-05 10:48:27 +02:00
|
|
|
(:method ((type (eql :property)) attribute stream)
|
2014-09-03 20:18:34 +02:00
|
|
|
(when attribute
|
|
|
|
(format stream (format NIL "~a~~a~~@[:~@[~* ~]~~a~~];" (indent) *pretty*)
|
|
|
|
(first attribute) (second attribute)))))
|
2014-09-03 18:48:37 +02:00
|
|
|
|
2014-09-03 20:18:34 +02:00
|
|
|
(defun write-sheet-part (stream block cp ap)
|
2014-09-03 18:48:37 +02:00
|
|
|
(declare (ignore cp ap))
|
2014-09-03 20:18:34 +02:00
|
|
|
(write-sheet-object (car block) (cdr block) stream))
|
2014-09-03 18:48:37 +02:00
|
|
|
|
|
|
|
(defun write-sheet (sheet &key (stream T) (pretty *pretty*))
|
|
|
|
(let ((*pretty* pretty))
|
2014-09-03 20:18:34 +02:00
|
|
|
(format stream (format NIL "~~{~~/lass::write-sheet-part/~~^~@[~*~%~%~]~~}" pretty) sheet)))
|