summaryrefslogtreecommitdiff
path: root/scm
diff options
context:
space:
mode:
authorThomas Morley <thomasmorley65@gmail.com>2015-08-23 15:24:06 +0200
committerThomas Morley <thomasmorley65@gmail.com>2015-09-05 11:35:59 +0200
commite2e1656c9d0897fb45a215bdcb96b146100c33e2 (patch)
treec648aa88afa13ce8d9955da232dc07c51b7491dc /scm
parent5b30a1793b07afeeed877ce97471e6a4a0d69169 (diff)
Clear fret-diagram- and harp-pedal-input-strings from whitespace
issue 4575 Whitespace-characters are deleted before further processing. Allows for \markup \fret-diagram #"s:2;h:5; 6-3;5-5;4-5;3-4;2-3;1-x;" Also adding errors for typos in fret-diagram with a meaningful message: \markup \fret-diagram #"s:2;g:r; 6-3;5-5;4-5;3-4;2-3;1-x;" will return: fatal error: Unhandled entry in fret-diagram "g:r" in "g:r" This error would not apply, if something for #\g would be defined in fret-parse-definition-string somewhere in the future. Then, the message would be: fatal error: Unhandled entry in fret-diagram "r" in "g:r" Something similiar is already in harp-pedals.scm
Diffstat (limited to 'scm')
-rw-r--r--scm/fret-diagrams.scm34
-rw-r--r--scm/harp-pedals.scm3
-rw-r--r--scm/lily-library.scm6
3 files changed, 36 insertions, 7 deletions
diff --git a/scm/fret-diagrams.scm b/scm/fret-diagrams.scm
index 041d180c04..85cfbb9b36 100644
--- a/scm/fret-diagrams.scm
+++ b/scm/fret-diagrams.scm
@@ -44,7 +44,15 @@ to end-point."
(define (get-numeric-from-key keystring)
"Get the numeric value from a key of the form k:val"
- (string->number (substring keystring 2 (string-length keystring))))
+ (let* ((entry (substring keystring 2 (string-length keystring)))
+ (numeric-entry (string->number entry)))
+ ;; throw an error, if `entry' can't be transformed into a number
+ (if numeric-entry
+ numeric-entry
+ (ly:error
+ "Unhandled entry in fret-diagram \"~a\" in \"~a\""
+ entry
+ keystring))))
(define (numerify mylist)
"Convert string values to numeric or character"
@@ -245,7 +253,11 @@ with magnification @var{mag} of the string @var{text}."
((or (eq? my-code 'open)(eq? my-code 'mute))
(set! xo-list (cons* my-item xo-list)))
((eq? my-code 'barre)
- (set! barre-list (cons* (cdr my-item) barre-list)))
+ (if (every number? (cdr my-item))
+ (set! barre-list (cons* (cdr my-item) barre-list))
+ (ly:error
+ "barre-indications should contain only numbers: ~a"
+ (cdr my-item))))
((eq? my-code 'capo)
(set! capo-fret (cadr my-item)))
((eq? my-code 'place-fret)
@@ -923,7 +935,9 @@ a fret-indication list with the appropriate values"
(output-list '())
(new-props '())
(details (merge-details 'fret-diagram-details props '()))
- (items (string-split definition-string #\;)))
+ ;; remove whitespace-characters from definition-string
+ (cleared-string (remove-whitespace definition-string))
+ (items (string-split cleared-string #\;)))
(let parse-item ((myitems items))
(if (not (null? (cdr myitems)))
(let ((test-string (car myitems)))
@@ -959,7 +973,15 @@ a fret-indication list with the appropriate values"
(set! details
(acons 'dot-position dot-position details))))
(else
- (let ((this-list (string-split test-string #\-)))
+ (let* ((this-list (string-split test-string #\-))
+ (fret-number (string->number (car this-list))))
+ ;; If none of the above applies, `fret-number' needs to be a
+ ;; number. Throw an error, if not.
+ (if (not fret-number)
+ (ly:error
+ "Unhandled entry in fret-diagrams \"~a\" in \"~a\""
+ (car this-list)
+ test-string))
(if (string->number (cadr this-list))
(set! output-list
(cons-fret
@@ -968,11 +990,11 @@ a fret-indication list with the appropriate values"
(if (equal? (cadr this-list) "x" )
(set! output-list
(cons-fret
- (list 'mute (string->number (car this-list)))
+ (list 'mute fret-number)
output-list))
(set! output-list
(cons-fret
- (list 'open (string->number (car this-list)))
+ (list 'open fret-number)
output-list)))))))
(parse-item (cdr myitems)))))
;; add the modified details
diff --git a/scm/harp-pedals.scm b/scm/harp-pedals.scm
index a6c93774d3..9365f0a034 100644
--- a/scm/harp-pedals.scm
+++ b/scm/harp-pedals.scm
@@ -132,6 +132,7 @@ spacing after the divider).
stencils)))
;; Parse the harp pedal definition string into list of directions (-1/0/1), #\o and #\|
+;; Whitespace is removed from definition string before the procedure applies.
(define (harp-pedals-parse-string definition-string)
"Parse a harp pedals diagram string and return a list containing 1, 0, -1, #\\o or #\\|"
(map (lambda (c)
@@ -141,7 +142,7 @@ spacing after the divider).
((#\-) 0)
((#\| #\o) c)
(else c)))
- (string->list definition-string)))
+ (string->list (remove-whitespace definition-string))))
;; Analyze the pedal-list: Return (pedalcount . (divider positions))
diff --git a/scm/lily-library.scm b/scm/lily-library.scm
index 2270726902..c5bf8cc59d 100644
--- a/scm/lily-library.scm
+++ b/scm/lily-library.scm
@@ -786,6 +786,12 @@ as rectangular coordinates @ode{(x-length . y-length)}."
(define-public (string-startswith s prefix)
(equal? prefix (substring s 0 (min (string-length s) (string-length prefix)))))
+(define-public (remove-whitespace strg)
+"Remove characters satisfying @code{char-whitespace?} from string @var{strg}"
+ (string-delete
+ strg
+ char-whitespace?))
+
(define-public (string-encode-integer i)
(cond
((= i 0) "o")