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;
35 My_lily_parser::~My_lily_parser()
38 delete default_header_p_;
43 My_lily_parser::clear_notenames()
45 lexer_p_->clear_notenames();
49 My_lily_parser::set_version_check (bool ig)
51 ignore_version_b_ = ig;
55 My_lily_parser::parse_file (String init, String s)
57 lexer_p_ = new My_lily_lexer;
59 lexer_p_->main_input_str_ = s;
61 *mlog << _("Parsing ... ");
63 init_parse_b_ = false;
64 set_yydebug (!monitor->silent_b ("Parser") && check_debug);
65 lexer_p_->new_input (init, source_l_);
69 if (!define_spot_array_.empty())
71 warning (_("Braces don't match."));
75 inclusion_global_array = lexer_p_->filename_str_arr_;
79 My_lily_parser::remember_spot()
81 define_spot_array_.push (here_input());
85 My_lily_parser::here_ch_C() const
87 return lexer_p_->here_ch_C();
91 My_lily_parser::parser_error (String s)
93 here_input().error (s);
95 exit (fatal_error_i_);
101 My_lily_parser::set_duration_mode (String s)
104 last_duration_mode_b_ = (s== "LAST");
108 My_lily_parser::set_abbrev_beam (int type_i)
110 abbrev_beam_type_i_ = type_i;
114 My_lily_parser::set_default_duration (Duration const *d)
116 last_duration_mode_b_ = false;
117 default_duration_ = *d;
122 My_lily_parser::set_last_duration (Duration const *d)
124 if (last_duration_mode_b_)
126 default_duration_ = *d;
129 sticky plet factor only within plet brackets
131 default_duration_.set_plet (1, 1);
137 My_lily_parser::get_word_element (Text_def* tdef_p, Duration * duration_p)
139 Chord* velt_p = new Request_chord;
141 Lyric_req* lreq_p = new Lyric_req (tdef_p);
143 lreq_p->duration_ = *duration_p;
144 lreq_p->set_spot (here_input());
146 velt_p->add (lreq_p);
153 My_lily_parser::get_rest_element (String s, Duration * duration_p)
155 Chord* velt_p = new Request_chord;
156 velt_p->set_spot (here_input());
160 Skip_req * skip_p = new Skip_req;
161 skip_p->duration_ = *duration_p;
163 skip_p->set_spot (here_input());
164 velt_p->add (skip_p);
166 else if ((duration_p->plet_.type_i_ == 1) && (duration_p->plet_.iso_i_ > 1))
168 Multi_measure_rest_req* m = new Multi_measure_rest_req;
169 // these shouldn't be necessary anymore
171 // default_duration_.plet_.iso_i_ = 1;
172 m->duration_ = *duration_p;
173 m->set_spot (here_input());
178 Rest_req * rest_req_p = new Rest_req;
179 rest_req_p->duration_ = *duration_p;
180 rest_req_p->set_spot (here_input());
182 velt_p->add (rest_req_p);
190 My_lily_parser::get_note_element (Note_req *rq, Duration * duration_p)
192 Chord*v = new Request_chord;
193 v->set_spot (here_input ());
197 // too bad parser reads (default) duration via member access,
198 // this hack will do for now..
199 if (abbrev_beam_type_i_)
201 assert (!duration_p->plet_b ());
202 duration_p->set_plet (1, 2);
204 rq->set_duration (*duration_p);
205 rq->set_spot (here_input ());
211 My_lily_parser::get_parens_request (int t)
213 Array<Request*>& reqs = *new Array<Request*>;
217 reqs.push (new Tie_req);
222 Plet_req* p = new Plet_req;
223 p->plet_i_ = plet_.type_i_;
230 if (!abbrev_beam_type_i_)
232 reqs.push (new Beam_req);
236 Abbreviation_beam_req* a = new Abbreviation_beam_req;
237 a->type_i_ = abbrev_beam_type_i_;
239 abbrev_beam_type_i_ = 0;
248 reqs.push (new Span_dynamic_req);
254 Plet_req* p = new Plet_req;
255 p->plet_i_ = plet_.type_i_;
262 reqs.push (new Slur_req);
273 reqs.top ()->span()->spantype = Span_req::START;
280 reqs[0]->span ()->spantype = Span_req::START;
283 reqs.top ()->span()->spantype = Span_req::STOP;
288 reqs[0]->span ()->spantype = Span_req::STOP;
295 for (int i = 0; i < reqs.size (); i++)
296 if (reqs[i]->musical ()->span_dynamic ())
298 Span_dynamic_req* s_l= (reqs[i]->musical ()->span_dynamic ()) ;
299 s_l->dynamic_dir_ = (t == '<') ? UP:DOWN;
302 // ugh? don't we do this in the parser too?
303 reqs[0]->set_spot (here_input());
308 My_lily_parser::add_requests (Chord*v)
310 for (int i = 0; i < pre_reqs.size(); i++)
312 v->add (pre_reqs[i]);
315 for (int i = 0; i <post_reqs.size(); i++)
317 v->add (post_reqs[i]);
323 My_lily_parser::pop_spot()
325 return define_spot_array_.pop();
329 My_lily_parser::here_input() const
331 Source_file * f_l= lexer_p_->source_file_l();
332 return Input (f_l, here_ch_C());
336 My_lily_parser::add_notename (String s, Melodic_req * m_p)
338 lexer_p_->add_notename (s, m_p);