On Thu, Oct 21, 2010 at 4:53 AM, <[email protected]> wrote: Hi Carl,
> I like this idea as a way to get the functionality you want in the short > term. But I don't like it for the long term. I think the long-term > syntax needs to be > > \language "foobar" > > so that we don't have a separate keyword for each language. As you > point out, that will require a parser change. WRONG!!!! (breathe, breathe) So I thought, but here's a way to do it anyway: see attached patch. It's so friggin' ridiculously simple that I didn't even bothered uploading it to codereview. ... Actually, I think I'm in love with it. Now, here's what I want you guys to do: put your fingers on your keyboard, more precisely on the following keys: L, G, T, and M. Then press these four keys, and hit "Send". Pretty please? Cheers, Valentin
From e61c8a21d6ce4cae4e516b048687b95966c70bc4 Mon Sep 17 00:00:00 2001 From: Valentin Villenave <[email protected]> Date: Sat, 23 Oct 2010 22:26:43 +0200 Subject: [PATCH] Fix #903: a simpler syntax for note names language This commit adds a new \language "foo" command, where "foo" is the (case-insensitive) name of any supported language, e.g. "italiano", "suomi" etc. This function may be used at top-level or anywhere else, even in -dsafe mode. Non-supported languages arguments are, well, not supported: if no recognizable string is provided, ly:gulp-file will just barf its standard error message. To preserve full compatibility with existing code, this patch leaves .ly language files unchanged (therefore, the old syntax is still perfectly valid). Since all it does is extract the pitchnames alist from whatever file it processes, more complex files such as "arabic.ly" are not supported. In spite of this limitation, this method is a convenient way of presenting foreign users with a simplified syntax, without having to bloat the parser with yet another keyword. Of course, it may be superseeded in the future with a more specialized implementation, possibly doing away with .ly files (if we reach a point where preserving compatibility is no longer an issue). --- ly/music-functions-init.ly | 29 +++++++++++++++++++++++++++-- 1 files changed, 27 insertions(+), 2 deletions(-) diff --git a/ly/music-functions-init.ly b/ly/music-functions-init.ly index 8ac1ded..3302d79 100644 --- a/ly/music-functions-init.ly +++ b/ly/music-functions-init.ly @@ -25,9 +25,12 @@ %% this file is alphabetically sorted. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% need SRFI-1 for filter; optargs for lambda* +%% need SRFI-1 for filter; +%% optargs for lambda*; +%% regex for string-match #(use-modules (srfi srfi-1) - (ice-9 optargs)) + (ice-9 optargs) + (ice-9 regex)) %% TODO: using define-music-function in a .scm causes crash. @@ -360,6 +363,28 @@ label = 'page-label label)))) +language = +#(define-music-function (parser location str) (string?) + (_i "Select note-names language.") + ;; This function is a hack around the old language + ;; selection system, using separate .ly files for each + ;; supported languages. + ;; TODO: re-implement language selection in a cleaner way. + (let* ((file-name (string-append (string-downcase! str) ".ly")) + + ; Ugh. ly:gulp-file's "file not found" error message + ; won't be much informative in this specific case. + (raw-string (ly:gulp-file file-name)) + + ; extract the pitchnames alist. + (delim-alist (string-match "`\\(.*\\)\\)\\s[ |\n]?\\)" raw-string )) + (extract-alist (match:substring delim-alist))) + + (if (ly:get-option 'verbose) + (ly:message (_ "Using ~a note names...") str)) + (ly:parser-set-note-names parser (eval-string extract-alist)) + make-void-music)) + makeClusters = #(define-music-function (parser location arg) (ly:music?) -- 1.7.3.1
_______________________________________________ lilypond-devel mailing list [email protected] http://lists.gnu.org/mailman/listinfo/lilypond-devel
