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@stack.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"
20 My_lily_parser::My_lily_parser (Sources * source_l)
25 abbrev_beam_type_i_ = 0;
26 default_duration_.durlog_i_ = 2;
27 default_octave_i_ = 0;
28 textstyle_str_="roman"; // in lexer?
30 last_duration_mode_b_ = true;
34 relative_octave_mode_b_ = false;
36 last_melodic_ = new Melodic_req;
37 last_melodic_->octave_i_ = 0; // -1; // huh?
38 last_melodic_->notename_i_ = 0;
39 last_melodic_->accidental_i_ = 0;
42 My_lily_parser::~My_lily_parser()
45 delete default_header_p_;
50 My_lily_parser::clear_notenames()
52 lexer_p_->clear_notenames();
56 My_lily_parser::set_version_check (bool ig)
58 ignore_version_b_ = ig;
62 My_lily_parser::parse_file (String init, String s)
64 lexer_p_ = new My_lily_lexer;
66 lexer_p_->main_input_str_ = s;
68 *mlog << _("Parsing ... ");
70 init_parse_b_ = false;
71 set_yydebug (!monitor->silent_b ("Parser") && check_debug);
72 lexer_p_->new_input (init, source_l_);
76 if (!define_spot_array_.empty())
78 warning (_("Braces don't match."));
82 inclusion_global_array = lexer_p_->filename_str_arr_;
86 My_lily_parser::remember_spot()
88 define_spot_array_.push (here_input());
92 My_lily_parser::here_ch_C() const
94 return lexer_p_->here_ch_C();
98 My_lily_parser::parser_error (String s)
100 here_input().error (s);
102 exit (fatal_error_i_);
108 My_lily_parser::set_duration_mode (String s)
111 last_duration_mode_b_ = (s== "LAST");
115 My_lily_parser::set_octave_mode (String s)
120 relative_octave_mode_b_ = true;
122 last_melodic_ = new Melodic_req;
123 last_melodic_->octave_i_ = 0; // -1; // huh?
124 last_melodic_->notename_i_ = 0;
125 last_melodic_->accidental_i_ = 0;
128 relative_octave_mode_b_ = false;
132 My_lily_parser::set_abbrev_beam (int type_i)
134 abbrev_beam_type_i_ = type_i;
138 My_lily_parser::set_default_duration (Duration const *d)
140 last_duration_mode_b_ = false;
141 default_duration_ = *d;
146 My_lily_parser::set_last_duration (Duration const *d)
148 if (last_duration_mode_b_)
150 default_duration_ = *d;
153 sticky plet factor only within plet brackets
155 default_duration_.set_plet (1, 1);
160 My_lily_parser::notename_str (Melodic_req* melodic)
163 String str ((char)('a' + ((melodic->notename_i_ + 2) % 7)));
164 int i = melodic->accidental_i_;
174 My_lily_parser::get_melodic_req (Melodic_req* melodic, int quotes)
176 if (relative_octave_mode_b_)
178 set_nearest (melodic);
179 int d = melodic->pitch () - last_melodic_->pitch ();
180 if (quotes && (sign (d) == sign (quotes)))
181 quotes -= sign (quotes);
182 melodic->octave_i_ += quotes;
186 Melodic_req nearest (*melodic);
187 set_nearest (&nearest);
188 melodic->octave_i_ += quotes;
190 if (find_quarts_global_b)
192 int e = melodic->pitch () - nearest.pitch ();
195 int d = melodic->pitch () - last_melodic_->pitch ();
196 String str = _("Interval bigger than quart");
197 int n = 1 + (abs (d) - 1) / 12;
198 String quote_str ('\'', n);
200 str += d < 0 ? _(", prepend: ") : _(", append: ");
203 str += _(", relative: ");
204 String name_str = notename_str (melodic);
205 str += d < 0 ? quote_str + name_str : name_str + quote_str;
207 melodic->warning (str);
211 delete last_melodic_;
212 last_melodic_ = melodic->clone ()->musical ()->melodic ();
217 My_lily_parser::set_nearest (Melodic_req* melodic)
219 melodic->octave_i_ = last_melodic_->octave_i_;
220 int d = melodic->pitch () - last_melodic_->pitch ();
222 melodic->octave_i_ -= sign (d);
226 My_lily_parser::get_word_element (Text_def* tdef_p, Duration * duration_p)
228 Chord* velt_p = new Request_chord;
230 Lyric_req* lreq_p = new Lyric_req (tdef_p);
232 lreq_p->duration_ = *duration_p;
233 lreq_p->set_spot (here_input());
235 velt_p->add (lreq_p);
243 My_lily_parser::get_rest_element (String s, Duration * duration_p)
245 Chord* velt_p = new Request_chord;
246 velt_p->set_spot (here_input());
250 Skip_req * skip_p = new Skip_req;
251 skip_p->duration_ = *duration_p;
253 skip_p->set_spot (here_input());
254 velt_p->add (skip_p);
258 Rest_req * rest_req_p = new Rest_req;
259 rest_req_p->duration_ = *duration_p;
260 rest_req_p->set_spot (here_input());
262 velt_p->add (rest_req_p);
270 My_lily_parser::get_note_element (Note_req *rq, Duration * duration_p)
272 Chord*v = new Request_chord;
273 v->set_spot (here_input ());
277 // too bad parser reads (default) duration via member access,
278 // this hack will do for now..
279 if (abbrev_beam_type_i_)
281 assert (!duration_p->plet_b ());
282 duration_p->set_plet (1, 2);
284 rq->set_duration (*duration_p);
285 rq->set_spot (here_input ());
291 My_lily_parser::get_parens_request (int t)
293 Array<Request*>& reqs = *new Array<Request*>;
297 reqs.push (new Tie_req);
302 Plet_req* p = new Plet_req;
303 p->plet_i_ = plet_.type_i_;
310 if (!abbrev_beam_type_i_)
312 reqs.push (new Beam_req);
316 Abbreviation_beam_req* a = new Abbreviation_beam_req;
317 a->type_i_ = abbrev_beam_type_i_;
319 abbrev_beam_type_i_ = 0;
328 reqs.push (new Span_dynamic_req);
334 Plet_req* p = new Plet_req;
335 p->plet_i_ = plet_.type_i_;
342 reqs.push (new Slur_req);
353 reqs.top ()->span()->spantype = Span_req::START;
360 reqs[0]->span ()->spantype = Span_req::START;
363 reqs.top ()->span()->spantype = Span_req::STOP;
368 reqs[0]->span ()->spantype = Span_req::STOP;
375 for (int i = 0; i < reqs.size (); i++)
376 if (reqs[i]->musical ()->span_dynamic ())
378 Span_dynamic_req* s_l= (reqs[i]->musical ()->span_dynamic ()) ;
379 s_l->dynamic_dir_ = (t == '<') ? UP:DOWN;
382 // ugh? don't we do this in the parser too?
383 reqs[0]->set_spot (here_input());
388 My_lily_parser::add_requests (Chord*v)
390 for (int i = 0; i < pre_reqs.size(); i++)
392 v->add (pre_reqs[i]);
395 for (int i = 0; i <post_reqs.size(); i++)
397 v->add (post_reqs[i]);
403 My_lily_parser::pop_spot()
405 return define_spot_array_.pop();
409 My_lily_parser::here_input() const
411 Source_file * f_l= lexer_p_->source_file_l();
412 return Input (f_l, here_ch_C());
416 My_lily_parser::add_notename (String s, Melodic_req * m_p)
418 lexer_p_->add_notename (s, m_p);