OLD | NEW |
1 /* | 1 /* |
2 This file is part of LilyPond, the GNU music typesetter. | 2 This file is part of LilyPond, the GNU music typesetter. |
3 | 3 |
4 Copyright (C) 1997--2020 Han-Wen Nienhuys <hanwen@xs4all.nl> | 4 Copyright (C) 1997--2020 Han-Wen Nienhuys <hanwen@xs4all.nl> |
5 | 5 |
6 LilyPond is free software: you can redistribute it and/or modify | 6 LilyPond is free software: you can redistribute it and/or modify |
7 it under the terms of the GNU General Public License as published by | 7 it under the terms of the GNU General Public License as published by |
8 the Free Software Foundation, either version 3 of the License, or | 8 the Free Software Foundation, either version 3 of the License, or |
9 (at your option) any later version. | 9 (at your option) any later version. |
10 | 10 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 ly_reexport_module (scm_current_module ()); | 145 ly_reexport_module (scm_current_module ()); |
146 if (!scm_is_pair (scopes_)) | 146 if (!scm_is_pair (scopes_)) |
147 start_module_ = scm_current_module (); | 147 start_module_ = scm_current_module (); |
148 | 148 |
149 for (SCM s = scopes_; scm_is_pair (s); s = scm_cdr (s)) | 149 for (SCM s = scopes_; scm_is_pair (s); s = scm_cdr (s)) |
150 ly_use_module (module, scm_car (s)); | 150 ly_use_module (module, scm_car (s)); |
151 scopes_ = scm_cons (module, scopes_); | 151 scopes_ = scm_cons (module, scopes_); |
152 | 152 |
153 set_current_scope (); | 153 set_current_scope (); |
154 } | 154 } |
| 155 |
155 bool | 156 bool |
156 Lily_lexer::has_scope () const | 157 Lily_lexer::has_scope () const |
157 { | 158 { |
158 return scm_is_pair (scopes_); | 159 return scm_is_pair (scopes_); |
159 } | 160 } |
160 | 161 |
161 SCM | 162 SCM |
162 Lily_lexer::remove_scope () | 163 Lily_lexer::remove_scope () |
163 { | 164 { |
164 SCM sc = scm_car (scopes_); | 165 SCM sc = scm_car (scopes_); |
165 scopes_ = scm_cdr (scopes_); | 166 scopes_ = scm_cdr (scopes_); |
166 set_current_scope (); | 167 set_current_scope (); |
167 return sc; | 168 return sc; |
168 } | 169 } |
169 | 170 |
170 SCM | 171 SCM |
171 Lily_lexer::set_current_scope () | 172 Lily_lexer::set_current_scope () |
172 { | 173 { |
173 SCM old = scm_current_module (); | 174 SCM old = scm_current_module (); |
174 | 175 |
175 if (scm_is_pair (scopes_)) | 176 if (scm_is_pair (scopes_)) |
176 scm_set_current_module (scm_car (scopes_)); | 177 scm_set_current_module (scm_car (scopes_)); |
177 else | 178 else |
178 scm_set_current_module (start_module_); | 179 scm_set_current_module (start_module_); |
179 | 180 |
180 return old; | 181 return old; |
181 } | 182 } |
182 | 183 |
| 184 SCM |
| 185 Lily_lexer::current_scope () const |
| 186 { |
| 187 if (scm_is_pair (scopes_)) |
| 188 return scm_car (scopes_); |
| 189 error (_ ("no active module in scope")); |
| 190 return SCM_BOOL_F; |
| 191 } |
| 192 |
183 int | 193 int |
184 Lily_lexer::lookup_keyword (const string &s) | 194 Lily_lexer::lookup_keyword (const string &s) |
185 { | 195 { |
186 return keytable_->lookup (s.c_str ()); | 196 return keytable_->lookup (s.c_str ()); |
187 } | 197 } |
188 | 198 |
189 SCM | 199 SCM |
190 Lily_lexer::keyword_list () const | 200 Lily_lexer::keyword_list () const |
191 { | 201 { |
192 if (!keytable_) | 202 if (!keytable_) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 } | 236 } |
227 | 237 |
228 void | 238 void |
229 Lily_lexer::start_main_input () | 239 Lily_lexer::start_main_input () |
230 { | 240 { |
231 yy_flex_debug = get_program_option ("debug-lexer"); | 241 yy_flex_debug = get_program_option ("debug-lexer"); |
232 parser_->set_yydebug (get_program_option ("debug-parser")); | 242 parser_->set_yydebug (get_program_option ("debug-parser")); |
233 | 243 |
234 new_input (main_input_name_, sources_); | 244 new_input (main_input_name_, sources_); |
235 | 245 |
236 scm_module_define (scm_car (scopes_), | 246 scm_module_define (current_scope (), |
237 ly_symbol2scm ("input-file-name"), | 247 ly_symbol2scm ("input-file-name"), |
238 ly_string2scm (main_input_name_)); | 248 ly_string2scm (main_input_name_)); |
239 } | 249 } |
240 | 250 |
241 void | 251 void |
242 Lily_lexer::new_input (const string &str, Sources *ss) | 252 Lily_lexer::new_input (const string &str, Sources *ss) |
243 { | 253 { |
244 if (is_main_input_ && be_safe_global) | 254 if (is_main_input_ && be_safe_global) |
245 { | 255 { |
246 LexerError (_ ("include files are not allowed in safe mode").c_str ()); | 256 LexerError (_ ("include files are not allowed in safe mode").c_str ()); |
(...skipping 19 matching lines...) Expand all Loading... |
266 } | 276 } |
267 | 277 |
268 if (scm_is_symbol (sym)) | 278 if (scm_is_symbol (sym)) |
269 { | 279 { |
270 if (lookup_keyword (ly_symbol2string (sym)) >= 0) | 280 if (lookup_keyword (ly_symbol2string (sym)) >= 0) |
271 { | 281 { |
272 string symstr = ly_symbol2string (sym); | 282 string symstr = ly_symbol2string (sym); |
273 warning (_f ("identifier name is a keyword: `%s'", symstr.c_str ())); | 283 warning (_f ("identifier name is a keyword: `%s'", symstr.c_str ())); |
274 } | 284 } |
275 | 285 |
276 SCM mod = scm_car (scopes_); | 286 SCM mod = current_scope (); |
277 | 287 |
278 if (scm_is_pair (path)) | 288 if (scm_is_pair (path)) |
279 { | 289 { |
280 SCM prev = ly_module_lookup (mod, sym); | 290 SCM prev = ly_module_lookup (mod, sym); |
281 if (scm_is_true (prev)) | 291 if (scm_is_true (prev)) |
282 val = nested_property_alist (scm_variable_ref (prev), path, val); | 292 val = nested_property_alist (scm_variable_ref (prev), path, val); |
283 else | 293 else |
284 val = nested_create_alist (path, val); | 294 val = nested_create_alist (path, val); |
285 } | 295 } |
286 scm_module_define (mod, sym, val); | 296 scm_module_define (mod, sym, val); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 scm_display (scopes_, port); | 396 scm_display (scopes_, port); |
387 scm_puts (" >", port); | 397 scm_puts (" >", port); |
388 return 1; | 398 return 1; |
389 } | 399 } |
390 | 400 |
391 bool | 401 bool |
392 Lily_lexer::is_clean () const | 402 Lily_lexer::is_clean () const |
393 { | 403 { |
394 return include_stack_.empty (); | 404 return include_stack_.empty (); |
395 } | 405 } |
OLD | NEW |