[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: music-functions: problem with -\tag
From: |
Nicolas Sceaux |
Subject: |
Re: music-functions: problem with -\tag |
Date: |
Fri, 14 May 2004 23:58:04 +0200 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) |
Fri, 14 May 2004 12:21:47 +0200, Nicolas a dit :
> Hello,
> While working on ly/music-functions-init.ly, I had a little problem
> with the \tag keyword, when occuring after a '-':
> c1-\mytag #'part ^4
> the parser complains:
> /home/nicolas/lilypond-cvs/dev/tag-filter.ly:28:12: Erreur: syntax error,
> unexpected MUSIC_FUNCTION_SCM_MUSIC:
> c1-\myta
> g #'part ^4
> I am not sure where/how to change the parser so that scheme music
> functions could be accepted at that place. Perhaps in the 'post_event'
> rule?
hm, my attempts introduce 39 shift/reduce conflicts... I don't see how
to do that. If someone want to look at it and try, here is a patch of
what I have done so far with ly:make-music-function.
Index: lily/lexer.ll
===================================================================
RCS file: /cvsroot/lilypond/lilypond/lily/lexer.ll,v
retrieving revision 1.135
diff -u -r1.135 lexer.ll
--- lily/lexer.ll 6 May 2004 22:16:16 -0000 1.135
+++ lily/lexer.ll 14 May 2004 21:48:11 -0000
@@ -917,6 +917,10 @@
{
return MUSIC_FUNCTION_SCM_SCM_MUSIC;
}
+ else if (type == ly_symbol2scm ("noarg"))
+ {
+ return MUSIC_FUNCTION;
+ }
else
{
/* TODO: print location */
Index: lily/music-function.cc
===================================================================
RCS file: /cvsroot/lilypond/lilypond/lily/music-function.cc,v
retrieving revision 1.2
diff -u -r1.2 music-function.cc
--- lily/music-function.cc 7 May 2004 09:16:09 -0000 1.2
+++ lily/music-function.cc 14 May 2004 21:48:23 -0000
@@ -45,7 +45,7 @@
else if (ly_c_procedure_p (ly_car (s)))
str += "scm";
}
-
+ if (str == "") str = "noarg";
scm_set_object_property_x (func, ly_symbol2scm ("music-function-signature"),
signature);
Index: lily/my-lily-lexer.cc
===================================================================
RCS file: /cvsroot/lilypond/lilypond/lily/my-lily-lexer.cc,v
retrieving revision 1.178
diff -u -r1.178 my-lily-lexer.cc
--- lily/my-lily-lexer.cc 9 May 2004 11:15:48 -0000 1.178
+++ lily/my-lily-lexer.cc 14 May 2004 21:48:23 -0000
@@ -25,19 +25,12 @@
static Keyword_ent the_key_tab[] = {
- {"acciaccatura", ACCIACCATURA},
{"accepts", ACCEPTS},
- {"addlyrics", ADDLYRICS},
{"addquote", ADDQUOTE},
{"alias", ALIAS},
{"alternative", ALTERNATIVE},
- {"applycontext", APPLYCONTEXT},
- {"applyoutput", APPLYOUTPUT},
- {"appoggiatura", APPOGGIATURA},
- {"autochange", AUTOCHANGE},
{"bar", BAR},
{"book", BOOK},
- {"breathe", BREATHE},
{"change", CHANGE},
{"chords", CHORDS},
{"clef", CLEF},
@@ -49,7 +42,6 @@
{"drums", DRUMS},
{"description", DESCRIPTION},
{"figures",FIGURES},
- {"grace", GRACE},
{"grobdescriptions", GROBDESCRIPTIONS},
{"header", HEADER},
{"key", KEY},
@@ -66,7 +58,6 @@
{"once", ONCE},
{"override", OVERRIDE},
{"paper", PAPER},
- {"partcombine", PARTCOMBINE},
{"partial", PARTIAL},
{"quote", QUOTE},
{"relative", RELATIVE},
Index: lily/parser.yy
===================================================================
RCS file: /cvsroot/lilypond/lilypond/lily/parser.yy,v
retrieving revision 1.383
diff -u -r1.383 parser.yy
--- lily/parser.yy 14 May 2004 06:49:52 -0000 1.383
+++ lily/parser.yy 14 May 2004 21:48:23 -0000
@@ -242,17 +242,12 @@
%pure_parser
%token ACCEPTS
-%token ADDLYRICS
%token ADDQUOTE
%token LYRICSTO
%token ALIAS
%token ALTERNATIVE
-%token APPLYCONTEXT
-%token APPLYOUTPUT
-%token AUTOCHANGE
%token BAR
%token BOOK
-%token BREATHE
%token CHANGE
%token CHORDMODIFIERS
%token CHORDS
@@ -269,9 +264,6 @@
%token EXTENDER
%token FIGURES FIGURE_OPEN FIGURE_CLOSE
%token FIGURE_BRACKET_CLOSE FIGURE_BRACKET_OPEN
-%token GRACE
-%token ACCIACCATURA
-%token APPOGGIATURA
%token GROBDESCRIPTIONS
%token HEADER
%token HYPHEN
@@ -289,7 +281,6 @@
%token ONCE
%token OVERRIDE SET REVERT
%token PAPER
-%token PARTCOMBINE
%token PARTIAL
%token QUOTE
%token RELATIVE
@@ -358,6 +349,7 @@
%token <scm> MARKUP_HEAD_SCM0_SCM1_SCM2
%token <scm> MARKUP_HEAD_SCM0_SCM1_MARKUP2
+%token <scm> MUSIC_FUNCTION
%token <scm> MUSIC_FUNCTION_SCM
%token <scm> MUSIC_FUNCTION_MUSIC
%token <scm> MUSIC_FUNCTION_SCM_MUSIC
@@ -371,7 +363,6 @@
%type <book> book_block book_body
%type <i> exclamations questions dots optional_rest
%type <i> bass_mod
-%type <scm> grace_head
%type <scm> oct_check
%type <scm> context_mod_list
%type <scm> lyric_element
@@ -911,20 +902,6 @@
Simple_music:
event_chord { $$ = $1; }
- | APPLYOUTPUT embedded_scm {
- if (!ly_input_procedure_p ($2))
- THIS->parser_error (_ ("\\applycontext takes function
argument"));
- $$ = MY_MAKE_MUSIC ("ApplyOutputEvent");
- $$->set_property ("procedure", $2);
- $$->set_spot (THIS->here_input ());
- }
- | APPLYCONTEXT embedded_scm {
- if (!ly_input_procedure_p ($2))
- THIS->parser_error (_ ("\\applycontext takes function
argument"));
- $$ = MY_MAKE_MUSIC ("ApplyContext");
- $$->set_property ("procedure", $2);
- $$->set_spot (THIS->here_input ());
- }
| MUSIC_IDENTIFIER {
$$ = unsmob_music ($1);
}
@@ -943,12 +920,6 @@
}
;
-grace_head:
- GRACE { $$ = scm_makfrom0str ("Grace"); }
- | ACCIACCATURA { $$ = scm_makfrom0str ("Acciaccatura"); }
- | APPOGGIATURA { $$ = scm_makfrom0str ("Appoggiatura"); }
- ;
-
context_mod_list:
/* */ { $$ = SCM_EOL; }
| context_mod_list context_mod {
@@ -968,7 +939,10 @@
;
Generic_prefix_music_scm:
- MUSIC_FUNCTION_SCM {
+ MUSIC_FUNCTION {
+ $$ = scm_list_2 ($1, make_input (THIS->here_input ()));
+ }
+ | MUSIC_FUNCTION_SCM {
THIS->push_spot ();
} embedded_scm {
$$ = scm_list_3 ($1, make_input (THIS->pop_spot ()), $3);
@@ -1044,76 +1018,6 @@
Generic_prefix_music {
$$ = $1;
}
- |AUTOCHANGE Music {
- SCM proc = ly_scheme_function ("make-autochange-music");
-
- SCM res = scm_call_1 (proc, $2->self_scm ());
- scm_gc_unprotect_object ($2->self_scm ());
- $$ = unsmob_music (res);
- scm_gc_protect_object (res);
- $$->set_spot (THIS->here_input ());
- }
- | PARTCOMBINE Music Music {
- SCM proc = ly_scheme_function ("make-part-combine-music");
-
- SCM res = scm_call_1 (proc, scm_listify ($2->self_scm (),
- $3->self_scm (), SCM_UNDEFINED));
- scm_gc_unprotect_object ($3->self_scm ());
- scm_gc_unprotect_object ($2->self_scm ());
- $$ = unsmob_music (res);
- scm_gc_protect_object (res);
- $$->set_spot (THIS->here_input ());
- }
- | grace_head Music {
-#if 1
- /*
- The other version is for easier debugging of
- Sequential_music_iterator in combination with grace notes.
- */
-
-/*
-
-TODO: should distinguish between both grace types in the
-basic music objects too, since the meaning is different.
-
-*/
-
- String start_str = "start" + ly_scm2string ($1) + "Music";
- String stop_str = "stop" + ly_scm2string ($1) + "Music";
-
- SCM start = THIS->lexer_->lookup_identifier (start_str);
- SCM stop = THIS->lexer_->lookup_identifier (stop_str);
-
- Music *startm = unsmob_music (start);
- Music *stopm = unsmob_music (stop);
-
- SCM ms = SCM_EOL;
- if (stopm) {
- stopm = stopm->clone ();
- ms = scm_cons (stopm->self_scm (), ms);
- scm_gc_unprotect_object (stopm->self_scm ());
- }
- ms = scm_cons ($2->self_scm (), ms);
- scm_gc_unprotect_object ($2->self_scm ());
- if (startm) {
- startm = startm->clone ();
- ms = scm_cons (startm->self_scm (), ms);
- scm_gc_unprotect_object (startm->self_scm ());
- }
-
- Music* seq = MY_MAKE_MUSIC ("SequentialMusic");
- seq->set_property ("elements", ms);
-
-
- $$ = MY_MAKE_MUSIC ("GraceMusic");
- $$->set_property ("element", seq->self_scm ());
- scm_gc_unprotect_object (seq->self_scm ());
-#else
- $$ = MY_MAKE_MUSIC ("GraceMusic");
- $$->set_property ("element", $2->self_scm ());
- scm_gc_unprotect_object ($2->self_scm ());
-#endif
- }
| CONTEXT simple_string '=' simple_string optional_context_mod Music {
$$ = context_spec_music ($2, $4, $6, $5);
@@ -1268,15 +1172,7 @@
;
re_rhythmed_music:
- ADDLYRICS Music Music {
- Music *m = MY_MAKE_MUSIC ("LyricCombineMusic");
- m->set_property ("elements", scm_listify ($2->self_scm (),
- $3->self_scm (), SCM_UNDEFINED));
- scm_gc_unprotect_object ($3->self_scm ());
- scm_gc_unprotect_object ($2->self_scm ());
- $$ = m;
- }
- | Grouped_music_list new_lyrics {
+ Grouped_music_list new_lyrics {
/* FIXME: should find out uniqueXXX name from music */
SCM name = $1->get_property ("context-id");
@@ -1695,10 +1591,7 @@
;
command_req:
- BREATHE {
- $$ = MY_MAKE_MUSIC ("BreathingSignEvent");
- }
- | E_TILDE {
+ E_TILDE {
$$ = MY_MAKE_MUSIC ("PesOrFlexaEvent");
}
| MARK DEFAULT {
Index: ly/music-functions-init.ly
===================================================================
RCS file: /cvsroot/lilypond/lilypond/ly/music-functions-init.ly,v
retrieving revision 1.1
diff -u -r1.1 music-functions-init.ly
--- ly/music-functions-init.ly 9 May 2004 13:06:36 -0000 1.1
+++ ly/music-functions-init.ly 14 May 2004 21:48:23 -0000
@@ -1,11 +1,60 @@
-applymusic = #(ly:make-music-function
- (list procedure? ly:music?) ; signature
- (lambda (where func music) ; the function
- (func music)))
+\version "2.3.2"
-\version "2.3.1"
+#(defmacro-public def-music-function (args signature . body)
+ "Helper macro for `ly:make-music-function'.
+Syntax:
+ (def-music-function (location arg1 arg2 ...) (arg1-type? arg2-type? ...)
+ ...function body...)
+"
+ `(ly:make-music-function (list ,@signature)
+ (lambda (,@args)
+ ,@body)))
+applymusic = #(def-music-function (location func music) (procedure? ly:music?)
+ (func music))
+addlyrics = #(def-music-function (location music lyrics) (ly:music? ly:music?)
+ (make-music 'LyricCombineMusic 'elements (list music lyrics)))
+
+#(use-modules (srfi srfi-1))
+#(define-public (symbol-or-symbols? obj)
+ "Return #t iif obj is a symbol or a symbol list."
+ (or (symbol? obj)
+ (and (list? obj)
+ (null? (remove symbol? obj)))))
+
+%% \mytag #'foo { ... } ==> OK
+%% c-\mytag #'foo ^4 ==> KO
+mytag = #(def-music-function (location tagname music) (symbol-or-symbols?
ly:music?)
+ (set! (ly:music-property music 'tags)
+ ((if (list? tagname) append cons) tagname (ly:music-property
music 'tags)))
+ music)
+
+#(defmacro def-grace-function (start stop)
+ `(def-music-function (location music) (ly:music?)
+ (make-music 'GraceMusic
+ 'element (make-music 'SequentialMusic
+ 'elements (list (ly:music-deep-copy ,start)
+ music
+ (ly:music-deep-copy ,stop))))))
+grace = #(def-grace-function startGraceMusic stopGraceMusic)
+acciaccatura = #(def-grace-function startAcciaccaturaMusic
stopAcciaccaturaMusic)
+appoggiatura = #(def-grace-function startAppoggiaturaMusic
stopAppoggiaturaMusic)
+
+partcombine = #(def-music-function (location part1 part2) (ly:music? ly:music?)
+ (make-part-combine-music (list part1 part2)))
+
+autochange = #(def-music-function (location music) (ly:music?)
+ (make-autochange-music music))
+
+applycontext = #(def-music-function (location proc) (procedure?)
+ (make-music 'ApplyContext 'procedure proc))
+
+applyoutput = #(def-music-function (location proc) (procedure?)
+ (make-music 'ApplyOutputEvent 'procedure proc))
+
+breathe = #(def-music-function (location) ()
+ (make-music 'EventChord 'elements (list (make-music
'BreathingSignEvent))))
%{
nicolas
music-functions: problem with -\tag, Han-Wen Nienhuys, 2004/05/14