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"
18 My_lily_parser::set_debug()
24 set_yydebug( !monitor->silence(s+"Parser") && check_debug);
25 lexer_p_->set_debug( !monitor->silence(s+"Lexer") && check_debug);
29 My_lily_parser::print_declarations()
35 if (!monitor->silence(s+"Declarations") && check_debug) {
36 lexer_p_->print_declarations(init_parse_b_);
42 My_lily_parser::parse_file(String init, String s)
44 *mlog << "Parsing ... ";
45 lexer_p_ = new My_lily_lexer;
50 lexer_p_->new_input(init, source_l_);
54 init_parse_b_ = false;
56 lexer_p_->new_input(s, source_l_);
60 if(!define_spot_array_.empty())
61 warning("Braces don't match.");
64 My_lily_parser::~My_lily_parser()
70 My_lily_parser::remember_spot()
72 define_spot_array_.push(here_input());
76 My_lily_parser::here_ch_C()const
78 return lexer_p_->here_ch_C();
82 My_lily_parser::parser_error(String s)
84 lexer_p_->LexerError(s);
87 exit( fatal_error_i_ );
92 My_lily_parser::set_duration_mode(String s)
95 last_duration_mode = (s== "LAST");
99 My_lily_parser::set_last_duration(Duration const *d)
101 if (last_duration_mode)
102 default_duration_ = *d;
107 My_lily_parser::get_word_element(Text_def* tdef_p, Duration * duration_p)
109 Voice_element* velt_p = new Voice_element;
111 Lyric_req* lreq_p = new Lyric_req(tdef_p);
113 lreq_p->duration_ = *duration_p;
114 lreq_p->set_spot( here_input());
123 My_lily_parser::get_rest_element(String, Duration * duration_p )
125 Voice_element* velt_p = new Voice_element;
126 velt_p->set_spot( here_input());
128 Rest_req * rest_req_p = new Rest_req;
129 rest_req_p->duration_ = *duration_p;
130 rest_req_p->set_spot( here_input());
132 velt_p->add(rest_req_p);
138 My_lily_parser::get_note_element(Note_req *rq, Duration * duration_p )
140 Voice_element*v = new Voice_element;
141 v->set_spot( here_input());
143 if (duration_p->type_i_ >= 2) {
144 Stem_req * stem_req_p = new Stem_req();
145 stem_req_p->duration_ = *duration_p;
147 stem_req_p->set_spot( here_input());
151 rq->set_duration(*duration_p);
152 rq->set_spot( here_input());
161 My_lily_parser::get_parens_request(char c)
166 req_p = new Barcheck_req;
172 Beam_req*b = new Beam_req;
173 int p_i=default_duration_.plet_.type_i_ ; // ugh . Should junk?
183 req_p = new Slur_req;
193 req_p->span()->spantype = Span_req::START;
197 req_p->span()->spantype = Span_req::STOP;
204 req_p->set_spot( here_input());
208 My_lily_parser::My_lily_parser(Sources * source_l)
210 source_l_ = source_l;
212 default_duration_.type_i_ = 4;
213 default_octave_i_ = 0;
214 textstyle_str_="roman"; // in lexer?
216 last_duration_mode = false;
221 My_lily_parser::add_requests(Voice_element*v)
223 for (int i = 0; i < pre_reqs.size(); i++) {
226 pre_reqs.set_size(0);
227 for (int i = 0; i <post_reqs.size(); i++) {
228 v->add(post_reqs[i]);
230 post_reqs.set_size(0);
234 My_lily_parser::pop_spot()
236 return define_spot_array_.pop();
240 My_lily_parser::here_input()const
242 Source_file * f_l= lexer_p_->source_file_l();
243 return Input(f_l, here_ch_C());