2 my-lily-parser.cc -- implement My_lily_parser
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "my-lily-parser.hh"
10 #include "my-lily-lexer.hh"
13 #include "music-list.hh"
14 #include "musical-request.hh"
15 #include "command-request.hh"
18 #include "file-results.hh"
19 #include "midi-def.hh"
20 #include "paper-def.hh"
21 #include "identifier.hh"
23 My_lily_parser::My_lily_parser (Sources * source_l)
28 abbrev_beam_type_i_ = 0;
29 default_duration_.durlog_i_ = 2;
30 default_abbrev_i_ = 0;
36 My_lily_parser::~My_lily_parser()
39 delete default_header_p_;
45 My_lily_parser::set_version_check (bool ig)
47 ignore_version_b_ = ig;
51 My_lily_parser::parse_file (String init, String s)
53 lexer_p_ = new My_lily_lexer;
55 lexer_p_->main_input_str_ = s;
57 *mlog << _ ("Parsing...");
59 init_parse_b_ = false;
60 set_yydebug (!monitor->silent_b ("Parser") && check_debug);
61 lexer_p_->new_input (init, source_l_);
64 if (!define_spot_array_.empty())
66 warning (_ ("braces don't match"));
70 inclusion_global_array = lexer_p_->filename_str_arr_;
74 My_lily_parser::remember_spot()
76 define_spot_array_.push (here_input());
80 My_lily_parser::here_ch_C() const
82 return lexer_p_->here_ch_C();
86 My_lily_parser::parser_error (String s)
88 here_input().error (s);
90 exit (fatal_error_i_);
96 My_lily_parser::set_abbrev_beam (int type_i)
98 abbrev_beam_type_i_ = type_i;
103 My_lily_parser::set_last_duration (Duration const *d)
105 default_duration_ = *d;
109 but keep sticky plet factor within plet brackets
111 default_duration_.plet_ = plet_;
116 My_lily_parser::get_word_element (String s, Duration * duration_p)
118 Simultaneous_music* velt_p = new Request_chord;
120 Lyric_req* lreq_p = new Lyric_req;
121 lreq_p ->text_str_ = s;
122 lreq_p->duration_ = *duration_p;
123 lreq_p->set_spot (here_input());
125 velt_p->add_music (lreq_p);
133 My_lily_parser::get_rest_element (String s, Duration * duration_p)
135 Simultaneous_music* velt_p = new Request_chord;
136 velt_p->set_spot (here_input());
140 Skip_req * skip_p = new Skip_req;
141 skip_p->duration_ = *duration_p;
143 skip_p->set_spot (here_input());
144 velt_p->add_music (skip_p);
148 Rest_req * rest_req_p = new Rest_req;
149 rest_req_p->duration_ = *duration_p;
150 rest_req_p->set_spot (here_input());
152 velt_p->add_music (rest_req_p);
160 My_lily_parser::get_note_element (Note_req *rq, Duration * duration_p)
162 Simultaneous_music*v = new Request_chord;
163 v->set_spot (here_input ());
167 // too bad parser reads (default) duration via member access,
168 // this hack will do for now..
169 if (abbrev_beam_type_i_)
171 assert (!duration_p->plet_b ());
172 duration_p->set_plet (1, 2);
174 rq->set_duration (*duration_p);
175 rq->set_spot (here_input ());
181 My_lily_parser::get_parens_request (int t)
183 Array<Request*>& reqs = *new Array<Request*>;
187 reqs.push (new Tie_req);
192 Plet_req* p = new Plet_req;
193 p->plet_i_ = plet_.type_i_;
200 if (!abbrev_beam_type_i_)
202 reqs.push (new Beam_req);
206 Abbreviation_beam_req* a = new Abbreviation_beam_req;
207 a->type_i_ = abbrev_beam_type_i_;
209 abbrev_beam_type_i_ = 0;
218 reqs.push (new Span_dynamic_req);
224 Plet_req* p = new Plet_req;
225 p->plet_i_ = plet_.type_i_;
232 reqs.push (new Slur_req);
243 reqs.top ()->access_Span_req ()->spantype = Span_req::START;
250 reqs[0]->access_Span_req ()->spantype = Span_req::START;
253 reqs.top ()->access_Span_req ()->spantype = Span_req::STOP;
258 reqs[0]->access_Span_req ()->spantype = Span_req::STOP;
265 for (int i = 0; i < reqs.size (); i++)
266 if (reqs[i]->access_Musical_req ()->access_Span_dynamic_req ())
268 Span_dynamic_req* s_l= (reqs[i]->access_Musical_req ()->access_Span_dynamic_req ()) ;
269 s_l->dynamic_dir_ = (t == '<') ? UP:DOWN;
272 // ugh? don't we do this in the parser too?
273 reqs[0]->set_spot (here_input());
278 My_lily_parser::add_requests (Simultaneous_music*v)
280 for (int i = 0; i < pre_reqs.size(); i++)
282 v->add_music (pre_reqs[i]);
285 for (int i = 0; i <post_reqs.size(); i++)
287 v->add_music (post_reqs[i]);
294 My_lily_parser::pop_spot()
296 return define_spot_array_.pop();
300 My_lily_parser::here_input() const
302 Source_file * f_l= lexer_p_->source_file_l();
303 return Input (f_l, here_ch_C());
307 My_lily_parser::add_notename (String s, Musical_pitch p)
309 lexer_p_->add_notename (s, p);
314 My_lily_parser::default_paper_p ()
316 Identifier *id = lexer_p_->lookup_identifier ("$defaultpaper");
317 return id ? id->access_Paper_def () : new Paper_def ;
321 My_lily_parser::default_midi_p ()
323 Identifier *id = lexer_p_->lookup_identifier ("$defaultmidi");
324 return id ? id->access_Midi_def () : new Midi_def ;