2 my-lily-parser.cc -- implement My_lily_parser
4 source file of the 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 "voice-element.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);
40 My_lily_parser::print_declarations()
46 if (!monitor->silence(s+"Declarations") && check_debug) {
47 lexer_p_->print_declarations(init_parse_b_);
53 My_lily_parser::do_init_file()
57 lexer_p_->new_input(init_str_, source_l_);
61 My_lily_parser::parse_file(String init, String s)
63 *mlog << "Parsing ... ";
64 lexer_p_ = new My_lily_lexer;
67 lexer_p_->new_input(s, source_l_);
71 if(!define_spot_array_.empty())
72 warning("Braces don't match.");
75 My_lily_parser::~My_lily_parser()
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_ );
102 My_lily_parser::set_duration_mode(String s)
105 last_duration_mode = (s== "LAST");
109 My_lily_parser::set_last_duration(Duration const *d)
111 if (last_duration_mode)
112 default_duration_ = *d;
117 My_lily_parser::get_word_element(Text_def* tdef_p, Duration * duration_p)
119 Voice_element* velt_p = new Voice_element;
121 Lyric_req* lreq_p = new Lyric_req(tdef_p);
123 lreq_p->duration_ = *duration_p;
124 lreq_p->set_spot( here_input());
133 My_lily_parser::get_rest_element(String, Duration * duration_p )
135 Voice_element* velt_p = new Voice_element;
136 velt_p->set_spot( here_input());
138 Rest_req * rest_req_p = new Rest_req;
139 rest_req_p->duration_ = *duration_p;
140 rest_req_p->set_spot( here_input());
142 velt_p->add(rest_req_p);
144 Stem_req * stem_p = new Stem_req;
145 stem_p->duration_ = *duration_p;
146 stem_p->set_spot ( here_input ());
153 My_lily_parser::get_note_element(Note_req *rq, Duration * duration_p )
155 Voice_element*v = new Voice_element;
156 v->set_spot( here_input());
160 if (duration_p->type_i_ >= 2) {
161 Stem_req * stem_req_p = new Stem_req();
162 stem_req_p->duration_ = *duration_p;
164 stem_req_p->set_spot( here_input());
168 rq->set_duration(*duration_p);
169 rq->set_spot( here_input());
175 My_lily_parser::get_parens_request(char c)
183 Beam_req*b = new Beam_req;
184 int p_i=default_duration_.plet_.type_i_ ; // ugh . Should junk?
194 req_p = new Span_dynamic_req;
199 req_p = new Slur_req;
211 req_p->span()->spantype = Span_req::START;
216 req_p->span()->spantype = Span_req::STOP;
223 if (req_p->musical()->span_dynamic()) {
224 Span_dynamic_req* s_l= (req_p->musical()->span_dynamic()) ;
225 s_l->dynamic_dir_i_ = (c == '<') ? 1:-1;
228 req_p->set_spot( here_input());
232 My_lily_parser::My_lily_parser(Sources * source_l)
235 source_l_ = source_l;
237 default_duration_.type_i_ = 4;
238 default_octave_i_ = 0;
239 textstyle_str_="roman"; // in lexer?
241 last_duration_mode = false;
246 My_lily_parser::add_requests(Voice_element*v)
248 for (int i = 0; i < pre_reqs.size(); i++) {
251 pre_reqs.set_size(0);
252 for (int i = 0; i <post_reqs.size(); i++) {
253 v->add(post_reqs[i]);
255 post_reqs.set_size(0);
259 My_lily_parser::pop_spot()
261 return define_spot_array_.pop();
265 My_lily_parser::here_input()const
267 Source_file * f_l= lexer_p_->source_file_l();
268 return Input(f_l, here_ch_C());
272 My_lily_parser::add_notename(String s, Melodic_req * m_p)
274 lexer_p_->add_notename(s, m_p);