[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Implement define-event-function (issue 5083045)
From: |
dak |
Subject: |
Implement define-event-function (issue 5083045) |
Date: |
Wed, 21 Sep 2011 19:10:48 +0000 |
Reviewers: ,
Message:
This allows defining music functions that can be used as directionless
events, a frequently made request. It may be noted that the amount of
code needed for implementing this functionality is not exactly
staggering given the current infrastructure in lexer and parser.
Example:
dyn=
#(define-event-function (parser location arg) (markup?)
(make-dynamic-script arg))
{ c1\dyn pffff }
Description:
Implement define-event-function
Please review this at http://codereview.appspot.com/5083045/
Affected files:
M lily/lexer.ll
M lily/parser.yy
M scm/c++.scm
M scm/lily.scm
M scm/music-functions.scm
Index: lily/lexer.ll
diff --git a/lily/lexer.ll b/lily/lexer.ll
index
db78e049f2597b09a0e772aa1f41e9e620aa12c3..e126e883071b0226728a2214bea9e79131c19f2e
100644
--- a/lily/lexer.ll
+++ b/lily/lexer.ll
@@ -812,6 +812,8 @@ Lily_lexer::scan_escaped_word (string str)
if (scm_is_eq (cs, ly_lily_module_constant ("ly:music?")))
funtype = MUSIC_FUNCTION;
+ else if (scm_is_eq (cs, ly_lily_module_constant ("event?")))
+ funtype = EVENT_FUNCTION;
else if (ly_is_procedure (cs))
funtype = SCM_FUNCTION;
else programming_error ("Bad syntax function predicate");
Index: lily/parser.yy
diff --git a/lily/parser.yy b/lily/parser.yy
index
82df956fa830db25b41bbcc3d9fcec7a56b378ea..1d88a648d6d832eef39863cc664cfc4534aa6070
100644
--- a/lily/parser.yy
+++ b/lily/parser.yy
@@ -286,6 +286,7 @@ If we give names, Bison complains.
%token <scm> PITCH_IDENTIFIER
%token <scm> DURATION_IDENTIFIER
%token <scm> EVENT_IDENTIFIER
+%token <scm> EVENT_FUNCTION
%token <scm> FRACTION
%token <scm> LYRICS_STRING
%token <scm> LYRIC_MARKUP_IDENTIFIER
@@ -393,6 +394,7 @@ If we give names, Bison complains.
%type <scm> embedded_scm_closed
%type <scm> embedded_scm_chord_body
%type <scm> embedded_scm_event
+%type <scm> event_function_event
%type <scm> figure_list
%type <scm> figure_spec
%type <scm> fraction
@@ -1680,6 +1682,13 @@ music_function_event:
}
;
+event_function_event:
+ EVENT_FUNCTION music_function_event_arglist {
+ $$ = run_music_function (PARSER, @$,
+ $1, $2);
+ }
+ ;
+
command_element:
command_event {
$$ = $1;
@@ -1879,6 +1888,7 @@ direction_less_event:
a->set_property ("tremolo-type", scm_from_int ($1));
$$ = a->unprotect ();
}
+ | event_function_event
;
direction_reqd_event:
Index: scm/c++.scm
diff --git a/scm/c++.scm b/scm/c++.scm
index
74f58f4da3f4da2449535f0faf6ca1034c85dcd0..17efd7e6b86e7b74cd44fd71d424795ff49f0aac
100644
--- a/scm/c++.scm
+++ b/scm/c++.scm
@@ -35,6 +35,11 @@
(and (pair? x)
(ly:moment? (car x)) (ly:moment? (cdr x))))
+(define-public (event? x)
+ (and (ly:music? x)
+ (memq 'event (ly:music-property x 'types))
+ #t))
+
(define-public (boolean-or-symbol? x)
(or (boolean? x) (symbol? x)))
Index: scm/lily.scm
diff --git a/scm/lily.scm b/scm/lily.scm
index
b82cd08aa2a2630077c06e38950eab438df7aa50..bea9662d5784ef6e962dcbc42a8e07ee0f55694f
100644
--- a/scm/lily.scm
+++ b/scm/lily.scm
@@ -529,6 +529,7 @@ LilyPond safe mode. The syntax is the same as
`define*-public'."
`((,boolean-or-symbol? . "boolean or symbol")
(,color? . "color")
(,cheap-list? . "list")
+ (,event? . "event")
(,grob-list? . "list of grobs")
;; this is built on cheap-list
(,list-or-symbol? . "list or symbol")
Index: scm/music-functions.scm
diff --git a/scm/music-functions.scm b/scm/music-functions.scm
index
e1ee53017392219563bd04d0700903421ac673db..75f72c05568fefc17c5a45348c3ba3ceb2f42ee1
100644
--- a/scm/music-functions.scm
+++ b/scm/music-functions.scm
@@ -827,6 +827,28 @@ Syntax:
"
`(define-syntax-function scheme? ,@rest))
+(defmacro-public define-event-function rest
+ "Defining macro returning event functions.
+Syntax:
+ (define-event-function (parser location arg1 arg2 ...) (arg1-type?
arg2-type? ...)
+ ...function body...)
+
+argX-type can take one of the forms @code{predicate?} for mandatory
+arguments satisfying the predicate, @code{(predicate?)} for optional
+parameters of that type defaulting to @code{#f}, @address@hidden(predicate?
+value)}} for optional parameters with a specified default
+value (evaluated at definition time). An optional parameter can be
+omitted in a call only when it can't get confused with a following
+parameter of different type.
+
+Predicates with syntactical significance are @code{ly:pitch?},
address@hidden:duration?}, @code{ly:music?}, @code{markup?}. Other
+predicates require the parameter to be entered as Scheme expression.
+
+Must return an event expression. The @code{origin} is automatically
+set to the @code{location} parameter."
+
+ `(define-syntax-function (event? (make-music 'Event 'void #t)) ,@rest))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- Implement define-event-function (issue 5083045),
dak <=
- Re: Implement define-event-function (issue 5083045), reinhold . kainhofer, 2011/09/21
- Re: Implement define-event-function (issue 5083045), n . puttock, 2011/09/21
- Re: Implement define-event-function (issue 5083045), dak, 2011/09/21
- Re: Implement define-event-function (issue 5083045), n . puttock, 2011/09/21
- Re: Implement define-event-function (issue 5083045), dak, 2011/09/21
- Re: Implement define-event-function (issue 5083045), dak, 2011/09/21
- Re: Implement define-event-function (issue 5083045), dak, 2011/09/21
- Re: Implement define-event-function (issue 5083045), dak, 2011/09/21