mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
[eguile] compact eguile processor
eradicate set! calls, inline strings, neater code. also fix missing-regex message.
This commit is contained in:
parent
0a15909d5e
commit
a107382bd7
@ -103,14 +103,6 @@
|
||||
(define startre (and (defined? 'make-regexp) (make-regexp "<\\?scm(:d)?[[:space:]]")))
|
||||
(define endre (and (defined? 'make-regexp) (make-regexp "(^|[[:space:]])\\?>")))
|
||||
|
||||
;; Guile code to mark starting and stopping text or code modes
|
||||
(define textstart "(display \"")
|
||||
(define textstop "\")")
|
||||
(define codestart "")
|
||||
(define codestop "")
|
||||
(define dcodestart "(display ")
|
||||
(define dcodestop ")")
|
||||
|
||||
;; Parse a template, and return a sequence of s-expressions
|
||||
;; e.g. "Text <?scm:d (+ x 2) ?>." -> (display "Text ")(display (+ x 2))(display ".")
|
||||
(define (template->script)
|
||||
@ -129,43 +121,28 @@
|
||||
(display t)
|
||||
(display-text t)))
|
||||
|
||||
(define stop textstop) ; text to output at end of current section
|
||||
|
||||
;; switch between code and text modes
|
||||
(define (switch-mode code? dmodifier?)
|
||||
(display stop)
|
||||
(cond
|
||||
(code? (display textstart)
|
||||
(set! stop textstop))
|
||||
(dmodifier? (display dcodestart)
|
||||
(set! stop dcodestop))
|
||||
(else (display codestart)
|
||||
(set! stop codestop))))
|
||||
|
||||
;; recursively process input stream
|
||||
(define (loop inp needle other code? line)
|
||||
(when (string-null? line)
|
||||
(set! line (read-line inp 'concat)))
|
||||
(unless (eof-object? line)
|
||||
(cond
|
||||
((regexp-exec needle line)
|
||||
=> (lambda (rmatch)
|
||||
(let ((dmodifier? #f))
|
||||
(display-it (match:prefix rmatch) code?)
|
||||
(unless code?
|
||||
;; switching from text to code -- check for modifier
|
||||
(set! dmodifier? (match:substring rmatch 1)))
|
||||
(switch-mode code? dmodifier?)
|
||||
(loop inp other needle (not code?) (match:suffix rmatch)))))
|
||||
(else ; no match - output whole line and continue
|
||||
(display-it line code?)
|
||||
(loop inp needle other code? "")))))
|
||||
(define (loop inp needle other code? line stop)
|
||||
(cond
|
||||
((eof-object? line) (display stop))
|
||||
((string-null? line) (loop inp needle other code? (read-line inp 'concat) stop))
|
||||
((regexp-exec needle line) =>
|
||||
(lambda (rmatch)
|
||||
(display-it (match:prefix rmatch) code?)
|
||||
(display stop)
|
||||
(loop inp other needle (not code?) (match:suffix rmatch)
|
||||
(cond
|
||||
(code? (display "(display \"") "\")")
|
||||
((match:substring rmatch 1) (display "(display ") ")")
|
||||
(else (display "") "")))))
|
||||
(else
|
||||
(display-it line code?)
|
||||
(loop inp needle other code? "" stop))))
|
||||
|
||||
(display textstart)
|
||||
(display "(display \"")
|
||||
(if (defined? 'make-regexp)
|
||||
(loop (current-input-port) startre endre #f "")
|
||||
(display "eguile requires guile with regex."))
|
||||
(display stop))
|
||||
(loop (current-input-port) startre endre #f "" "\")")
|
||||
(display "eguile requires guile with regex.\")")))
|
||||
|
||||
;end of (template->script)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user