LEFT | RIGHT |
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--2010 Han-Wen Nienhuys <hanwen@xs4all.nl> | 4 Copyright (C) 1997--2010 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 Lily_lexer::keyword_list () const | 202 Lily_lexer::keyword_list () const |
203 { | 203 { |
204 if (!keytable_) | 204 if (!keytable_) |
205 return SCM_EOL; | 205 return SCM_EOL; |
206 | 206 |
207 SCM l = SCM_EOL; | 207 SCM l = SCM_EOL; |
208 SCM *tail = &l; | 208 SCM *tail = &l; |
209 for (vsize i = 0; i < keytable_->table_.size (); i++) | 209 for (vsize i = 0; i < keytable_->table_.size (); i++) |
210 { | 210 { |
211 *tail = scm_acons (scm_from_locale_string (keytable_->table_[i].name_), | 211 *tail = scm_acons (scm_from_locale_string (keytable_->table_[i].name_), |
212 scm_from_int (keytable_->table_[i].tokcode_), | 212 » » » scm_from_int (keytable_->table_[i].tokcode_), |
213 SCM_EOL); | 213 » » » SCM_EOL); |
214 | 214 |
215 tail = SCM_CDRLOC (*tail); | 215 tail = SCM_CDRLOC (*tail); |
216 } | 216 } |
217 | 217 |
218 return l; | 218 return l; |
219 } | 219 } |
220 | 220 |
221 SCM | 221 SCM |
222 Lily_lexer::lookup_identifier_symbol (SCM sym) | 222 Lily_lexer::lookup_identifier_symbol (SCM sym) |
223 { | 223 { |
224 for (SCM s = scopes_; scm_is_pair (s); s = scm_cdr (s)) | 224 for (SCM s = scopes_; scm_is_pair (s); s = scm_cdr (s)) |
225 { | 225 { |
226 SCM var = ly_module_lookup (scm_car (s), sym); | 226 SCM var = ly_module_lookup (scm_car (s), sym); |
227 if (var != SCM_BOOL_F) | 227 if (var != SCM_BOOL_F) |
228 return scm_variable_ref (var); | 228 » return scm_variable_ref (var); |
229 } | 229 } |
230 | 230 |
231 return SCM_UNDEFINED; | 231 return SCM_UNDEFINED; |
232 } | 232 } |
233 | 233 |
234 SCM | 234 SCM |
235 Lily_lexer::lookup_identifier (string name) | 235 Lily_lexer::lookup_identifier (string name) |
236 { | 236 { |
237 return lookup_identifier_symbol (ly_symbol2scm (name.c_str ())); | 237 return lookup_identifier_symbol (ly_symbol2scm (name.c_str ())); |
238 } | 238 } |
239 | 239 |
240 void | 240 void |
241 Lily_lexer::start_main_input () | 241 Lily_lexer::start_main_input () |
242 { | 242 { |
243 yy_flex_debug = get_program_option ("debug-lexer"); | 243 yy_flex_debug = get_program_option ("debug-lexer"); |
244 parser_->set_yydebug (get_program_option ("debug-parser")); | 244 parser_->set_yydebug (get_program_option ("debug-parser")); |
245 | 245 |
246 new_input (main_input_name_, sources_); | 246 new_input (main_input_name_, sources_); |
247 | 247 |
248 scm_module_define (scm_car (scopes_), | 248 scm_module_define (scm_car (scopes_), |
249 ly_symbol2scm ("input-file-name"), | 249 » » ly_symbol2scm ("input-file-name"), |
250 ly_string2scm (main_input_name_)); | 250 » » ly_string2scm (main_input_name_)); |
251 } | 251 } |
252 | 252 |
253 void | 253 void |
254 Lily_lexer::new_input (string str, string d, Sources *ss) | 254 Lily_lexer::new_input (string str, string d, Sources *ss) |
255 { | 255 { |
256 Includable_lexer::new_input (str, d, ss); | 256 Includable_lexer::new_input (str, d, ss); |
257 } | 257 } |
258 | 258 |
259 void | 259 void |
260 Lily_lexer::new_input (string str, Sources *ss) | 260 Lily_lexer::new_input (string str, Sources *ss) |
(...skipping 17 matching lines...) Expand all Loading... |
278 if (scm_is_string (path)) | 278 if (scm_is_string (path)) |
279 sym = scm_string_to_symbol (path); | 279 sym = scm_string_to_symbol (path); |
280 else if (scm_is_pair (path)) | 280 else if (scm_is_pair (path)) |
281 { | 281 { |
282 sym = scm_car (path); | 282 sym = scm_car (path); |
283 path = scm_cdr (path); | 283 path = scm_cdr (path); |
284 } | 284 } |
285 | 285 |
286 if (scm_is_symbol (sym)) | 286 if (scm_is_symbol (sym)) |
287 { | 287 { |
288 string symstr = ly_symbol2string (sym); | 288 string symstr = ly_symbol2string (sym); |
289 if (lookup_keyword (ly_symbol2string (sym)) >= 0) | 289 if (lookup_keyword (ly_symbol2string (sym)) >= 0) |
290 { | 290 » { |
291 warning (_f ("identifier name is a keyword: `%s'", symstr.c_str ())); | 291 » warning (_f ("identifier name is a keyword: `%s'", symstr.c_str ())); |
292 } | 292 » } |
293 | 293 |
294 SCM mod = scm_car (scopes_); | 294 SCM mod = scm_car (scopes_); |
| 295 |
295 if (scm_is_pair (path)) | 296 if (scm_is_pair (path)) |
296 { | 297 » { |
297 SCM prev = scm_module_lookup (mod, sym); | 298 » SCM prev = scm_module_lookup (mod, sym); |
298 if (prev != SCM_UNDEFINED) | 299 » if (prev != SCM_UNDEFINED) |
299 val = nested_property_alist (prev, path, val); | 300 » val = nested_property_alist (prev, path, val); |
300 } | 301 » } |
301 /* Do the equivalent of (define-public( sym val) */ | 302 |
| 303 /* Do the equivalent of (define-public( sym val) */ |
302 scm_module_define (mod, sym, val); | 304 scm_module_define (mod, sym, val); |
303 scm_c_export (symstr.c_str(), NULL); | 305 scm_c_export (symstr.c_str(), NULL); |
304 } | 306 } |
305 else | 307 else |
306 programming_error ("identifier is not a symbol"); | 308 programming_error ("identifier is not a symbol"); |
307 } | 309 } |
308 | 310 |
309 void | 311 void |
310 Lily_lexer::LexerError (char const *s) | 312 Lily_lexer::LexerError (char const *s) |
311 { | 313 { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 | 352 |
351 /** | 353 /** |
352 Since we don't create the buffer state from the bytes directly, we | 354 Since we don't create the buffer state from the bytes directly, we |
353 don't know about the location of the lexer. Add this as a | 355 don't know about the location of the lexer. Add this as a |
354 YY_USER_ACTION */ | 356 YY_USER_ACTION */ |
355 void | 357 void |
356 Lily_lexer::add_lexed_char (int count) | 358 Lily_lexer::add_lexed_char (int count) |
357 { | 359 { |
358 char const *start = here_str0 (); | 360 char const *start = here_str0 (); |
359 lexloc_->set (get_source_file (), | 361 lexloc_->set (get_source_file (), |
360 start, start + count); | 362 » » start, start + count); |
361 char_count_stack_.back () += count; | 363 char_count_stack_.back () += count; |
362 } | 364 } |
363 | 365 |
364 #include "ly-smobs.icc" | 366 #include "ly-smobs.icc" |
365 | 367 |
366 IMPLEMENT_SMOBS (Lily_lexer); | 368 IMPLEMENT_SMOBS (Lily_lexer); |
367 IMPLEMENT_TYPE_P (Lily_lexer, "ly:lily-lexer?"); | 369 IMPLEMENT_TYPE_P (Lily_lexer, "ly:lily-lexer?"); |
368 IMPLEMENT_DEFAULT_EQUAL_P (Lily_lexer); | 370 IMPLEMENT_DEFAULT_EQUAL_P (Lily_lexer); |
369 | 371 |
370 SCM | 372 SCM |
(...skipping 14 matching lines...) Expand all Loading... |
385 int | 387 int |
386 Lily_lexer::print_smob (SCM s, SCM port, scm_print_state*) | 388 Lily_lexer::print_smob (SCM s, SCM port, scm_print_state*) |
387 { | 389 { |
388 Lily_lexer *lexer = Lily_lexer::unsmob (s); | 390 Lily_lexer *lexer = Lily_lexer::unsmob (s); |
389 | 391 |
390 scm_puts ("#<Lily_lexer ", port); | 392 scm_puts ("#<Lily_lexer ", port); |
391 scm_display (lexer->scopes_, port); | 393 scm_display (lexer->scopes_, port); |
392 scm_puts (" >", port); | 394 scm_puts (" >", port); |
393 return 1; | 395 return 1; |
394 } | 396 } |
LEFT | RIGHT |