lilypond-1.3.28
[lilypond.git] / lily / my-lily-parser.cc
blob854f846c1b898735f66ddbdae2686fae3acc8e7e
1 /*
2 my-lily-parser.cc -- implement My_lily_parser
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
8 */
10 #include "my-lily-parser.hh"
11 #include "my-lily-lexer.hh"
12 #include "debug.hh"
13 #include "main.hh"
14 #include "music-list.hh"
15 #include "musical-request.hh"
16 #include "command-request.hh"
17 #include "lily-guile.hh"
18 #include "parser.hh"
19 #include "scope.hh"
20 #include "file-results.hh"
21 #include "midi-def.hh"
22 #include "paper-def.hh"
23 #include "identifier.hh"
24 #include "chord.hh"
26 My_lily_parser::My_lily_parser (Sources * source_l)
28 first_b_ = true;
29 source_l_ = source_l;
30 lexer_p_ = 0;
31 abbrev_beam_type_i_ = 0;
32 default_duration_.durlog_i_ = 2;
33 error_level_i_ = 0;
35 fatal_error_i_ = 0;
36 default_header_p_ =0;
39 My_lily_parser::~My_lily_parser()
41 delete lexer_p_;
42 delete default_header_p_;
45 void
46 My_lily_parser::set_version_check (bool ig)
48 ignore_version_b_ = ig;
51 void
52 My_lily_parser::parse_file (String init, String s)
54 lexer_p_ = new My_lily_lexer;
55 init_str_ = init;
56 lexer_p_->main_input_str_ = s;
58 progress_indication (_("Parsing..."));
60 init_parse_b_ = false;
61 set_yydebug (flower_dstream &&!flower_dstream->silent_b ("Parser"));
62 lexer_p_->new_input (init, source_l_);
63 do_yyparse ();
65 if (!define_spot_array_.empty())
67 warning (_ ("Braces don't match"));
68 error_level_i_ = 1;
71 inclusion_global_array = lexer_p_->filename_str_arr_;
73 error_level_i_ = error_level_i_ | lexer_p_->errorlevel_i_; // ugh naming.
76 void
77 My_lily_parser::remember_spot()
79 define_spot_array_.push (here_input());
82 char const *
83 My_lily_parser::here_ch_C() const
85 return lexer_p_->here_ch_C();
88 void
89 My_lily_parser::parser_error (String s)
91 here_input().error (s);
92 if (fatal_error_i_)
93 exit (fatal_error_i_);
94 error_level_i_ = 1;
95 exit_status_i_ = 1;
98 void
99 My_lily_parser::set_last_duration (Duration const *d)
101 default_duration_ = *d;
104 void
105 My_lily_parser::set_abbrev_beam (int type_i)
107 abbrev_beam_type_i_ = type_i;
113 // junk me
114 Simultaneous_music *
115 My_lily_parser::get_chord (Musical_pitch tonic, Array<Musical_pitch>* add_arr_p, Array<Musical_pitch>* sub_arr_p, Musical_pitch* inversion_p, Musical_pitch* bass_p, Duration d)
117 Simultaneous_music*v = new Request_chord;
118 v->set_spot (here_input ());
121 UARGAUGRAGRUAUGRUINAGRAUGIRNA
125 Chord chord = to_chord (tonic, add_arr_p, sub_arr_p, inversion_p, bass_p);
127 Tonic_req* t = new Tonic_req;
128 t->pitch_ = tonic;
129 v->add_music (t);
131 //urg
132 if (inversion_p
133 && Chord::find_notename_i (&chord.pitch_arr_, *inversion_p) > 0)
135 Inversion_req* i = new Inversion_req;
136 i->pitch_ = *inversion_p;
137 v->add_music (i);
140 if (bass_p)
142 Bass_req* b = new Bass_req;
143 b->pitch_ = *bass_p;
144 v->add_music (b);
147 Array<Musical_pitch> pitch_arr = chord.to_pitch_arr ();
148 for (int i = 0; i < pitch_arr.size (); i++)
150 Musical_pitch p = pitch_arr[i];
151 Note_req* n = new Note_req;
152 n->pitch_ = p;
153 n->duration_ = d;
154 v->add_music (n);
157 return v;
162 Input
163 My_lily_parser::pop_spot()
165 return define_spot_array_.pop();
168 Input
169 My_lily_parser::here_input() const
171 return lexer_p_->here_input ();
174 Paper_def*
175 My_lily_parser::default_paper_p ()
177 Identifier *id = lexer_p_->lookup_identifier ("$defaultpaper");
178 return id ? id->access_content_Paper_def (true) : new Paper_def ;
181 Midi_def*
182 My_lily_parser::default_midi_p ()
184 Identifier *id = lexer_p_->lookup_identifier ("$defaultmidi");
185 return id ? id->access_content_Midi_def (true) : new Midi_def ;