From 009077224499a8da26314177ca8e94b1600050a5 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Mon, 23 Jan 2023 00:07:14 +0000 Subject: skribilo: Add skribilo fragment document. * tissue/skribilo.scm: New file. --- tissue/skribilo.scm | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 tissue/skribilo.scm (limited to 'tissue') diff --git a/tissue/skribilo.scm b/tissue/skribilo.scm new file mode 100644 index 0000000..4a216d3 --- /dev/null +++ b/tissue/skribilo.scm @@ -0,0 +1,97 @@ +;;; tissue --- Text based issue tracker +;;; Copyright © 2023 Arun Isaac +;;; +;;; This file is part of tissue. +;;; +;;; tissue is free software: you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation, either version 3 of the License, or +;;; (at your option) any later version. +;;; +;;; tissue is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with tissue. If not, see . + +(define-module (tissue skribilo) + #:use-module (rnrs conditions) + #:use-module (rnrs exceptions) + #:use-module (srfi srfi-26) + #:use-module (ice-9 match) + #:use-module (oop goops) + #:use-module (skribilo ast) + #:use-module (skribilo evaluator) + #:use-module (skribilo reader) + #:use-module (tissue document) + #:use-module (tissue file-document) + #:use-module (tissue utils) + #:export ( + skribilo-fragment-filename + skribilo-fragment-identifier + document-fragment)) + +(define-class () + (identifier #:getter skribilo-fragment-identifier #:init-keyword #:identifier) + (reader-name #:getter skribilo-fragment-reader-name #:init-keyword #:reader-name)) + +(define (document-node file identifier reader-name) + "Return @code{} object describing node identified by +@var{identifier} in @var{file} read using reader named by +@var{reader-name}." + (find1-down (lambda (node) + (and (is-a? node ) + (string=? (markup-ident node) identifier))) + (call-with-input-file file + (cut evaluate-ast-from-port <> #:reader (make-reader reader-name))))) + +(define* (document-fragment file identifier #:key (reader-name 'skribe)) + "Return a @code{} object describing node identified +by @var{identifier} in @var{file} read using reader named by +@var{reader-name}." + (make + #:title (ast->string + (markup-option (document-node file identifier reader-name) + #:title)) + #:path file + #:commits (commits-affecting-file file) + #:identifier identifier + #:reader-name reader-name)) + +(define-method (document-id-term (fragment )) + "Return the ID term for skribilo @var{fragment}." + (string-append "Qskribilofragment." + (file-document-path fragment) + "#" + (skribilo-fragment-identifier fragment))) + +(define (ast->text node port) + "Serialize AST @var{node} into text suitable for indexing. Write +output to @var{port}." + (cond + ((is-a? node ) + (for-each (match-lambda + ((_ . value) + (display (ast->string value) port))) + (node-options node)) + (newline port) + (ast->text (node-body node) port)) + ((string? node) + (display node port)) + ((number? node) + (display (number->string node) port)) + ((list? node) + (for-each (lambda (element) + (ast->text element port) port) + node)))) + +(define-method (document-text (fragment )) + "Return the full text of skribilo @var{fragment}." + (call-with-output-string + (cut ast->text + (document-node (file-document-path fragment) + (skribilo-fragment-identifier fragment) + (skribilo-fragment-reader-name fragment)) + <>))) -- cgit v1.2.3