]> git.donarmstrong.com Git - lilypond.git/blob - lily/music-function-scheme.cc
Merge branch 'master' into lilypond/translation
[lilypond.git] / lily / music-function-scheme.cc
1 #include "music-function.hh"
2
3 LY_DEFINE (ly_music_function_p, "ly:music-function?", 1, 0, 0,
4            (SCM x),
5            "Is @var{x} a @code{music-function}?")
6 {
7   return is_music_function (x) ? SCM_BOOL_T : SCM_BOOL_F;
8 }
9
10 LY_DEFINE (ly_music_function_extract, "ly:music-function-extract", 1, 0, 0,
11            (SCM x),
12            "Return the Scheme function inside@tie{}@var{x}.")
13 {
14   LY_ASSERT_TYPE (is_music_function, x, 1);
15
16   return get_music_function_transform (x);
17 }
18
19 LY_DEFINE (ly_music_function_signature, "ly:music-function-signature", 1, 0, 0,
20            (SCM x),
21            "Return the function signature inside@tie{}@var{x}.")
22 {
23   LY_ASSERT_TYPE (is_music_function, x, 1);
24
25   return get_music_function_signature (x);
26 }
27
28 LY_DEFINE (ly_make_music_function, "ly:make-music-function", 2, 0, 0,
29            (SCM signature, SCM func),
30            "Make a function to process music, to be used for the"
31            " parser.  @var{func} is the function, and @var{signature}"
32            " describes its arguments.  @var{signature}'s cdr is a list"
33            " containing either @code{ly:music?} predicates or other type"
34            " predicates.  Its car is the syntax function to call.")
35 {
36   LY_ASSERT_TYPE (ly_is_list, signature, 1);
37   LY_ASSERT_TYPE (ly_is_procedure, func, 2);
38   int n = 0;
39   for (SCM p = signature; scm_is_pair (p); p = scm_cdr (p), ++n)
40     {
41       SCM proc = scm_car (p);
42       if (scm_is_pair (proc))
43         proc = scm_car (proc);
44       if (scm_is_false (scm_procedure_p (proc)))
45         {
46           scm_wrong_type_arg_msg ("music-function", n, p,
47                                   "music function predicate");
48         }
49     }
50
51   return make_music_function (signature, func);
52 }