From 008c8d9efeee79db584b3a7a39bb5cf03ebfb646 Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Sun, 9 Dec 2007 05:53:04 +0000 Subject: [PATCH] Change indentation style to put open paren inline, contents indented, and close paren unindented. Change indentation increment from 2 to 4. Generate optional trailing ";" in bnodes and "." in subgraphs. Don't automatically indent multiple objects; instead try to break lines where needed. Add space after an unquoted literal, to prevent confusion should it be followed by ".". --- v7/src/xml/turtle.scm | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/v7/src/xml/turtle.scm b/v7/src/xml/turtle.scm index 29165cdb2..07998fbc4 100644 --- a/v7/src/xml/turtle.scm +++ b/v7/src/xml/turtle.scm @@ -1,6 +1,6 @@ #| -*-Scheme-*- -$Id: turtle.scm,v 1.39 2007/12/09 05:09:27 cph Exp $ +$Id: turtle.scm,v 1.40 2007/12/09 05:53:04 cph Exp $ Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, @@ -808,7 +808,7 @@ USA. (begin (space port) (writer port)) - (let ((indentation (indent+ indentation))) + (begin (write-object (car os) indentation inline-bnode port) (for-each (lambda (o) (write-string "," port) @@ -816,7 +816,7 @@ USA. (cdr os))))))) (define (write-object o indentation inline-bnode port) - (write-indentation indentation port) + (maybe-break indentation port) (cond ((linear-object-writer o inline-bnode) => (lambda (writer) (writer port))) @@ -827,6 +827,7 @@ USA. (write-parens "(" ")" indentation port (lambda (indentation) (for-each (lambda (o) + (maybe-break indentation port) (write-object o indentation inline-bnode port)) os))))) ((inline-bnode o) @@ -841,7 +842,14 @@ USA. (write-pgroups (group-triples ts rdf-triple-predicate) indentation inline-bnode - port)))) + port) + (write-string ";" port)))) + +(define (maybe-break indentation port) + (if (> (or (output-port/column port) 0) + (- (output-port/x-size port) 10)) + (write-indentation (indent+ indentation) port) + (space port))) (define (write-subject s indentation inline-bnode port) (cond ((uri? s) @@ -867,13 +875,11 @@ USA. (define (write-graph graph indentation inline-bnode port) (write-parens "{" "}" indentation port (lambda (indentation) - (do ((groups (groups-to-write (rdf-graph-triples graph) inline-bnode) - (cdr groups))) - ((not (pair? groups))) - (write-indentation indentation port) - (write-group (car groups) indentation inline-bnode port) - (if (pair? (cdr groups)) - (write-string "." port)))))) + (for-each (lambda (group) + (write-indentation indentation port) + (write-group group indentation inline-bnode port) + (write-string "." port)) + (groups-to-write (rdf-graph-triples graph) inline-bnode))))) (define (write-predicate p port) (if (eq? p rdf:type) @@ -888,7 +894,9 @@ USA. (eq? type xsd:decimal) (eq? type xsd:double) (eq? type xsd:integer))) - (write-string text port) + (begin + (write-string text port) + (space port)) (begin (write-literal-text text port) (cond ((rdf-literal-type literal) @@ -1010,7 +1018,7 @@ USA. (loop (- indentation 1)))))) (define (indent+ indentation) - (+ indentation 2)) + (+ indentation 4)) (define (classify-list items n-classes classifier) (let ((classes (make-vector n-classes '()))) -- 2.25.1