2 my-lily-parser.cc -- implement My_lily_parser
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 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"
20 My_lily_parser::My_lily_parser (Sources * source_l)
25 abbrev_beam_type_i_ = 0;
26 default_abbrev_type_i_ = 0;
27 default_duration_.durlog_i_ = 2;
28 default_octave_i_ = 0;
29 textstyle_str_="roman"; // in lexer?
31 last_duration_mode_b_ = true;
36 My_lily_parser::~My_lily_parser()
39 delete default_header_p_;
44 My_lily_parser::clear_notenames()
46 lexer_p_->clear_notenames();
50 My_lily_parser::set_version_check (bool ig)
52 ignore_version_b_ = ig;
55 My_lily_parser::set_debug()
61 set_yydebug (!monitor->silence (s+"Parser") && check_debug);
62 lexer_p_->set_debug (!monitor->silence (s+"Lexer") && check_debug);
67 My_lily_parser::print_declarations()
74 if (!monitor->silence (s+"Declarations") && check_debug)
76 lexer_p_->print_declarations (init_parse_b_);
82 My_lily_parser::parse_file (String init, String s)
84 lexer_p_ = new My_lily_lexer;
87 *mlog << "Parsing ... ";
91 lexer_p_->new_input (init, source_l_);
96 error ("Found errors in init files");
100 init_parse_b_ = false;
102 lexer_p_->new_input (s , source_l_);
104 print_declarations();
107 if (!define_spot_array_.empty())
109 warning ("Braces don't match.");
115 My_lily_parser::remember_spot()
117 define_spot_array_.push (here_input());
121 My_lily_parser::here_ch_C() const
123 return lexer_p_->here_ch_C();
127 My_lily_parser::parser_error (String s)
129 here_input().error (s);
131 exit (fatal_error_i_);
136 My_lily_parser::set_duration_mode (String s)
139 last_duration_mode_b_ = (s== "LAST");
143 My_lily_parser::set_abbrev_beam (int type_i)
145 abbrev_beam_type_i_ = type_i;
149 My_lily_parser::set_last_abbrev (int type_i)
151 default_abbrev_type_i_ = type_i;
155 My_lily_parser::set_default_duration (Duration const *d)
157 last_duration_mode_b_ = false;
158 default_duration_ = *d;
164 My_lily_parser::set_last_duration (Duration const *d)
166 if (last_duration_mode_b_)
167 default_duration_ = *d;
173 My_lily_parser::get_word_element (Text_def* tdef_p, Duration * duration_p)
175 Chord* velt_p = new Request_chord;
177 Lyric_req* lreq_p = new Lyric_req (tdef_p);
179 lreq_p->duration_ = *duration_p;
180 lreq_p->set_spot (here_input());
182 velt_p->add (lreq_p);
189 My_lily_parser::get_rest_element (String s, Duration * duration_p)
191 Chord* velt_p = new Request_chord;
192 velt_p->set_spot (here_input());
196 Skip_req * skip_p = new Skip_req;
197 skip_p->duration_ = *duration_p;
199 skip_p->set_spot (here_input());
200 velt_p->add (skip_p);
204 Rest_req * rest_req_p = new Rest_req;
205 rest_req_p->duration_ = *duration_p;
206 rest_req_p->set_spot (here_input());
208 velt_p->add (rest_req_p);
216 My_lily_parser::get_note_element (Note_req *rq, Duration * duration_p)
218 Chord*v = new Request_chord;
219 v->set_spot (here_input());
223 // too bad parser reads (default) duration via member access,
224 // this hack will do for now..
225 if (abbrev_beam_type_i_)
227 assert (!duration_p->plet_b ());
228 duration_p->set_plet (1, 2);
230 rq->set_duration (*duration_p);
231 rq->set_spot (here_input());
237 My_lily_parser::get_parens_request (char c)
249 if (!abbrev_beam_type_i_)
251 Beam_req*b = new Beam_req;
252 int p_i=plet_.type_i_ ; // ugh . Should junk?
259 Abbreviation_beam_req* a = new Abbreviation_beam_req;
260 a->type_i_ = abbrev_beam_type_i_;
262 abbrev_beam_type_i_ = 0;
271 req_p = new Span_dynamic_req;
276 req_p = new Slur_req;
289 req_p->span()->spantype = Span_req::START;
294 req_p->span()->spantype = Span_req::STOP;
301 if (req_p->musical()->span_dynamic ())
303 Span_dynamic_req* s_l= (req_p->musical()->span_dynamic ()) ;
304 s_l->dynamic_dir_ = (c == '<') ? UP:DOWN;
307 req_p->set_spot (here_input());
312 My_lily_parser::add_requests (Chord*v)
314 for (int i = 0; i < pre_reqs.size(); i++)
316 v->add (pre_reqs[i]);
319 for (int i = 0; i <post_reqs.size(); i++)
321 v->add (post_reqs[i]);
327 My_lily_parser::pop_spot()
329 return define_spot_array_.pop();
333 My_lily_parser::here_input() const
335 Source_file * f_l= lexer_p_->source_file_l();
336 return Input (f_l, here_ch_C());
340 My_lily_parser::add_notename (String s, Melodic_req * m_p)
342 lexer_p_->add_notename (s, m_p);