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_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;
54 My_lily_parser::set_debug()
60 set_yydebug (!monitor->silence (s+"Parser") && check_debug);
61 lexer_p_->set_debug (!monitor->silence (s+"Lexer") && check_debug);
66 My_lily_parser::print_declarations()
73 if (!monitor->silence (s+"Declarations") && check_debug)
75 lexer_p_->print_declarations (init_parse_b_);
81 My_lily_parser::parse_file (String init, String s)
83 lexer_p_ = new My_lily_lexer;
86 *mlog << "Parsing ... ";
90 lexer_p_->new_input (init, source_l_);
95 error ("Found errors in init files");
99 init_parse_b_ = false;
101 lexer_p_->new_input (s , source_l_);
103 print_declarations();
106 if (!define_spot_array_.empty())
108 warning ("Braces don't match.");
114 My_lily_parser::remember_spot()
116 define_spot_array_.push (here_input());
120 My_lily_parser::here_ch_C() const
122 return lexer_p_->here_ch_C();
126 My_lily_parser::parser_error (String s)
128 here_input().error (s);
130 exit (fatal_error_i_);
135 My_lily_parser::set_duration_mode (String s)
138 last_duration_mode_b_ = (s== "LAST");
142 My_lily_parser::set_abbrev_beam (int type_i)
144 abbrev_beam_type_i_ = type_i;
148 My_lily_parser::set_default_duration (Duration const *d)
150 last_duration_mode_b_ = false;
151 default_duration_ = *d;
156 My_lily_parser::set_last_duration (Duration const *d)
158 if (last_duration_mode_b_)
159 default_duration_ = *d;
164 My_lily_parser::get_word_element (Text_def* tdef_p, Duration * duration_p)
166 Chord* velt_p = new Request_chord;
168 Lyric_req* lreq_p = new Lyric_req (tdef_p);
170 lreq_p->duration_ = *duration_p;
171 lreq_p->set_spot (here_input());
173 velt_p->add (lreq_p);
180 My_lily_parser::get_rest_element (String s, Duration * duration_p)
182 Chord* velt_p = new Request_chord;
183 velt_p->set_spot (here_input());
187 Skip_req * skip_p = new Skip_req;
188 skip_p->duration_ = *duration_p;
190 skip_p->set_spot (here_input());
191 velt_p->add (skip_p);
195 Rest_req * rest_req_p = new Rest_req;
196 rest_req_p->duration_ = *duration_p;
197 rest_req_p->set_spot (here_input());
199 velt_p->add (rest_req_p);
207 My_lily_parser::get_note_element (Note_req *rq, Duration * duration_p)
209 Chord*v = new Request_chord;
210 v->set_spot (here_input ());
214 // too bad parser reads (default) duration via member access,
215 // this hack will do for now..
216 if (abbrev_beam_type_i_)
218 assert (!duration_p->plet_b ());
219 duration_p->set_plet (1, 2);
221 rq->set_duration (*duration_p);
222 rq->set_spot (here_input ());
228 My_lily_parser::get_parens_request (char c)
240 if (!abbrev_beam_type_i_)
242 Beam_req*b = new Beam_req;
243 int p_i=plet_.type_i_ ; // ugh . Should junk?
250 Abbreviation_beam_req* a = new Abbreviation_beam_req;
251 a->type_i_ = abbrev_beam_type_i_;
253 abbrev_beam_type_i_ = 0;
262 req_p = new Span_dynamic_req;
267 req_p = new Slur_req;
280 req_p->span()->spantype = Span_req::START;
285 req_p->span()->spantype = Span_req::STOP;
292 if (req_p->musical()->span_dynamic ())
294 Span_dynamic_req* s_l= (req_p->musical()->span_dynamic ()) ;
295 s_l->dynamic_dir_ = (c == '<') ? UP:DOWN;
298 req_p->set_spot (here_input());
303 My_lily_parser::add_requests (Chord*v)
305 for (int i = 0; i < pre_reqs.size(); i++)
307 v->add (pre_reqs[i]);
310 for (int i = 0; i <post_reqs.size(); i++)
312 v->add (post_reqs[i]);
318 My_lily_parser::pop_spot()
320 return define_spot_array_.pop();
324 My_lily_parser::here_input() const
326 Source_file * f_l= lexer_p_->source_file_l();
327 return Input (f_l, here_ch_C());
331 My_lily_parser::add_notename (String s, Melodic_req * m_p)
333 lexer_p_->add_notename (s, m_p);