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"
19 My_lily_parser::clear_notenames()
21 lexer_p_->clear_notenames();
24 My_lily_parser::set_version_check(bool ig)
26 ignore_version_b_ = ig;
29 My_lily_parser::set_debug()
35 set_yydebug( !monitor->silence(s+"Parser") && check_debug);
36 lexer_p_->set_debug( !monitor->silence(s+"Lexer") && check_debug);
41 My_lily_parser::print_declarations()
47 if (!monitor->silence(s+"Declarations") && check_debug) {
48 lexer_p_->print_declarations(init_parse_b_);
54 My_lily_parser::do_init_file()
58 lexer_p_->new_input(init_str_, source_l_);
62 My_lily_parser::parse_file(String init, String s)
64 lexer_p_ = new My_lily_lexer;
69 *mlog << "Parsing ... ";
70 lexer_p_->new_input(s, source_l_);
71 if (!lexer_p_->source_file_l()) {
72 warning("Can not find toplevel file. Ignoring " + s);
78 if(!define_spot_array_.empty())
79 warning("Braces don't match.");
82 My_lily_parser::~My_lily_parser()
88 My_lily_parser::remember_spot()
90 define_spot_array_.push(here_input());
94 My_lily_parser::here_ch_C()const
96 return lexer_p_->here_ch_C();
100 My_lily_parser::parser_error(String s)
102 here_input().error(s);
103 if ( fatal_error_i_ )
104 exit( fatal_error_i_ );
109 My_lily_parser::set_duration_mode(String s)
112 last_duration_mode_b_ = (s== "LAST");
116 My_lily_parser::set_default_duration(Duration const *d)
118 last_duration_mode_b_ = false;
119 default_duration_ = *d;
124 My_lily_parser::set_last_duration(Duration const *d)
126 if (last_duration_mode_b_)
127 default_duration_ = *d;
132 My_lily_parser::get_word_element(Text_def* tdef_p, Duration * duration_p)
134 Chord* velt_p = new Voice_element;
136 Lyric_req* lreq_p = new Lyric_req(tdef_p);
138 lreq_p->duration_ = *duration_p;
139 lreq_p->set_spot( here_input());
148 My_lily_parser::get_rest_element(String s, Duration * duration_p )
150 Chord* velt_p = new Voice_element;
151 velt_p->set_spot( here_input());
153 if (s=="s") { /* Space */
154 Skip_req * skip_p = new Skip_req;
155 skip_p->duration_ = *duration_p;
157 skip_p->set_spot( here_input());
161 Rest_req * rest_req_p = new Rest_req;
162 rest_req_p->duration_ = *duration_p;
163 rest_req_p->set_spot( here_input());
165 velt_p->add(rest_req_p);
167 Stem_req * stem_p = new Stem_req;
168 stem_p->duration_ = *duration_p;
169 stem_p->set_spot ( here_input ());
177 My_lily_parser::get_note_element(Note_req *rq, Duration * duration_p )
179 Chord*v = new Voice_element;
180 v->set_spot( here_input());
184 if (duration_p->type_i_ >= 2) {
185 Stem_req * stem_req_p = new Stem_req();
186 stem_req_p->duration_ = *duration_p;
188 stem_req_p->set_spot( here_input());
192 rq->set_duration(*duration_p);
193 rq->set_spot( here_input());
199 My_lily_parser::get_parens_request(char c)
210 Beam_req*b = new Beam_req;
211 int p_i=default_duration_.plet_.type_i_ ; // ugh . Should junk?
221 req_p = new Span_dynamic_req;
226 req_p = new Slur_req;
238 req_p->span()->spantype = Span_req::START;
243 req_p->span()->spantype = Span_req::STOP;
250 if (req_p->musical()->span_dynamic()) {
251 Span_dynamic_req* s_l= (req_p->musical()->span_dynamic()) ;
252 s_l->dynamic_dir_i_ = (c == '<') ? 1:-1;
255 req_p->set_spot( here_input());
259 My_lily_parser::My_lily_parser(Sources * source_l)
262 source_l_ = source_l;
264 default_duration_.type_i_ = 4;
265 default_octave_i_ = 0;
266 textstyle_str_="roman"; // in lexer?
268 last_duration_mode_b_ = true;
273 My_lily_parser::add_requests(Chord*v)
275 for (int i = 0; i < pre_reqs.size(); i++) {
278 pre_reqs.set_size(0);
279 for (int i = 0; i <post_reqs.size(); i++) {
280 v->add(post_reqs[i]);
282 post_reqs.set_size(0);
286 My_lily_parser::pop_spot()
288 return define_spot_array_.pop();
292 My_lily_parser::here_input()const
294 Source_file * f_l= lexer_p_->source_file_l();
295 return Input(f_l, here_ch_C());
299 My_lily_parser::add_notename(String s, Melodic_req * m_p)
301 lexer_p_->add_notename(s, m_p);