From 0ae0eb4b5fda460347066ca582ab858697bb71f4 Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Mon, 19 Sep 2011 00:56:02 +0200 Subject: [PATCH] parser.yy: Reorganization/cleanup --- lily/parser.yy | 157 ++++++++++++++++++++++++++----------------------- 1 file changed, 84 insertions(+), 73 deletions(-) diff --git a/lily/parser.yy b/lily/parser.yy index 02c99e2f42..df3cd1a584 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -328,7 +328,6 @@ If we give names, Bison complains. %type composite_music %type grouped_music_list %type closed_music -%type open_music %type music %type prefix_composite_music %type repeated_music @@ -388,18 +387,19 @@ If we give names, Bison complains. %type context_prop_spec %type direction_less_char %type duration_length -%type closed_embedded_scm %type embedded_scm +%type embedded_scm_bare +%type embedded_scm_closed +%type embedded_scm_chord_body +%type embedded_scm_event %type figure_list %type figure_spec %type fraction %type full_markup %type full_markup_list -%type function_scm_argument %type function_arglist -%type function_arglist_nonmusic_last -%type closed_function_arglist -%type open_function_arglist +%type function_arglist_bare +%type function_arglist_closed %type identifier_init %type lilypond %type lilypond_header @@ -412,7 +412,6 @@ If we give names, Bison complains. %type markup_composed_list %type markup_command_list %type markup_command_list_arguments -%type closed_markup_command_list_arguments %type markup_command_basic_arguments %type markup_head_1_item %type markup_head_1_list @@ -440,9 +439,10 @@ If we give names, Bison complains. %type property_operation %type property_path property_path_revved %type scalar -%type closed_scalar -%type open_scm_function_call -%type closed_scm_function_call +%type scalar_bare +%type scalar_closed +%type scm_function_call +%type scm_function_call_closed %type script_abbreviation %type simple_chord_elements %type simple_markup @@ -545,28 +545,20 @@ toplevel_expression: } ; -closed_embedded_scm: +embedded_scm_bare: SCM_TOKEN | SCM_IDENTIFIER - | closed_scm_function_call ; +/* The generic version may end in music, or not */ + embedded_scm: - closed_embedded_scm - | open_scm_function_call + embedded_scm_bare + | scm_function_call ; -closed_scm_function_call: - SCM_FUNCTION closed_function_arglist - { - $$ = run_music_function (PARSER, @$, - $1, $2); - } - ; - -open_scm_function_call: - SCM_FUNCTION open_function_arglist - { +scm_function_call: + SCM_FUNCTION function_arglist { $$ = run_music_function (PARSER, @$, $1, $2); } @@ -974,10 +966,10 @@ tempo_event: TEMPO steno_duration '=' tempo_range { $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4); } - | TEMPO closed_scalar steno_duration '=' tempo_range { + | TEMPO scalar_closed steno_duration '=' tempo_range { $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5); } - | TEMPO closed_scalar { + | TEMPO scalar { $$ = MAKE_SYNTAX ("tempo", @$, $2); } ; @@ -1102,52 +1094,49 @@ closed_music: | grouped_music_list ; -/* Music that potentially accepts additional events or durations */ -open_music: - simple_music - | prefix_composite_music - ; - grouped_music_list: simultaneous_music { $$ = $1; } | sequential_music { $$ = $1; } ; -function_scm_argument: - closed_embedded_scm - | simple_string - ; - /* An argument list. If a function \foo expects scm scm music, then the lexer expands \foo into the token sequence: MUSIC_FUNCTION EXPECT_MUSIC EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS and this rule returns the reversed list of arguments. */ function_arglist: - closed_function_arglist - | open_function_arglist + function_arglist_bare + | EXPECT_MUSIC function_arglist music { + $$ = scm_cons ($3, $2); + } + | EXPECT_SCM function_arglist embedded_scm { + $$ = scm_cons ($3, $2); + } ; -open_function_arglist: - EXPECT_MUSIC function_arglist open_music { +function_arglist_closed: + function_arglist_bare + | EXPECT_MUSIC function_arglist closed_music { $$ = scm_cons ($3, $2); } - | EXPECT_SCM function_arglist open_scm_function_call { + | EXPECT_SCM function_arglist embedded_scm_closed { $$ = scm_cons ($3, $2); } ; -/* a closed argument list is one that does not end in a music - expression that could still take a duration or event */ +embedded_scm_closed: + embedded_scm_bare + | scm_function_call_closed + ; -closed_function_arglist: - function_arglist_nonmusic_last - | EXPECT_MUSIC function_arglist closed_music { - $$ = scm_cons ($3, $2); - } +scm_function_call_closed: + SCM_FUNCTION function_arglist_closed { + $$ = run_music_function (PARSER, @$, + $1, $2); + } ; -function_arglist_nonmusic_last: +function_arglist_bare: EXPECT_NO_MORE_ARGS { /* This is for 0-ary functions, so they don't need to read a lookahead token */ @@ -1162,11 +1151,11 @@ function_arglist_nonmusic_last: | EXPECT_PITCH function_arglist pitch_also_in_chords { $$ = scm_cons ($3, $2); } - | EXPECT_DURATION closed_function_arglist duration_length { + | EXPECT_DURATION function_arglist_closed duration_length { $$ = scm_cons ($3, $2); } - | EXPECT_SCM function_arglist function_scm_argument { - $$ = scm_cons ($3, $2); + | EXPECT_SCM function_arglist simple_string { + $$ = scm_cons ($3, $2); } ; @@ -1342,10 +1331,10 @@ context_change: property_path_revved: - closed_embedded_scm { + embedded_scm_closed { $$ = scm_cons ($1, SCM_EOL); } - | property_path_revved closed_embedded_scm { + | property_path_revved embedded_scm_closed { $$ = scm_cons ($2, $1); } ; @@ -1483,7 +1472,8 @@ simple_string: STRING { } ; -closed_scalar: string { +scalar_bare: + string { $$ = $1; } | lyric_element { @@ -1492,7 +1482,7 @@ closed_scalar: string { | bare_number { $$ = $1; } - | closed_embedded_scm { + | embedded_scm_bare { $$ = $1; } | full_markup { @@ -1500,10 +1490,17 @@ closed_scalar: string { } ; -scalar: closed_scalar - | open_scm_function_call +scalar: + scalar_bare | + scm_function_call + ; + +scalar_closed: + scalar_bare | + scm_function_call_closed ; + event_chord: /* TODO: Create a special case that avoids the creation of EventChords around simple_elements that have no post_events? @@ -1624,10 +1621,21 @@ chord_body_element: */ music_function_chord_body_arglist: - function_arglist_nonmusic_last + function_arglist_bare | EXPECT_MUSIC music_function_chord_body_arglist chord_body_element { $$ = scm_cons ($3, $2); } + | EXPECT_SCM function_arglist embedded_scm_chord_body { + $$ = scm_cons ($3, $2); + } + ; + +embedded_scm_chord_body: + embedded_scm_bare + | SCM_FUNCTION music_function_chord_body_arglist { + $$ = run_music_function (PARSER, @$, + $1, $2); + } ; music_function_chord_body: @@ -1643,10 +1651,21 @@ music_function_chord_body: * refrain from doing so. */ music_function_event_arglist: - function_arglist_nonmusic_last + function_arglist_bare | EXPECT_MUSIC music_function_event_arglist post_event { $$ = scm_cons ($3, $2); } + | EXPECT_SCM function_arglist embedded_scm_event { + $$ = scm_cons ($3, $2); + } + ; + +embedded_scm_event: + embedded_scm_bare + | SCM_FUNCTION music_function_event_arglist { + $$ = run_music_function (PARSER, @$, + $1, $2); + } ; music_function_event: @@ -2522,7 +2541,7 @@ markup_braced_list_body: ; markup_command_list: - MARKUP_LIST_FUNCTION closed_markup_command_list_arguments { + MARKUP_LIST_FUNCTION markup_command_list_arguments { $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL)); } ; @@ -2531,7 +2550,7 @@ markup_command_basic_arguments: EXPECT_MARKUP_LIST markup_command_list_arguments markup_list { $$ = scm_cons ($3, $2); } - | EXPECT_SCM markup_command_list_arguments closed_embedded_scm { + | EXPECT_SCM markup_command_list_arguments embedded_scm_closed { $$ = scm_cons ($3, $2); } | EXPECT_NO_MORE_ARGS { @@ -2539,21 +2558,13 @@ markup_command_basic_arguments: } ; -closed_markup_command_list_arguments: +markup_command_list_arguments: markup_command_basic_arguments { $$ = $1; } | EXPECT_MARKUP markup_command_list_arguments markup { $$ = scm_cons ($3, $2); } ; -markup_command_list_arguments: - closed_markup_command_list_arguments - | EXPECT_SCM markup_command_list_arguments open_scm_function_call - { - $$ = scm_cons ($3, $2); - } - ; - markup_head_1_item: MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments { $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL)); -- 2.39.5