]> git.donarmstrong.com Git - lilypond.git/blob - lily/my-lily-parser.cc
release: 1.3.75
[lilypond.git] / lily / my-lily-parser.cc
1 /*
2   my-lily-parser.cc -- implement My_lily_parser
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7        Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9
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"
25
26 My_lily_parser::My_lily_parser (Sources * source_l)
27 {
28   source_l_ = source_l;
29   lexer_p_ = 0;
30   default_duration_.durlog_i_ = 2;
31   error_level_i_ = 0;
32
33   fatal_error_i_ = 0;
34   default_header_p_ =0;
35 }
36
37 My_lily_parser::~My_lily_parser()
38 {
39   delete lexer_p_;
40   delete default_header_p_;
41 }
42
43 void
44 My_lily_parser::set_version_check (bool )
45 {
46 }
47
48 void
49 My_lily_parser::parse_file (String init, String s)
50 {
51   lexer_p_ = new My_lily_lexer;
52
53   lexer_p_->main_input_str_ = s;
54
55   progress_indication (_("Parsing..."));
56
57   set_yydebug (flower_dstream &&!flower_dstream->silent_b ("Parser"));
58   lexer_p_->new_input (init, source_l_);
59   do_yyparse ();
60
61   if (!define_spot_array_.empty())
62     {
63       warning (_ ("Braces don't match"));
64       error_level_i_ = 1;
65     }
66
67   inclusion_global_array = lexer_p_->filename_str_arr_;
68
69   error_level_i_ = error_level_i_ | lexer_p_->errorlevel_i_; // ugh naming.
70 }
71
72 void
73 My_lily_parser::remember_spot()
74 {
75   define_spot_array_.push (here_input());
76 }
77
78 char const *
79 My_lily_parser::here_ch_C() const
80 {
81   return lexer_p_->here_ch_C();
82 }
83
84 void
85 My_lily_parser::parser_error (String s)
86 {
87   here_input().error (s);
88   if (fatal_error_i_)
89     exit (fatal_error_i_);
90   error_level_i_ = 1;
91   exit_status_i_ = 1;
92 }
93
94 void
95 My_lily_parser::set_last_duration (Duration const *d)
96 {
97   default_duration_ = *d;
98 }
99
100 // junk me
101 Simultaneous_music *
102 My_lily_parser::get_chord (Musical_pitch tonic,
103                            Array<Musical_pitch>* add_arr_p,
104                            Array<Musical_pitch>* sub_arr_p,
105                            Musical_pitch* inversion_p,
106                            Musical_pitch* bass_p,
107                            Duration d)
108 {
109
110   /*
111     UARGAUGRAGRUAUGRUINAGRAUGIRNA
112
113     ugh
114    */
115   Chord chord = to_chord (tonic, add_arr_p, sub_arr_p, inversion_p, bass_p);
116   inversion_p = 0;
117   bass_p = 0;
118
119   Tonic_req* t = new Tonic_req;
120   t->pitch_ = tonic;
121   SCM l = gh_cons (t->self_scm (), SCM_EOL);
122
123   //urg
124   if (chord.inversion_b_
125       && Chord::find_notename_i (&chord.pitch_arr_, chord.inversion_pitch_) > 0)
126     {
127       Inversion_req* i = new Inversion_req;
128       i->pitch_ = chord.inversion_pitch_;
129       l = gh_cons (i->self_scm (), l);
130     }
131
132   if (chord.bass_b_)
133     {
134       Bass_req* b = new Bass_req;
135       b->pitch_ = chord.bass_pitch_;
136       l = gh_cons (b->self_scm (), l);      
137     }
138
139   Array<Musical_pitch> pitch_arr = chord.to_pitch_arr ();
140   for (int i = pitch_arr.size (); --i >= 0;)
141     {
142       Musical_pitch p = pitch_arr[i];
143       Note_req* n = new Note_req;
144       n->pitch_ = p;
145       n->duration_ = d;
146       l = gh_cons (n->self_scm (), l);
147     }
148
149   Simultaneous_music*v = new Request_chord (l);
150   v->set_spot (here_input ());
151
152   return v;
153 }
154
155
156
157 Input
158 My_lily_parser::pop_spot()
159 {
160   return define_spot_array_.pop();
161 }
162
163 Input
164 My_lily_parser::here_input() const
165 {
166   return  lexer_p_->here_input ();
167 }
168
169
170