From b5fdb2addcfb55bf2c3d9f484ae7dda895d09bf9 Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Tue, 2 Jun 2015 11:51:32 +0200 Subject: [PATCH] Issue 4421/1: Deal sensibly with non-existent parser/location This concerns ly:parser-error and note-name->lily-string, and in consequence also display-lily-music. --- lily/lily-parser-scheme.cc | 25 ++++++++++++++++++------- scm/define-music-display-methods.scm | 9 +++++---- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/lily/lily-parser-scheme.cc b/lily/lily-parser-scheme.cc index 6e706f29f7..b9e0407d46 100644 --- a/lily/lily-parser-scheme.cc +++ b/lily/lily-parser-scheme.cc @@ -291,21 +291,32 @@ LY_DEFINE (ly_parser_output_name, "ly:parser-output-name", LY_DEFINE (ly_parser_error, "ly:parser-error", 2, 1, 0, (SCM parser, SCM msg, SCM input), - "Display an error message and make the parser fail.") + "Display an error message and make the parser fail." + " When @var{parser} is @code{##f}, raise a suitable other error.") { - LY_ASSERT_SMOB (Lily_parser, parser, 1); + if (scm_is_true (parser)) + LY_ASSERT_SMOB (Lily_parser, parser, 1); Lily_parser *p = unsmob (parser); LY_ASSERT_TYPE (scm_is_string, msg, 2); string s = ly_scm2string (msg); Input *i = unsmob (input); - if (i) - p->parser_error (*i, s); + if (p) + { + if (i) + p->parser_error (*i, s); + else + p->parser_error (s); + } else - p->parser_error (s); - - return parser; + { + if (i) + i->non_fatal_error (s); + else + scm_misc_error ("ly:parser-error", "~A", scm_list_1 (msg)); + } + return SCM_UNSPECIFIED; } LY_DEFINE (ly_parser_clear_error, "ly:parser-clear-error", diff --git a/scm/define-music-display-methods.scm b/scm/define-music-display-methods.scm index 2d2a178857..e2412367b8 100644 --- a/scm/define-music-display-methods.scm +++ b/scm/define-music-display-methods.scm @@ -89,10 +89,11 @@ expression." (define (pitch= pitch1 pitch2) (and (= (ly:pitch-notename pitch1) (ly:pitch-notename pitch2)) (= (ly:pitch-alteration pitch1) (ly:pitch-alteration pitch2)))) - (let ((result (rassoc ly-pitch (ly:parser-lookup parser 'pitchnames) pitch=))) - (if result - (car result) - #f))) + (let* ((pitches (if parser (ly:parser-lookup parser 'pitchnames) + (assoc-get (string->symbol default-language) + language-pitch-names '()))) + (result (rassoc ly-pitch pitches pitch=))) + (and result (car result)))) (define-public (octave->lily-string pitch) (let ((octave (ly:pitch-octave pitch))) -- 2.39.5