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"
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_octave_i_ = 0;
31 textstyle_str_="roman"; // in lexer?
37 My_lily_parser::~My_lily_parser()
40 delete default_header_p_;
45 My_lily_parser::clear_notenames()
47 lexer_p_->clear_notenames();
51 My_lily_parser::set_version_check (bool ig)
53 ignore_version_b_ = ig;
57 My_lily_parser::parse_file (String init, String s)
59 lexer_p_ = new My_lily_lexer;
61 lexer_p_->main_input_str_ = s;
63 *mlog << _("Parsing ... ");
65 init_parse_b_ = false;
66 set_yydebug (!monitor->silent_b ("Parser") && check_debug);
67 lexer_p_->new_input (init, source_l_);
71 if (!define_spot_array_.empty())
73 warning (_("Braces don't match."));
77 inclusion_global_array = lexer_p_->filename_str_arr_;
81 My_lily_parser::remember_spot()
83 define_spot_array_.push (here_input());
87 My_lily_parser::here_ch_C() const
89 return lexer_p_->here_ch_C();
93 My_lily_parser::parser_error (String s)
95 here_input().error (s);
97 exit (fatal_error_i_);
103 My_lily_parser::set_abbrev_beam (int type_i)
105 abbrev_beam_type_i_ = type_i;
110 My_lily_parser::set_last_duration (Duration const *d)
112 default_duration_ = *d;
115 sticky plet factor only within plet brackets
117 default_duration_.set_plet (1, 1);
122 My_lily_parser::get_word_element (Text_def* tdef_p, Duration * duration_p)
124 Chord* velt_p = new Request_chord;
126 Lyric_req* lreq_p = new Lyric_req (tdef_p);
128 lreq_p->duration_ = *duration_p;
129 lreq_p->set_spot (here_input());
131 velt_p->add (lreq_p);
139 My_lily_parser::get_rest_element (String s, Duration * duration_p)
141 Chord* velt_p = new Request_chord;
142 velt_p->set_spot (here_input());
146 Skip_req * skip_p = new Skip_req;
147 skip_p->duration_ = *duration_p;
149 skip_p->set_spot (here_input());
150 velt_p->add (skip_p);
154 Rest_req * rest_req_p = new Rest_req;
155 rest_req_p->duration_ = *duration_p;
156 rest_req_p->set_spot (here_input());
158 velt_p->add (rest_req_p);
166 My_lily_parser::get_note_element (Note_req *rq, Duration * duration_p)
168 Chord*v = new Request_chord;
169 v->set_spot (here_input ());
173 // too bad parser reads (default) duration via member access,
174 // this hack will do for now..
175 if (abbrev_beam_type_i_)
177 assert (!duration_p->plet_b ());
178 duration_p->set_plet (1, 2);
180 rq->set_duration (*duration_p);
181 rq->set_spot (here_input ());
187 My_lily_parser::get_parens_request (int t)
189 Array<Request*>& reqs = *new Array<Request*>;
193 reqs.push (new Tie_req);
198 Plet_req* p = new Plet_req;
199 p->plet_i_ = plet_.type_i_;
206 if (!abbrev_beam_type_i_)
208 reqs.push (new Beam_req);
212 Abbreviation_beam_req* a = new Abbreviation_beam_req;
213 a->type_i_ = abbrev_beam_type_i_;
215 abbrev_beam_type_i_ = 0;
224 reqs.push (new Span_dynamic_req);
230 Plet_req* p = new Plet_req;
231 p->plet_i_ = plet_.type_i_;
238 reqs.push (new Slur_req);
249 reqs.top ()->span()->spantype = Span_req::START;
256 reqs[0]->span ()->spantype = Span_req::START;
259 reqs.top ()->span()->spantype = Span_req::STOP;
264 reqs[0]->span ()->spantype = Span_req::STOP;
271 for (int i = 0; i < reqs.size (); i++)
272 if (reqs[i]->musical ()->span_dynamic ())
274 Span_dynamic_req* s_l= (reqs[i]->musical ()->span_dynamic ()) ;
275 s_l->dynamic_dir_ = (t == '<') ? UP:DOWN;
278 // ugh? don't we do this in the parser too?
279 reqs[0]->set_spot (here_input());
284 My_lily_parser::add_requests (Chord*v)
286 for (int i = 0; i < pre_reqs.size(); i++)
288 v->add (pre_reqs[i]);
291 for (int i = 0; i <post_reqs.size(); i++)
293 v->add (post_reqs[i]);
299 My_lily_parser::pop_spot()
301 return define_spot_array_.pop();
305 My_lily_parser::here_input() const
307 Source_file * f_l= lexer_p_->source_file_l();
308 return Input (f_l, here_ch_C());
312 My_lily_parser::add_notename (String s, Musical_pitch p)
314 lexer_p_->add_notename (s, p);
319 My_lily_parser::default_paper_p ()
321 Identifier *id = lexer_p_->lookup_identifier ("default_paper");
322 return id ? id->paperdef () : new Paper_def ;
326 My_lily_parser::default_midi_p ()
328 Identifier *id = lexer_p_->lookup_identifier ("default_midi");
329 return id ? id->mididef () : new Midi_def ;