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->duration_ = *duration_p;
175 rq->set_spot (here_input ());
185 My_lily_parser::get_parens_request (int t)
187 Array<Request*>& reqs = *new Array<Request*>;
191 reqs.push (new Tie_req);
196 Plet_req* p = new Plet_req;
197 p->plet_i_ = plet_.type_i_;
204 if (!abbrev_beam_type_i_)
206 reqs.push (new Beam_req);
210 Abbreviation_beam_req* a = new Abbreviation_beam_req;
211 a->type_i_ = abbrev_beam_type_i_;
213 abbrev_beam_type_i_ = 0;
222 reqs.push (new Span_dynamic_req);
228 Plet_req* p = new Plet_req;
229 p->plet_i_ = plet_.type_i_;
236 reqs.push (new Slur_req);
247 dynamic_cast<Span_req*> (reqs.top ())->spantype = Span_req::START;
254 dynamic_cast<Span_req*> (reqs.top ())->spantype = Span_req::START;
257 dynamic_cast<Span_req*> (reqs.top ())->spantype = Span_req::STOP;
262 dynamic_cast<Span_req*> (reqs[0])->spantype = Span_req::STOP;
269 for (int i = 0; i < reqs.size (); i++)
270 if (dynamic_cast<Span_dynamic_req*> (reqs[i]))
272 Span_dynamic_req* s_l= dynamic_cast<Span_dynamic_req*> (reqs[i]);
273 s_l->dynamic_dir_ = (t == '<') ? UP:DOWN;
276 // ugh? don't we do this in the parser too?
277 reqs[0]->set_spot (here_input());
282 My_lily_parser::add_requests (Simultaneous_music*v)
284 for (int i = 0; i < pre_reqs.size(); i++)
286 v->add_music (pre_reqs[i]);
289 for (int i = 0; i <post_reqs.size(); i++)
291 v->add_music (post_reqs[i]);
298 My_lily_parser::pop_spot()
300 return define_spot_array_.pop();
304 My_lily_parser::here_input() const
306 Source_file * f_l= lexer_p_->source_file_l();
307 return Input (f_l, here_ch_C());
311 My_lily_parser::add_notename (String s, Musical_pitch p)
313 lexer_p_->add_notename (s, p);
318 My_lily_parser::default_paper_p ()
320 Identifier *id = lexer_p_->lookup_identifier ("$defaultpaper");
321 return id ? id->access_content_Paper_def (true) : new Paper_def ;
325 My_lily_parser::default_midi_p ()
327 Identifier *id = lexer_p_->lookup_identifier ("$defaultmidi");
328 return id ? id->access_content_Midi_def (true) : new Midi_def ;