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();
25 My_lily_parser::set_debug()
31 set_yydebug( !monitor->silence(s+"Parser") && check_debug);
32 lexer_p_->set_debug( !monitor->silence(s+"Lexer") && check_debug);
36 My_lily_parser::print_declarations()
42 if (!monitor->silence(s+"Declarations") && check_debug) {
43 lexer_p_->print_declarations(init_parse_b_);
49 My_lily_parser::parse_file(String init, String s)
51 *mlog << "Parsing ... ";
52 lexer_p_ = new My_lily_lexer;
57 lexer_p_->new_input(init, source_l_);
61 init_parse_b_ = false;
63 lexer_p_->new_input(s, source_l_);
67 if(!define_spot_array_.empty())
68 warning("Braces don't match.");
71 My_lily_parser::~My_lily_parser()
77 My_lily_parser::remember_spot()
79 define_spot_array_.push(here_input());
83 My_lily_parser::here_ch_C()const
85 return lexer_p_->here_ch_C();
89 My_lily_parser::parser_error(String s)
91 here_input().error(s);
93 exit( fatal_error_i_ );
98 My_lily_parser::set_duration_mode(String s)
101 last_duration_mode = (s== "LAST");
105 My_lily_parser::set_last_duration(Duration const *d)
107 if (last_duration_mode)
108 default_duration_ = *d;
113 My_lily_parser::get_word_element(Text_def* tdef_p, Duration * duration_p)
115 Voice_element* velt_p = new Voice_element;
117 Lyric_req* lreq_p = new Lyric_req(tdef_p);
119 lreq_p->duration_ = *duration_p;
120 lreq_p->set_spot( here_input());
129 My_lily_parser::get_rest_element(String, Duration * duration_p )
131 Voice_element* velt_p = new Voice_element;
132 velt_p->set_spot( here_input());
134 Rest_req * rest_req_p = new Rest_req;
135 rest_req_p->duration_ = *duration_p;
136 rest_req_p->set_spot( here_input());
138 velt_p->add(rest_req_p);
144 My_lily_parser::get_note_element(Note_req *rq, Duration * duration_p )
146 Voice_element*v = new Voice_element;
147 v->set_spot( here_input());
149 if (duration_p->type_i_ >= 2) {
150 Stem_req * stem_req_p = new Stem_req();
151 stem_req_p->duration_ = *duration_p;
153 stem_req_p->set_spot( here_input());
157 rq->set_duration(*duration_p);
158 rq->set_spot( here_input());
167 My_lily_parser::get_parens_request(char c)
175 Beam_req*b = new Beam_req;
176 int p_i=default_duration_.plet_.type_i_ ; // ugh . Should junk?
186 req_p = new Span_dynamic_req;
191 req_p = new Slur_req;
203 req_p->span()->spantype = Span_req::START;
208 req_p->span()->spantype = Span_req::STOP;
215 if (req_p->musical()->span_dynamic()) {
216 Span_dynamic_req* s_l= (req_p->musical()->span_dynamic()) ;
217 s_l->dynamic_dir_i_ = (c == '<') ? 1:-1;
220 req_p->set_spot( here_input());
224 My_lily_parser::My_lily_parser(Sources * source_l)
226 source_l_ = source_l;
228 default_duration_.type_i_ = 4;
229 default_octave_i_ = 0;
230 textstyle_str_="roman"; // in lexer?
232 last_duration_mode = false;
237 My_lily_parser::add_requests(Voice_element*v)
239 for (int i = 0; i < pre_reqs.size(); i++) {
242 pre_reqs.set_size(0);
243 for (int i = 0; i <post_reqs.size(); i++) {
244 v->add(post_reqs[i]);
246 post_reqs.set_size(0);
250 My_lily_parser::pop_spot()
252 return define_spot_array_.pop();
256 My_lily_parser::here_input()const
258 Source_file * f_l= lexer_p_->source_file_l();
259 return Input(f_l, here_ch_C());
263 My_lily_parser::add_notename(String s, Melodic_req * m_p)
265 lexer_p_->add_notename(s, m_p);