-
Notifications
You must be signed in to change notification settings - Fork 67
/
parser.yy
4172 lines (3804 loc) · 99 KB
/
parser.yy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- mode: c++; c-file-style: "linux"; indent-tabs-mode: t -*- */
/*
This file is part of LilyPond, the GNU music typesetter.
Copyright (C) 1997--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
Jan Nieuwenhuizen <janneke@gnu.org>
LilyPond is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
LilyPond is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
*/
/* Mode and indentation are at best a rough approximation based on TAB
* formatting (reasonable for compatibility with unspecific editor
* modes as Bison modes are hard to find) and need manual correction
* frequently. Without a reasonably dependable way of formatting a
* Bison file sensibly, there is little point in trying to fix the
* inconsistent state of indentation.
*/
%{
#define yyerror Lily_parser::parser_error
/* We use custom location type: Input objects */
#define YYLTYPE Input
#define YYSTYPE SCM
#define YYLLOC_DEFAULT(Current,Rhs,N) \
((Current).set_location ((Rhs)[1], (Rhs)[N]))
#define YYPRINT(file, type, value) \
do { \
if (scm_is_eq (value, SCM_UNSPECIFIED)) \
break; \
SCM s = Display::value_to_lily_string (value); \
char *p = scm_to_locale_string (s); \
fputs (p, file); \
free (p); \
} while (0)
%}
%parse-param {Lily_parser *parser}
%parse-param {SCM *retval}
%lex-param {Lily_parser *parser}
%error-verbose
%debug
/* We use SCMs to do strings, because it saves us the trouble of
deleting them. Let's hope that a stack overflow doesn't trigger a move
of the parse stack onto the heap. */
%left PREC_BOT
%nonassoc REPEAT
%nonassoc ALTERNATIVE
/* The above precedences tackle the shift/reduce problem
1. \repeat
\repeat .. \alternative
\repeat { \repeat .. \alternative }
or
\repeat { \repeat } \alternative
*/
%nonassoc COMPOSITE
%left ADDLYRICS
%right ':' UNSIGNED REAL E_UNSIGNED EVENT_IDENTIFIER EVENT_FUNCTION '^' '_'
HYPHEN EXTENDER DURATION_IDENTIFIER '!'
/* The above are needed for collecting tremoli and other items (that
could otherwise be interpreted as belonging to the next function
argument) greedily, and together with the next rule will serve to
join numbers and units greedily instead of allowing them into
separate function arguments
*/
%nonassoc NUMBER_IDENTIFIER
%left PREC_TOP
%pure-parser
%locations
%{ // -*-Fundamental-*-
/*
FIXME:
* The rules for who is protecting what are very shady. Uniformise
this.
* There are too many lexical modes?
*/
#include "config.hh"
#include <cctype>
#include <cstdlib>
#include <cstdio>
using namespace std;
#include "book.hh"
#include "context-def.hh"
#include "context-mod.hh"
#include "dimensions.hh"
#include "file-path.hh"
#include "input.hh"
#include "international.hh"
#include "lily-guile.hh"
#include "lily-lexer.hh"
#include "lily-parser.hh"
#include "ly-module.hh"
#include "main.hh"
#include "misc.hh"
#include "music.hh"
#include "output-def.hh"
#include "paper-book.hh"
#include "scm-hash.hh"
#include "score.hh"
#include "text-interface.hh"
#include "warn.hh"
#include "lily-imports.hh"
void
Lily_parser::parser_error (Input const *i, Lily_parser *parser, SCM *, const string &s)
{
parser->parser_error (*i, s);
}
// The following are somewhat precarious constructs as they may change
// the value of the lookahead token. That implies that the lookahead
// token must not yet have made an impact on the state stack other
// than causing the reduction of the current rule, or switching the
// lookahead token while Bison is mulling it over will cause trouble.
#define MYBACKUP(Token, Value, Location) \
do { \
if (yychar != YYEMPTY) \
parser->lexer_->push_extra_token \
(yylloc, yychar, yylval); \
if (Token) \
parser->lexer_->push_extra_token \
(Location, Token, Value); \
parser->lexer_->push_extra_token (Location, BACKUP); \
yychar = YYEMPTY; \
} while (0)
#define MYREPARSE(Location, Pred, Token, Value) \
do { \
if (yychar != YYEMPTY) \
parser->lexer_->push_extra_token \
(yylloc, yychar, yylval); \
parser->lexer_->push_extra_token \
(Location, Token, Value); \
parser->lexer_->push_extra_token \
(Location, REPARSE, Pred); \
yychar = YYEMPTY; \
} while (0)
%}
%{
#define MY_MAKE_MUSIC(x, spot) \
make_music_with_input (ly_symbol2scm (x), \
parser->lexer_->override_input (spot))
/* ES TODO:
- delay application of the function
*/
#define LOWLEVEL_MAKE_SYNTAX(location, proc, ...) \
with_location \
(parser->lexer_->override_input (location).smobbed_copy (), \
proc, \
##__VA_ARGS__)
/* Syntactic Sugar. */
#define MAKE_SYNTAX(name, location, ...) \
LOWLEVEL_MAKE_SYNTAX (location, Syntax::name, ##__VA_ARGS__)
#define START_MAKE_SYNTAX(name, ...) \
scm_list_n (Syntax::name, ##__VA_ARGS__, SCM_UNDEFINED)
#define FINISH_MAKE_SYNTAX(start, location, ...) \
LOWLEVEL_MAKE_SYNTAX \
(location, \
Guile_user::apply, \
scm_car (start), \
scm_append_x \
(scm_list_2 (scm_cdr (start), \
scm_list_n (__VA_ARGS__, SCM_UNDEFINED))))
SCM get_next_unique_context_id ();
SCM get_next_unique_lyrics_context_id ();
#undef _
#if !HAVE_GETTEXT
#define _(x) x
#else
#include <libintl.h>
#define _(x) gettext (x)
#endif
static Music *make_music_with_input (SCM name, Input where);
SCM check_scheme_arg (Lily_parser *parser, Input loc,
SCM arg, SCM args, SCM pred, SCM disp = SCM_UNDEFINED);
SCM make_music_from_simple (Lily_parser *parser, Input loc, SCM pitch);
SCM loc_on_music (Lily_parser *parser, Input loc, SCM arg);
SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
SCM make_chord_step (SCM step, Rational alter);
SCM make_simple_markup (SCM a);
SCM make_duration (SCM t, int dots = 0);
bool is_regular_identifier (SCM id, bool multiple=false);
SCM try_string_variants (SCM pred, SCM str);
int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
%}
/* The third option is an alias that will be used to display the
syntax error. Bison CVS now correctly handles backslash escapes.
FIXME: Bison needs to translate some of these, eg, STRING.
*/
/* Keyword tokens with plain escaped name. */
%token END_OF_FILE 0 "end of input"
%token ACCEPTS "\\accepts"
%token ADDLYRICS "\\addlyrics"
%token ALIAS "\\alias"
%token ALTERNATIVE "\\alternative"
%token BOOK "\\book"
%token BOOKPART "\\bookpart"
%token CHANGE "\\change"
%token CHORDMODE "\\chordmode"
%token CHORDS "\\chords"
%token CONSISTS "\\consists"
%token CONTEXT "\\context"
%token DEFAULT "\\default"
%token DEFAULTCHILD "\\defaultchild"
%token DENIES "\\denies"
%token DESCRIPTION "\\description"
%token DRUMMODE "\\drummode"
%token DRUMS "\\drums"
%token ETC "\\etc"
%token FIGUREMODE "\\figuremode"
%token FIGURES "\\figures"
%token HEADER "\\header"
%token INVALID "\\version-error"
%token LAYOUT "\\layout"
%token LYRICMODE "\\lyricmode"
%token LYRICS "\\lyrics"
%token LYRICSTO "\\lyricsto"
%token MARKUP "\\markup"
%token MARKUPLIST "\\markuplist"
%token MIDI "\\midi"
%token NAME "\\name"
%token NOTEMODE "\\notemode"
%token OVERRIDE "\\override"
%token PAPER "\\paper"
%token REMOVE "\\remove"
%token REPEAT "\\repeat"
%token REST "\\rest"
%token REVERT "\\revert"
%token SCORE "\\score"
%token SCORELINES "\\score-lines"
%token SEQUENTIAL "\\sequential"
%token SET "\\set"
%token SIMULTANEOUS "\\simultaneous"
%token TEMPO "\\tempo"
%token TYPE "\\type"
%token UNSET "\\unset"
%token WITH "\\with"
/* Keyword token exceptions. */
%token NEWCONTEXT "\\new"
/* Other string tokens. */
%token CHORD_BASS "/+"
%token CHORD_CARET "^"
%token CHORD_COLON ":"
%token CHORD_MINUS "-"
%token CHORD_SLASH "/"
%token ANGLE_OPEN "<"
%token ANGLE_CLOSE ">"
%token DOUBLE_ANGLE_OPEN "<<"
%token DOUBLE_ANGLE_CLOSE ">>"
%token E_BACKSLASH "\\"
%token E_EXCLAMATION "\\!"
%token E_PLUS "\\+"
%token EXTENDER "__"
/*
If we give names, Bison complains.
*/
%token FIGURE_CLOSE /* "\\>" */
%token FIGURE_OPEN /* "\\<" */
%token FIGURE_SPACE "_"
%token HYPHEN "--"
%token MULTI_MEASURE_REST
%token E_UNSIGNED
%token UNSIGNED
/* Artificial tokens, for more generic function syntax */
%token EXPECT_MARKUP "markup?"
%token EXPECT_SCM "scheme?"
%token BACKUP "(backed-up?)"
%token REPARSE "(reparsed?)"
%token EXPECT_MARKUP_LIST "markup-list?"
%token EXPECT_OPTIONAL "optional?"
/* After the last argument. */
%token EXPECT_NO_MORE_ARGS;
/* An artificial token for parsing embedded Lilypond */
%token EMBEDDED_LILY "#{"
%token BOOK_IDENTIFIER
%token CHORD_MODIFIER
%token CHORD_REPETITION
%token CONTEXT_MOD_IDENTIFIER
%token DRUM_PITCH
%token PITCH_IDENTIFIER
%token DURATION_IDENTIFIER
%token EVENT_IDENTIFIER
%token EVENT_FUNCTION
%token FRACTION
%token LYRIC_ELEMENT
%token MARKUP_FUNCTION
%token MARKUP_LIST_FUNCTION
%token MARKUP_IDENTIFIER
%token MARKUPLIST_IDENTIFIER
%token MUSIC_FUNCTION
%token MUSIC_IDENTIFIER
%token NOTENAME_PITCH
%token NUMBER_IDENTIFIER
%token REAL
%token RESTNAME
%token SCM_ARG
%token SCM_FUNCTION
%token SCM_IDENTIFIER
%token SCM_TOKEN
%token STRING
%token SYMBOL_LIST
%token TONICNAME_PITCH
%left '-' '+'
/* We don't assign precedence to / and *, because we might need varied
prec levels in different prods */
%left UNARY_MINUS
%%
start_symbol:
lilypond
| EMBEDDED_LILY {
SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
parser->lexer_->push_note_state (nn);
} embedded_lilypond {
parser->lexer_->pop_state ();
*retval = $3;
}
;
lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
| lilypond toplevel_expression {
}
| lilypond assignment {
}
| lilypond error {
parser->error_level_ = 1;
}
| lilypond INVALID {
parser->error_level_ = 1;
}
;
toplevel_expression:
{
parser->lexer_->add_scope (get_header (parser));
} lilypond_header {
parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
}
| book_block {
SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
scm_call_1 (proc, $1);
}
| bookpart_block {
SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
scm_call_1 (proc, $1);
}
| BOOK_IDENTIFIER {
SCM proc = parser->lexer_->lookup_identifier
(unsmob<Book>($1)->paper_
? "toplevel-book-handler"
: "toplevel-bookpart-handler");
scm_call_1 (proc, $1);
}
| score_block {
SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
scm_call_1 (proc, $1);
}
| composite_music {
SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
scm_call_1 (proc, $1);
}
| full_markup {
SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
scm_call_1 (proc, scm_list_1 ($1));
}
| full_markup_list {
SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
scm_call_1 (proc, $1);
}
| SCM_TOKEN {
// Evaluate and ignore #xxx, as opposed to \xxx
parser->lexer_->eval_scm_token ($1, @1);
}
| embedded_scm_active
{
SCM out = SCM_UNDEFINED;
if (Text_interface::is_markup ($1))
out = scm_list_1 ($1);
else if (Text_interface::is_markup_list ($1))
out = $1;
if (scm_is_pair (out))
{
SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
scm_call_1 (proc, out);
} else if (unsmob<Score> ($1))
{
SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
scm_call_1 (proc, $1);
} else if (Output_def * od = unsmob<Output_def> ($1)) {
SCM id = SCM_EOL;
if (to_boolean (od->c_variable ("is-paper")))
id = ly_symbol2scm ("$defaultpaper");
else if (to_boolean (od->c_variable ("is-midi")))
id = ly_symbol2scm ("$defaultmidi");
else if (to_boolean (od->c_variable ("is-layout")))
id = ly_symbol2scm ("$defaultlayout");
parser->lexer_->set_identifier (id, $1);
} else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
parser->parser_error (@1, _("bad expression type"));
}
| output_def {
SCM id = SCM_EOL;
Output_def * od = unsmob<Output_def> ($1);
if (to_boolean (od->c_variable ("is-paper")))
id = ly_symbol2scm ("$defaultpaper");
else if (to_boolean (od->c_variable ("is-midi")))
id = ly_symbol2scm ("$defaultmidi");
else if (to_boolean (od->c_variable ("is-layout")))
id = ly_symbol2scm ("$defaultlayout");
parser->lexer_->set_identifier (id, $1);
}
;
embedded_scm_bare:
SCM_TOKEN
{
$$ = parser->lexer_->eval_scm_token ($1, @1);
}
| SCM_IDENTIFIER
;
embedded_scm_active:
SCM_IDENTIFIER
| scm_function_call
;
embedded_scm_bare_arg:
SCM_ARG
| SCM_TOKEN
{
$$ = parser->lexer_->eval_scm_token ($1, @1);
}
| FRACTION
| partial_markup
| full_markup_list
| context_modification
| score_block
| context_def_spec_block
| book_block
| bookpart_block
| output_def
;
/* The generic version may end in music, or not */
embedded_scm:
embedded_scm_bare
| scm_function_call
;
/* embedded_scm_arg is _not_ casting pitches to music by default, this
* has to be done by the function itself. Note that this may cause
* the results of scm_function_call or embedded_scm_bare_arg to be
* turned into music from pitches as well. Note that this creates a
* distinctly awkward situation for calculated drum pitches. Those
* are at the current point of time rejected as music constituents as
* they can't be distinguished from "proper" symbols.
*/
embedded_scm_arg:
embedded_scm_bare_arg
| scm_function_call
| music_assign
;
scm_function_call:
SCM_FUNCTION function_arglist {
$$ = MAKE_SYNTAX (music_function, @$,
$1, $2);
}
;
embedded_lilypond_number:
'-' embedded_lilypond_number
{
$$ = scm_difference ($2, SCM_UNDEFINED);
}
| bare_number_common
| UNSIGNED NUMBER_IDENTIFIER
{
$$ = scm_product ($1, $2);
}
;
embedded_lilypond:
/* empty */
{
// FIXME: @$ does not contain a useful source location
// for empty rules, and the only token in the whole
// production, EMBEDDED_LILY, is synthetic and also
// contains no source location.
$$ = MAKE_SYNTAX (void_music, @$);
}
| identifier_init_nonumber
| embedded_lilypond_number
| post_event post_events
{
$$ = scm_reverse_x ($2, SCM_EOL);
if (Music *m = unsmob<Music> ($1))
{
if (m->is_mus_type ("post-event-wrapper"))
$$ = scm_append
(scm_list_2 (m->get_property ("elements"),
$$));
else
$$ = scm_cons ($1, $$);
}
if (scm_is_pair ($$)
&& scm_is_null (scm_cdr ($$)))
$$ = scm_car ($$);
else
{
Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
m->set_property ("elements", $$);
$$ = m->unprotect ();
}
}
| multiplied_duration
| music_embedded music_embedded music_list {
$3 = scm_reverse_x ($3, SCM_EOL);
if (unsmob<Music> ($2))
$3 = scm_cons ($2, $3);
if (unsmob<Music> ($1))
$3 = scm_cons ($1, $3);
$$ = MAKE_SYNTAX (sequential_music, @$, $3);
}
| error {
parser->error_level_ = 1;
$$ = SCM_UNSPECIFIED;
}
| INVALID embedded_lilypond {
parser->error_level_ = 1;
$$ = $2;
}
;
lilypond_header_body:
/* empty */ { $$ = SCM_UNSPECIFIED; }
| lilypond_header_body assignment {
}
| lilypond_header_body embedded_scm {
}
;
lilypond_header:
HEADER '{' lilypond_header_body '}' {
$$ = parser->lexer_->remove_scope ();
}
;
/*
DECLARATIONS
*/
assignment_id:
STRING { $$ = $1; }
;
assignment:
assignment_id '=' identifier_init {
parser->lexer_->set_identifier ($1, $3);
$$ = SCM_UNSPECIFIED;
}
| assignment_id property_path '=' identifier_init {
SCM path = scm_cons (scm_string_to_symbol ($1), $2);
parser->lexer_->set_identifier (path, $4);
$$ = SCM_UNSPECIFIED;
}
| assignment_id '.' property_path '=' identifier_init {
SCM path = scm_cons (scm_string_to_symbol ($1), $3);
parser->lexer_->set_identifier (path, $5);
$$ = SCM_UNSPECIFIED;
}
;
identifier_init:
identifier_init_nonumber
| number_expression
| post_event_nofinger post_events
{
$$ = scm_reverse_x ($2, SCM_EOL);
if (Music *m = unsmob<Music> ($1))
{
if (m->is_mus_type ("post-event-wrapper"))
$$ = scm_append
(scm_list_2 (m->get_property ("elements"),
$$));
else
$$ = scm_cons ($1, $$);
}
if (scm_is_pair ($$)
&& scm_is_null (scm_cdr ($$)))
$$ = scm_car ($$);
else
{
Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
m->set_property ("elements", $$);
$$ = m->unprotect ();
}
}
;
identifier_init_nonumber:
score_block
| book_block
| bookpart_block
| output_def
| context_def_spec_block
| music_assign
| pitch_or_music
| FRACTION
| string
| embedded_scm
| partial_markup
| full_markup_list
| context_modification
| partial_function ETC
{
$$ = MAKE_SYNTAX (partial_music_function, @$,
scm_reverse_x ($1, SCM_EOL));
}
;
// Partial functions
partial_function:
MUSIC_FUNCTION function_arglist_partial
{
$$ = scm_acons ($1, $2, SCM_EOL);
}
| EVENT_FUNCTION function_arglist_partial
{
$$ = scm_acons ($1, $2, SCM_EOL);
}
| SCM_FUNCTION function_arglist_partial
{
$$ = scm_acons ($1, $2, SCM_EOL);
}
| OVERRIDE grob_prop_path '='
{
if (SCM_UNBNDP ($2))
$$ = scm_list_1 (SCM_BOOL_F);
else
$$ = scm_cons
(scm_list_3 (Syntax::property_override_function,
scm_cdr ($2), scm_car ($2)),
SCM_EOL);
}
| SET context_prop_spec '='
{
if (SCM_UNBNDP ($2))
$$ = scm_list_1 (SCM_BOOL_F);
else
$$ = scm_cons
(scm_list_3 (Syntax::property_set_function,
scm_cadr ($2), scm_car ($2)),
SCM_EOL);
}
| MUSIC_FUNCTION EXPECT_SCM function_arglist_optional partial_function
{
$$ = scm_acons ($1, $3, $4);
}
| EVENT_FUNCTION EXPECT_SCM function_arglist_optional partial_function
{
$$ = scm_acons ($1, $3, $4);
}
| SCM_FUNCTION EXPECT_SCM function_arglist_optional partial_function
{
$$ = scm_acons ($1, $3, $4);
}
| OVERRIDE grob_prop_path '=' partial_function
{
if (SCM_UNBNDP ($2))
$$ = scm_list_1 (SCM_BOOL_F);
else
$$ = scm_cons
(scm_list_3 (Syntax::property_override_function,
scm_cdr ($2), scm_car ($2)),
$4);
}
| SET context_prop_spec '=' partial_function
{
if (SCM_UNBNDP ($2))
$$ = scm_list_1 (SCM_BOOL_F);
else
$$ = scm_cons
(scm_list_3 (Syntax::property_set_function,
scm_cadr ($2), scm_car ($2)),
$4);
}
| MUSIC_FUNCTION EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup partial_function
{
$$ = scm_acons ($1, $4, $5);
}
| EVENT_FUNCTION EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup partial_function
{
$$ = scm_acons ($1, $4, $5);
}
| SCM_FUNCTION EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup partial_function
{
$$ = scm_acons ($1, $4, $5);
}
;
context_def_spec_block:
CONTEXT '{' context_def_spec_body '}'
{
$$ = $3;
Context_def *td = unsmob<Context_def> ($$);
if (!td) {
$$ = Context_def::make_scm ();
td = unsmob<Context_def> ($$);
}
td->origin ()->set_spot (@$);
}
;
context_mod_arg:
embedded_scm
|
{
SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
parser->lexer_->push_note_state (nn);
}
composite_music
{
parser->lexer_->pop_state ();
$$ = $2;
}
;
context_def_spec_body:
/**/ {
$$ = SCM_UNSPECIFIED;
}
| context_def_spec_body context_mod {
if (!SCM_UNBNDP ($2)) {
Context_def *td = unsmob<Context_def> ($$);
if (!td) {
$$ = Context_def::make_scm ();
td = unsmob<Context_def> ($$);
}
unsmob<Context_def> ($$)->add_context_mod ($2);
}
}
| context_def_spec_body context_modification {
Context_def *td = unsmob<Context_def> ($$);
if (!td) {
$$ = Context_def::make_scm ();
td = unsmob<Context_def> ($$);
}
SCM new_mods = unsmob<Context_mod> ($2)->get_mods ();
for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
td->add_context_mod (scm_car (m));
}
}
| context_def_spec_body context_mod_arg {
Context_def *td = unsmob<Context_def> ($1);
if (scm_is_eq ($2, SCM_UNSPECIFIED))
;
else if (!td && unsmob<Context_def> ($2))
$$ = $2;
else {
if (!td) {
$$ = Context_def::make_scm ();
td = unsmob<Context_def> ($$);
}
if (unsmob<Music> ($2)) {
SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
$2 = scm_call_1 (proc, $2);
}
if (Context_mod *cm = unsmob<Context_mod> ($2)) {
for (SCM m = cm->get_mods (); scm_is_pair (m); m = scm_cdr (m)) {
td->add_context_mod (scm_car (m));
}
} else
parser->parser_error (@2, _ ("not a context mod"));
}
}
;
book_block:
BOOK '{' book_body '}' {
$$ = $3;
unsmob<Book> ($$)->origin ()->set_spot (@$);
pop_paper (parser);
parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
}
;
/* FIXME:
* Use 'handlers' like for toplevel-* stuff?
* grok \layout and \midi? */
book_body:
{
Book *book = new Book;
init_papers (parser);
book->paper_ = dynamic_cast<Output_def*> (unsmob<Output_def> (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
book->paper_->unprotect ();
push_paper (parser, book->paper_);
book->header_ = get_header (parser);
$$ = book->unprotect ();
parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
}
| BOOK_IDENTIFIER {
parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
}
| book_body paper_block {
unsmob<Book> ($1)->paper_ = unsmob<Output_def> ($2);
set_paper (parser, unsmob<Output_def> ($2));
}
| book_body bookpart_block {
SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
scm_call_2 (proc, $1, $2);
}
| book_body score_block {
SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
scm_call_2 (proc, $1, $2);
}
| book_body composite_music {
SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
scm_call_2 (proc, $1, $2);
}
| book_body full_markup {
SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
scm_call_2 (proc, $1, scm_list_1 ($2));
}
| book_body full_markup_list {
SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
scm_call_2 (proc, $1, $2);
}
| book_body SCM_TOKEN {
// Evaluate and ignore #xxx, as opposed to \xxx
parser->lexer_->eval_scm_token ($2, @2);
}
| book_body embedded_scm_active
{
SCM out = SCM_UNDEFINED;
if (Text_interface::is_markup ($2))
out = scm_list_1 ($2);
else if (Text_interface::is_markup_list ($2))
out = $2;
if (scm_is_pair (out))
{
SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
scm_call_2 (proc, $1, out);
} else if (unsmob<Score> ($2))
{
SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
scm_call_2 (proc, $1, $2);
} else if (Output_def *od = unsmob<Output_def> ($2)) {
SCM id = SCM_EOL;
if (to_boolean (od->c_variable ("is-paper")))
id = ly_symbol2scm ("$defaultpaper");
else if (to_boolean (od->c_variable ("is-midi")))
id = ly_symbol2scm ("$defaultmidi");
else if (to_boolean (od->c_variable ("is-layout")))
id = ly_symbol2scm ("$defaultlayout");
parser->lexer_->set_identifier (id, $2);
} else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
parser->parser_error (@2, _("bad expression type"));
}
| book_body
{
parser->lexer_->add_scope (unsmob<Book> ($1)->header_);
} lilypond_header
| book_body error {
Book *book = unsmob<Book> ($1);
book->paper_ = 0;
book->scores_ = SCM_EOL;
book->bookparts_ = SCM_EOL;
}
;
bookpart_block:
BOOKPART '{' bookpart_body '}' {
$$ = $3;
unsmob<Book> ($$)->origin ()->set_spot (@$);
parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
}
;
bookpart_body:
{
Book *book = new Book;
$$ = book->unprotect ();
parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
}
| BOOK_IDENTIFIER {
parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
}
| bookpart_body paper_block {
unsmob<Book> ($$)->paper_ = unsmob<Output_def> ($2);
}
| bookpart_body score_block {
SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
scm_call_2 (proc, $1, $2);
}
| bookpart_body composite_music {
SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
scm_call_2 (proc, $1, $2);
}
| bookpart_body full_markup {
SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
scm_call_2 (proc, $1, scm_list_1 ($2));
}
| bookpart_body full_markup_list {
SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
scm_call_2 (proc, $1, $2);
}
| bookpart_body SCM_TOKEN {
// Evaluate and ignore #xxx, as opposed to \xxx
parser->lexer_->eval_scm_token ($2, @2);
}