LEFT | RIGHT |
1 %{ // -*- mode: c++; c-file-style: "linux"; indent-tabs-mode: t -*- | 1 %{ // -*- mode: c++; c-file-style: "linux"; indent-tabs-mode: t -*- |
2 /* | 2 /* |
3 This file is part of LilyPond, the GNU music typesetter. | 3 This file is part of LilyPond, the GNU music typesetter. |
4 | 4 |
5 Copyright (C) 1996--2012 Han-Wen Nienhuys <hanwen@xs4all.nl> | 5 Copyright (C) 1996--2012 Han-Wen Nienhuys <hanwen@xs4all.nl> |
6 Jan Nieuwenhuizen <janneke@gnu.org> | 6 Jan Nieuwenhuizen <janneke@gnu.org> |
7 | 7 |
8 LilyPond is free software: you can redistribute it and/or modify | 8 LilyPond is free software: you can redistribute it and/or modify |
9 it under the terms of the GNU General Public License as published by | 9 it under the terms of the GNU General Public License as published by |
10 the Free Software Foundation, either version 3 of the License, or | 10 the Free Software Foundation, either version 3 of the License, or |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 SCM lookup_markup_list_command (string s); | 85 SCM lookup_markup_list_command (string s); |
86 bool is_valid_version (string s); | 86 bool is_valid_version (string s); |
87 | 87 |
88 | 88 |
89 #define start_quote() do { \ | 89 #define start_quote() do { \ |
90 yy_push_state (quote); \ | 90 yy_push_state (quote); \ |
91 yylval = SCM_EOL; \ | 91 yylval = SCM_EOL; \ |
92 } while (0) | 92 } while (0) |
93 | 93 |
94 /* | 94 /* |
95 The inside of \"violin1" is marked by nesting two quote modes as we | 95 The inside of \"violin1" is marked by commandquote mode |
96 don't have a dedicated command mode. | |
97 */ | 96 */ |
98 | 97 |
99 #define start_command_quote() do { \ | 98 #define start_command_quote() do { \ |
100 yy_push_state (quote); \ | 99 yy_push_state (commandquote);» \ |
101 yy_push_state (quote); \ | |
102 yylval = SCM_EOL; \ | 100 yylval = SCM_EOL; \ |
103 } while (0) | 101 } while (0) |
104 | 102 |
105 #define yylval (*lexval_) | 103 #define yylval (*lexval_) |
106 | 104 |
107 #define yylloc (*lexloc_) | 105 #define yylloc (*lexloc_) |
108 | 106 |
109 #define YY_USER_ACTION add_lexed_char (YYLeng ()); | 107 #define YY_USER_ACTION add_lexed_char (YYLeng ()); |
110 | 108 |
111 | 109 |
(...skipping 12 matching lines...) Expand all Loading... |
124 %option stack | 122 %option stack |
125 %option never-interactive· | 123 %option never-interactive· |
126 %option warn | 124 %option warn |
127 | 125 |
128 %x extratoken | 126 %x extratoken |
129 %x chords | 127 %x chords |
130 %x figures | 128 %x figures |
131 %x incl | 129 %x incl |
132 %x lyrics | 130 %x lyrics |
133 %x longcomment | 131 %x longcomment |
| 132 %x maininput |
134 %x markup | 133 %x markup |
135 %x notes | 134 %x notes |
136 %x quote | 135 %x quote |
| 136 %x commandquote |
137 %x sourcefileline | 137 %x sourcefileline |
138 %x sourcefilename | 138 %x sourcefilename |
139 %x version | 139 %x version |
140 | 140 |
141 /* The strategy concerning multibyte characters is to accept them but | 141 /* The strategy concerning multibyte characters is to accept them but |
142 * call YYText_utf8 for patterns that might contain them, in order to | 142 * call YYText_utf8 for patterns that might contain them, in order to |
143 * get a single code path responsible for flagging non-UTF-8 input: | 143 * get a single code path responsible for flagging non-UTF-8 input: |
144 * Patterns for accepting only valid UTF-8 without backing up are | 144 * Patterns for accepting only valid UTF-8 without backing up are |
145 * really hard to do and complex, and if nice error messages are | 145 * really hard to do and complex, and if nice error messages are |
146 * wanted, one would need patterns catching the invalid input as well. | 146 * wanted, one would need patterns catching the invalid input as well. |
147 * | 147 * |
148 * Since editors and operating environments don't necessarily behave | 148 * Since editors and operating environments don't necessarily behave |
149 * reasonably in the presence of mixed encodings, we flag encoding | 149 * reasonably in the presence of mixed encodings, we flag encoding |
150 * errors also in identifiers, comments, and strings where it would be | 150 * errors also in identifiers, comments, and strings where it would be |
151 * conceivable to just transparently work with the byte string. But | 151 * conceivable to just transparently work with the byte string. But |
152 * the whole point of caring about UTF-8 in here at all is too avoid | 152 * the whole point of caring about UTF-8 in here at all is too avoid |
153 * stranger errors later when input passes into backends or log files | 153 * stranger errors later when input passes into backends or log files |
154 * or console output or error messages. | 154 * or console output or error messages. |
155 */ | 155 */ |
156 | 156 |
157 A [a-zA-Z\200-\377] | 157 A [a-zA-Z\200-\377] |
158 AA {A}|_ | 158 AA {A}|_ |
159 N [0-9] | 159 N [0-9] |
160 ANY_CHAR (.|\n) | 160 ANY_CHAR (.|\n) |
161 WORD {A}([-_]{A}|{A})* | 161 WORD {A}([-_]{A}|{A})* |
162 COMMAND \\{WORD} | 162 COMMAND \\{WORD} |
163 | 163 /* SPECIAL category is for every letter that needs to get passed to |
| 164 * the parser rather than being redefinable by the user */ |
| 165 SPECIAL»» [-+*/=<>{}!?_^'',.:] |
| 166 SHORTHAND» (.|\\.) |
164 UNSIGNED {N}+ | 167 UNSIGNED {N}+ |
165 E_UNSIGNED \\{N}+ | 168 E_UNSIGNED \\{N}+ |
166 FRACTION {N}+\/{N}+ | 169 FRACTION {N}+\/{N}+ |
167 INT -?{UNSIGNED} | 170 INT -?{UNSIGNED} |
168 REAL ({INT}\.{N}*)|(-?\.{N}+) | 171 REAL ({INT}\.{N}*)|(-?\.{N}+) |
| 172 STRICTREAL {UNSIGNED}\.{UNSIGNED} |
169 WHITE [ \n\t\f\r] | 173 WHITE [ \n\t\f\r] |
170 HORIZONTALWHITE [ \t] | 174 HORIZONTALWHITE [ \t] |
171 BLACK [^ \n\t\f\r] | 175 BLACK [^ \n\t\f\r] |
172 RESTNAME [rs] | 176 RESTNAME [rs] |
173 ESCAPED [nt\\''""] | 177 ESCAPED [nt\\''""] |
174 EXTENDER __ | 178 EXTENDER __ |
175 HYPHEN -- | 179 HYPHEN -- |
176 BOM_UTF8 \357\273\277 | 180 BOM_UTF8 \357\273\277 |
177 | 181 |
178 %% | 182 %% |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 LexerWarning (_ ("stray UTF-8 BOM encountered").c_str ()); | 224 LexerWarning (_ ("stray UTF-8 BOM encountered").c_str ()); |
221 // exit (1); | 225 // exit (1); |
222 } | 226 } |
223 debug_output (_ ("Skipping UTF-8 BOM")); | 227 debug_output (_ ("Skipping UTF-8 BOM")); |
224 } | 228 } |
225 | 229 |
226 <INITIAL,chords,figures,incl,lyrics,markup,notes>{ | 230 <INITIAL,chords,figures,incl,lyrics,markup,notes>{ |
227 "%{" { | 231 "%{" { |
228 yy_push_state (longcomment); | 232 yy_push_state (longcomment); |
229 } | 233 } |
230 %[^{\n\r][^\n\r]*[\n\r]» { | 234 %[^{\n\r][^\n\r]*[\n\r]?» { |
231 (void) YYText_utf8 (); | 235 (void) YYText_utf8 (); |
232 } | 236 } |
233 %[^{\n\r]» { // backup rule | 237 %[\n\r]?» { |
234 » (void) YYText_utf8 (); | |
235 } | |
236 %[\n\r]» { | |
237 } | |
238 %[^{\n\r][^\n\r]*» { | |
239 » (void) YYText_utf8 (); | |
240 } | 238 } |
241 {WHITE}+ { | 239 {WHITE}+ { |
242 | 240 |
243 } | 241 } |
244 } | 242 } |
245 | 243 |
246 <INITIAL,notes,figures,chords,markup>{ | 244 <INITIAL,notes,figures,chords,markup>{ |
247 \" { | 245 \" { |
248 start_quote (); | 246 start_quote (); |
249 } | 247 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 "%"+"}" { | 314 "%"+"}" { |
317 yy_pop_state (); | 315 yy_pop_state (); |
318 } | 316 } |
319 } | 317 } |
320 | 318 |
321 | 319 |
322 <INITIAL,chords,lyrics,notes,figures>\\maininput { | 320 <INITIAL,chords,lyrics,notes,figures>\\maininput { |
323 if (!is_main_input_) | 321 if (!is_main_input_) |
324 { | 322 { |
325 start_main_input (); | 323 start_main_input (); |
| 324 main_input_level_ = include_stack_.size (); |
326 is_main_input_ = true; | 325 is_main_input_ = true; |
| 326 int state = YYSTATE; |
| 327 yy_push_state (maininput); |
| 328 yy_push_state (state); |
327 } | 329 } |
328 else | 330 else |
329 » » error (_ ("\\maininput not allowed outside init files")); | 331 » » LexerError (_ ("\\maininput not allowed outside init files").c_s
tr ()); |
330 } | 332 } |
331 | 333 |
332 <INITIAL,chords,lyrics,figures,notes>\\include { | 334 <INITIAL,chords,lyrics,figures,notes>\\include { |
333 yy_push_state (incl); | 335 yy_push_state (incl); |
334 } | 336 } |
335 <incl>\"[^""]*\" { /* got the include file name */ | 337 <incl>\"[^""]*\" { /* got the include file name */ |
336 string s (YYText_utf8 ()+1); | 338 string s (YYText_utf8 ()+1); |
337 s = s.substr (0, s.rfind ('"')); | 339 s = s.substr (0, s.rfind ('"')); |
338 | 340 |
339 new_input (s, sources_); | 341 new_input (s, sources_); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 LexerError (_ ("string expected after \\include").c_str ()); | 381 LexerError (_ ("string expected after \\include").c_str ()); |
380 if (sval != SCM_UNDEFINED) { | 382 if (sval != SCM_UNDEFINED) { |
381 SCM err = scm_current_error_port (); | 383 SCM err = scm_current_error_port (); |
382 scm_puts ("This value was found instead: ", err); | 384 scm_puts ("This value was found instead: ", err); |
383 scm_display (sval, err); | 385 scm_display (sval, err); |
384 } | 386 } |
385 } | 387 } |
386 } | 388 } |
387 | 389 |
388 <incl,version,sourcefilename>\"[^""]* { // backup rule | 390 <incl,version,sourcefilename>\"[^""]* { // backup rule |
389 » error (_ ("end quote missing")); | 391 » LexerError (_ ("end quote missing").c_str ()); |
390 » exit (1); | 392 » yy_pop_state (); |
391 } | 393 } |
392 | 394 |
393 /* Flex picks the longest matching pattern including trailing | 395 /* Flex picks the longest matching pattern including trailing |
394 * contexts. Without the backup pattern, r-. does not trigger the | 396 * contexts. Without the backup pattern, r-. does not trigger the |
395 * {RESTNAME} rule but rather the {WORD}/[-_] rule coming later, | 397 * {RESTNAME} rule but rather the {WORD}/[-_] rule coming later, |
396 * needed for avoiding backup states. | 398 * needed for avoiding backup states. |
397 */ | 399 */ |
398 | 400 |
399 <chords,notes,figures>{RESTNAME}/[-_] | // pseudo backup rule | 401 <chords,notes,figures>{RESTNAME}/[-_] | // pseudo backup rule |
400 <chords,notes,figures>{RESTNAME} { | 402 <chords,notes,figures>{RESTNAME} { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 return FIGURE_SPACE; | 483 return FIGURE_SPACE; |
482 } | 484 } |
483 \> { | 485 \> { |
484 yylval = SCM_UNSPECIFIED; | 486 yylval = SCM_UNSPECIFIED; |
485 return FIGURE_CLOSE; | 487 return FIGURE_CLOSE; |
486 } | 488 } |
487 \< { | 489 \< { |
488 yylval = SCM_UNSPECIFIED; | 490 yylval = SCM_UNSPECIFIED; |
489 return FIGURE_OPEN; | 491 return FIGURE_OPEN; |
490 } | 492 } |
| 493 \\\+ { |
| 494 yylval = SCM_UNSPECIFIED; |
| 495 return E_PLUS; |
| 496 } |
| 497 \\! { |
| 498 yylval = SCM_UNSPECIFIED; |
| 499 return E_EXCLAMATION; |
| 500 } |
| 501 \\\\ { |
| 502 yylval = SCM_UNSPECIFIED; |
| 503 return E_BACKSLASH; |
| 504 } |
| 505 [][] { |
| 506 yylval = SCM_UNSPECIFIED; |
| 507 return YYText ()[0]; |
| 508 } |
491 } | 509 } |
492 | 510 |
493 <notes,figures>{ | 511 <notes,figures>{ |
494 {WORD}/[-_] | // backup rule | 512 {WORD}/[-_] | // backup rule |
495 {WORD} { | 513 {WORD} { |
496 return scan_bare_word (YYText_utf8 ()); | 514 return scan_bare_word (YYText_utf8 ()); |
497 } | 515 } |
498 \\\" { | 516 \\\" { |
499 start_command_quote (); | 517 start_command_quote (); |
500 } | 518 } |
501 {COMMAND}/[-_] | // backup rule | 519 {COMMAND}/[-_] | // backup rule |
502 {COMMAND} { | 520 {COMMAND} { |
503 return scan_escaped_word (YYText_utf8 () + 1);· | 521 return scan_escaped_word (YYText_utf8 () + 1);· |
504 } | 522 } |
505 {FRACTION} { | 523 {FRACTION} { |
506 yylval = scan_fraction (YYText ()); | 524 yylval = scan_fraction (YYText ()); |
507 return FRACTION; | 525 return FRACTION; |
508 } | 526 } |
509 » {UNSIGNED}/\/» | // backup rule | 527 » {STRICTREAL}» { |
510 » {UNSIGNED}» » { | 528 » » yylval = scm_c_read_string (YYText ()); |
| 529 » » return REAL; |
| 530 » } |
| 531 » {UNSIGNED}/[/.]»| // backup rule |
| 532 » {UNSIGNED}» { |
511 yylval = scm_c_read_string (YYText ()); | 533 yylval = scm_c_read_string (YYText ()); |
512 return UNSIGNED; | 534 return UNSIGNED; |
513 } | 535 } |
514 {E_UNSIGNED} { | 536 {E_UNSIGNED} { |
515 yylval = scm_c_read_string (YYText () + 1); | 537 yylval = scm_c_read_string (YYText () + 1); |
516 return E_UNSIGNED; | 538 return E_UNSIGNED; |
517 } | 539 } |
518 } | 540 } |
519 | 541 |
520 <quote>{ | 542 <quote,commandquote>{ |
521 \\{ESCAPED} { | 543 \\{ESCAPED} { |
522 char c = escaped_char (YYText ()[1]); | 544 char c = escaped_char (YYText ()[1]); |
523 yylval = scm_cons (scm_from_locale_stringn (&c, 1), | 545 yylval = scm_cons (scm_from_locale_stringn (&c, 1), |
524 yylval); | 546 yylval); |
525 } | 547 } |
526 [^\\""]+ { | 548 [^\\""]+ { |
527 yylval = scm_cons (scm_from_locale_string (YYText_utf8 ()), | 549 yylval = scm_cons (scm_from_locale_string (YYText_utf8 ()), |
528 yylval); | 550 yylval); |
529 } | 551 } |
530 \" { | 552 \" { |
531 | 553 |
532 yy_pop_state (); | |
533 | |
534 /* yylval is union. Must remember STRING before setting SCM*/ | 554 /* yylval is union. Must remember STRING before setting SCM*/ |
535 | 555 |
536 yylval = scm_string_concatenate_reverse (yylval, | 556 yylval = scm_string_concatenate_reverse (yylval, |
537 SCM_UNDEFINED, | 557 SCM_UNDEFINED, |
538 SCM_UNDEFINED); | 558 SCM_UNDEFINED); |
539 | 559 |
540 » » if (get_state () == quote) { | 560 » » if (get_state () == commandquote) { |
541 yy_pop_state (); | 561 yy_pop_state (); |
542 return scan_escaped_word (ly_scm2string (yylval)); | 562 return scan_escaped_word (ly_scm2string (yylval)); |
543 } | 563 } |
544 | 564 |
545 » » return is_lyric_state () ? LYRICS_STRING : STRING; | 565 » » yy_pop_state (); |
| 566 |
| 567 » » return STRING; |
546 } | 568 } |
547 \\ { | 569 \\ { |
548 yylval = scm_cons (scm_from_locale_string (YYText ()), | 570 yylval = scm_cons (scm_from_locale_string (YYText ()), |
549 yylval); | 571 yylval); |
550 } | 572 } |
551 } | 573 } |
552 | 574 |
553 <lyrics>{ | 575 <lyrics>{ |
554 \" { | 576 \" { |
555 start_quote (); | 577 start_quote (); |
556 } | 578 } |
557 {FRACTION} { | 579 {FRACTION} { |
558 yylval = scan_fraction (YYText ()); | 580 yylval = scan_fraction (YYText ()); |
559 return FRACTION; | 581 return FRACTION; |
560 } | 582 } |
561 » {UNSIGNED}/\/» | // backup rule | 583 » {STRICTREAL}» { |
| 584 » » yylval = scm_c_read_string (YYText ()); |
| 585 » » return REAL; |
| 586 » } |
| 587 » {UNSIGNED}/[/.]»| // backup rule |
562 {UNSIGNED} { | 588 {UNSIGNED} { |
563 yylval = scm_c_read_string (YYText ()); | 589 yylval = scm_c_read_string (YYText ()); |
564 return UNSIGNED; | 590 return UNSIGNED; |
565 } | 591 } |
566 \\\" { | 592 \\\" { |
567 start_command_quote (); | 593 start_command_quote (); |
568 } | 594 } |
569 {COMMAND}/[-_] | // backup rule | 595 {COMMAND}/[-_] | // backup rule |
570 {COMMAND} { | 596 {COMMAND} { |
571 return scan_escaped_word (YYText_utf8 () + 1); | 597 return scan_escaped_word (YYText_utf8 () + 1); |
572 } | 598 } |
573 » /* Characters needed to express durations, assignments, barchecks */ | 599 » \\.|\|» { |
574 » [*.=|]» { | 600 » » // UTF-8 already covered by COMMAND |
| 601 » » return scan_shorthand (YYText ()); |
| 602 » } |
| 603 » /* Characters needed to express durations, assignments */ |
| 604 » [*.=]» { |
575 yylval = SCM_UNSPECIFIED; | 605 yylval = SCM_UNSPECIFIED; |
576 return YYText ()[0]; | 606 return YYText ()[0]; |
577 } | 607 } |
578 [^$#{}\"\\ \t\n\r\f0-9]+ { | 608 [^$#{}\"\\ \t\n\r\f0-9]+ { |
579 /* ugr. This sux. */ | 609 /* ugr. This sux. */ |
580 string s (YYText_utf8 ()); | 610 string s (YYText_utf8 ()); |
581 yylval = SCM_UNSPECIFIED; | 611 yylval = SCM_UNSPECIFIED; |
582 if (s == "__") | 612 if (s == "__") |
583 return EXTENDER; | 613 return EXTENDER; |
584 if (s == "--") | 614 if (s == "--") |
585 return HYPHEN; | 615 return HYPHEN; |
586 s = lyric_fudge (s); | 616 s = lyric_fudge (s); |
587 yylval = ly_string2scm (s); | 617 yylval = ly_string2scm (s); |
588 | 618 |
589 » » return LYRICS_STRING; | 619 » » return STRING; |
590 } | 620 } |
591 /* This should really just cover {} */ | 621 /* This should really just cover {} */ |
592 » . { | 622 » [{}] { |
593 yylval = SCM_UNSPECIFIED; | 623 yylval = SCM_UNSPECIFIED; |
594 » » return YYText ()[0]; // above catches all multibytes. | 624 » » return YYText ()[0]; |
595 } | 625 } |
596 } | 626 } |
597 <chords>{ | 627 <chords>{ |
598 {WORD}/[-_] | // backup rule | 628 {WORD}/[-_] | // backup rule |
599 {WORD} { | 629 {WORD} { |
600 return scan_bare_word (YYText_utf8 ()); | 630 return scan_bare_word (YYText_utf8 ()); |
601 } | 631 } |
602 \\\" { | 632 \\\" { |
603 start_command_quote (); | 633 start_command_quote (); |
604 } | 634 } |
(...skipping 22 matching lines...) Expand all Loading... |
627 yylval = SCM_UNSPECIFIED; | 657 yylval = SCM_UNSPECIFIED; |
628 return CHORD_BASS; | 658 return CHORD_BASS; |
629 } | 659 } |
630 \/ { | 660 \/ { |
631 yylval = SCM_UNSPECIFIED; | 661 yylval = SCM_UNSPECIFIED; |
632 return CHORD_SLASH; | 662 return CHORD_SLASH; |
633 } | 663 } |
634 \^ { | 664 \^ { |
635 yylval = SCM_UNSPECIFIED; | 665 yylval = SCM_UNSPECIFIED; |
636 return CHORD_CARET; | 666 return CHORD_CARET; |
637 } | |
638 . { | |
639 yylval = SCM_UNSPECIFIED; | |
640 return YYText ()[0]; // WORD catches all multibyte. | |
641 } | 667 } |
642 } | 668 } |
643 | 669 |
644 | 670 |
645 <markup>{ | 671 <markup>{ |
646 \\score { | 672 \\score { |
647 yylval = SCM_UNSPECIFIED; | 673 yylval = SCM_UNSPECIFIED; |
648 return SCORE; | 674 return SCORE; |
649 } | 675 } |
650 \\\" { | 676 \\\" { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 push_extra_token(EXPECT_SCM, predicate); | 726 push_extra_token(EXPECT_SCM, predicate); |
701 } | 727 } |
702 return token_type; | 728 return token_type; |
703 } | 729 } |
704 [^$#{}\"\\ \t\n\r\f]+ { | 730 [^$#{}\"\\ \t\n\r\f]+ { |
705 string s (YYText_utf8 ());· | 731 string s (YYText_utf8 ());· |
706 | 732 |
707 yylval = ly_string2scm (s); | 733 yylval = ly_string2scm (s); |
708 return STRING; | 734 return STRING; |
709 } | 735 } |
710 » . { | 736 » [{}] { |
711 yylval = SCM_UNSPECIFIED; | 737 yylval = SCM_UNSPECIFIED; |
712 » » return YYText ()[0]; // Above is catchall for multibyte | 738 » » return YYText ()[0]; |
713 } | 739 } |
714 } | 740 } |
715 | 741 |
716 <longcomment><<EOF>> { | 742 <longcomment><<EOF>> { |
717 LexerError (_ ("EOF found inside a comment").c_str ()); | 743 LexerError (_ ("EOF found inside a comment").c_str ()); |
718 » » is_main_input_ = false; // should be safe , can't have \include
in --safe. | 744 » » yy_pop_state (); |
719 yylval = SCM_UNSPECIFIED; | 745 » } |
720 » » if (!close_input ()) | 746 |
721 » » yyterminate (); // can't move this, since it actually rets a Y
Y_NULL | 747 <quote,commandquote><<EOF>> { |
722 » } | 748 » LexerError (_ ("EOF found inside string").c_str ()); |
| 749 » yy_pop_state (); |
| 750 } |
723 | 751 |
724 <<EOF>> { | 752 <<EOF>> { |
725 yylval = SCM_UNSPECIFIED; | 753 yylval = SCM_UNSPECIFIED; |
726 if (is_main_input_) | 754 if (is_main_input_) |
727 { | 755 { |
728 » » /* 2 = init.ly + current file. | 756 » » is_main_input_ = include_stack_.size () > main_input_level_; |
729 » » > because we're before closing, but is_main_input_ should | 757 » » if (!is_main_input_) |
730 » » reflect after. | 758 » » { |
731 » » */· | 759 » » » main_input_level_ = 0; |
732 » » is_main_input_ = include_stack_.size () > 2; | 760 » » » pop_state (); |
| 761 » » » if (YYSTATE != maininput) |
| 762 » » » { |
| 763 » » » » LexerError (_ ("Unfinished main input").c_str ()
); |
| 764 » » » » do { |
| 765 » » » » » yy_pop_state (); |
| 766 » » » » } while (YYSTATE != maininput); |
| 767 » » » } |
| 768 » » » extra_tokens_ = SCM_EOL; |
| 769 » » » yy_pop_state (); |
| 770 » » } |
733 if (!close_input () || !is_main_input_) | 771 if (!close_input () || !is_main_input_) |
734 /* Returns YY_NULL */ | 772 /* Returns YY_NULL */ |
735 yyterminate (); | 773 yyterminate (); |
736 } | 774 } |
737 else if (!close_input ()) | 775 else if (!close_input ()) |
738 /* Returns YY_NULL */ | 776 /* Returns YY_NULL */ |
739 yyterminate (); | 777 yyterminate (); |
| 778 } |
| 779 |
| 780 <maininput>{ANY_CHAR} { |
| 781 while (include_stack_.size () > main_input_level_ |
| 782 && close_input ()) |
| 783 ; |
| 784 yyterminate (); |
740 } | 785 } |
741 | 786 |
742 <INITIAL>{ | 787 <INITIAL>{ |
743 {WORD}/[-_] | // backup rule | 788 {WORD}/[-_] | // backup rule |
744 {WORD} { | 789 {WORD} { |
745 return scan_bare_word (YYText_utf8 ()); | 790 return scan_bare_word (YYText_utf8 ()); |
746 } | 791 } |
747 \\\" { | 792 \\\" { |
748 start_command_quote (); | 793 start_command_quote (); |
749 } | 794 } |
(...skipping 14 matching lines...) Expand all Loading... |
764 return REAL; | 809 return REAL; |
765 } | 810 } |
766 | 811 |
767 {UNSIGNED}/\/ | // backup rule | 812 {UNSIGNED}/\/ | // backup rule |
768 {UNSIGNED} { | 813 {UNSIGNED} { |
769 yylval = scm_c_read_string (YYText ()); | 814 yylval = scm_c_read_string (YYText ()); |
770 return UNSIGNED; | 815 return UNSIGNED; |
771 } | 816 } |
772 | 817 |
773 | 818 |
774 [{}]» { | 819 -/\.» { // backup rule |
775 yylval = SCM_UNSPECIFIED; | 820 yylval = SCM_UNSPECIFIED; |
776 return YYText ()[0]; | 821 return YYText ()[0]; |
777 } | 822 } |
778 | 823 |
779 -/\.» | // backup rule | 824 <INITIAL,chords,lyrics,figures,notes>{SPECIAL}» { |
780 [*:=]» » { | |
781 yylval = SCM_UNSPECIFIED; | 825 yylval = SCM_UNSPECIFIED; |
782 return YYText ()[0]; | 826 return YYText ()[0]; |
783 } | 827 } |
784 | 828 |
785 <INITIAL,notes,figures>.» { | 829 <INITIAL,chords,lyrics,figures,notes>{SHORTHAND}» { |
786 yylval = SCM_UNSPECIFIED; | 830 » return scan_shorthand (YYText_utf8 ()); // should not be utf-8 |
787 » return YYText ()[0]; | |
788 } | |
789 | |
790 <INITIAL,lyrics,notes,figures>\\. { | |
791 yylval = SCM_UNSPECIFIED; | |
792 char c = YYText ()[1]; | |
793 | |
794 switch (c) { | |
795 case '>': | |
796 » return E_ANGLE_CLOSE; | |
797 case '<': | |
798 » return E_ANGLE_OPEN; | |
799 case '!': | |
800 » return E_EXCLAMATION; | |
801 case '(': | |
802 » return E_OPEN; | |
803 case ')': | |
804 » return E_CLOSE; | |
805 case '[': | |
806 » return E_BRACKET_OPEN; | |
807 case '+': | |
808 » return E_PLUS; | |
809 case ']': | |
810 » return E_BRACKET_CLOSE; | |
811 case '~': | |
812 » return E_TILDE; | |
813 case '\\': | |
814 » return E_BACKSLASH; | |
815 | |
816 default: | |
817 » return E_CHAR; | |
818 } | |
819 } | 831 } |
820 | 832 |
821 <*>.[\200-\277]* { | 833 <*>.[\200-\277]* { |
822 string msg = _f ("invalid character: `%s'", YYText_utf8 ()); | 834 string msg = _f ("invalid character: `%s'", YYText_utf8 ()); |
823 LexerError (msg.c_str ()); | 835 LexerError (msg.c_str ()); |
824 yylval = SCM_UNSPECIFIED; | 836 yylval = SCM_UNSPECIFIED; |
825 return '%'; // Better not return half a utf8 character. | 837 return '%'; // Better not return half a utf8 character. |
826 } | 838 } |
827 | 839 |
828 %% | 840 %% |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
901 Lily_lexer::pop_state () | 913 Lily_lexer::pop_state () |
902 { | 914 { |
903 bool extra = (YYSTATE == extratoken); | 915 bool extra = (YYSTATE == extratoken); |
904 | 916 |
905 if (extra) | 917 if (extra) |
906 yy_pop_state (); | 918 yy_pop_state (); |
907 | 919 |
908 if (YYSTATE == notes || YYSTATE == chords) | 920 if (YYSTATE == notes || YYSTATE == chords) |
909 pitchname_tab_stack_ = scm_cdr (pitchname_tab_stack_); | 921 pitchname_tab_stack_ = scm_cdr (pitchname_tab_stack_); |
910 | 922 |
911 » yy_pop_state (); | 923 » // don't cross the maininput threshold |
| 924 » if (YYSTATE != maininput) |
| 925 » » yy_pop_state (); |
912 | 926 |
913 if (extra) { | 927 if (extra) { |
914 hidden_state_ = YYSTATE; | 928 hidden_state_ = YYSTATE; |
915 yy_push_state (extratoken); | 929 yy_push_state (extratoken); |
916 } | 930 } |
917 } | 931 } |
918 | 932 |
919 int | 933 int |
920 Lily_lexer::identifier_type (SCM sid) | 934 Lily_lexer::identifier_type (SCM sid) |
921 { | 935 { |
922 int k = try_special_identifiers (&yylval , sid); | 936 int k = try_special_identifiers (&yylval , sid); |
923 return k >= 0 ? k : SCM_IDENTIFIER; | 937 return k >= 0 ? k : SCM_IDENTIFIER; |
924 } | 938 } |
925 | 939 |
926 | 940 |
927 int | 941 int |
928 Lily_lexer::scan_escaped_word (string str) | 942 Lily_lexer::scan_escaped_word (const string &str) |
929 { | 943 { |
930 // use more SCM for this. | 944 // use more SCM for this. |
931 | 945 |
932 // SCM sym = ly_symbol2scm (str.c_str ()); | 946 // SCM sym = ly_symbol2scm (str.c_str ()); |
933 | 947 |
934 yylval = SCM_UNSPECIFIED; | 948 yylval = SCM_UNSPECIFIED; |
935 int i = lookup_keyword (str); | 949 int i = lookup_keyword (str); |
936 » if (i == MARKUP && is_lyric_state ()) | 950 |
937 » » return LYRIC_MARKUP; | |
938 if (i != -1) | 951 if (i != -1) |
939 return i; | 952 return i; |
940 | 953 |
941 SCM sid = lookup_identifier (str); | 954 SCM sid = lookup_identifier (str); |
| 955 if (Music *m = unsmob_music (sid)) |
| 956 { |
| 957 m->set_spot (override_input (last_input_)); |
| 958 } |
| 959 |
942 if (sid != SCM_UNDEFINED) | 960 if (sid != SCM_UNDEFINED) |
943 return scan_scm_id (sid); | 961 return scan_scm_id (sid); |
944 | 962 |
945 string msg (_f ("unknown escaped string: `\\%s'", str));········ | 963 string msg (_f ("unknown escaped string: `\\%s'", str));········ |
| 964 LexerError (msg.c_str ()); |
| 965 |
| 966 yylval = ly_string2scm (str); |
| 967 |
| 968 return STRING; |
| 969 } |
| 970 |
| 971 int |
| 972 Lily_lexer::scan_shorthand (const string &str) |
| 973 { |
| 974 SCM sid = lookup_identifier (str); |
| 975 if (Music *m = unsmob_music (sid)) |
| 976 { |
| 977 m->set_spot (override_input (last_input_)); |
| 978 } |
| 979 |
| 980 if (sid != SCM_UNDEFINED) |
| 981 return scan_scm_id (sid); |
| 982 |
| 983 string msg (_f ("undefined character or shorthand: %s", str));·· |
946 LexerError (msg.c_str ()); | 984 LexerError (msg.c_str ()); |
947 | 985 |
948 yylval = ly_string2scm (str); | 986 yylval = ly_string2scm (str); |
949 | 987 |
950 return STRING; | 988 return STRING; |
951 } | 989 } |
952 | 990 |
953 int | 991 int |
954 Lily_lexer::scan_scm_id (SCM sid) | 992 Lily_lexer::scan_scm_id (SCM sid) |
955 { | 993 { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1001 if (!scm_is_eq (optional, SCM_UNDEFINED)) | 1039 if (!scm_is_eq (optional, SCM_UNDEFINED)) |
1002 push_extra_token (EXPECT_OPTIONAL, optional); | 1040 push_extra_token (EXPECT_OPTIONAL, optional); |
1003 } | 1041 } |
1004 return funtype; | 1042 return funtype; |
1005 } | 1043 } |
1006 yylval = sid; | 1044 yylval = sid; |
1007 return identifier_type (sid); | 1045 return identifier_type (sid); |
1008 } | 1046 } |
1009 | 1047 |
1010 int | 1048 int |
1011 Lily_lexer::scan_bare_word (string str) | 1049 Lily_lexer::scan_bare_word (const string &str) |
1012 { | 1050 { |
1013 SCM sym = ly_symbol2scm (str.c_str ()); | 1051 SCM sym = ly_symbol2scm (str.c_str ()); |
1014 if ((YYSTATE == notes) || (YYSTATE == chords)) { | 1052 if ((YYSTATE == notes) || (YYSTATE == chords)) { |
1015 SCM handle = SCM_BOOL_F; | 1053 SCM handle = SCM_BOOL_F; |
1016 if (scm_is_pair (pitchname_tab_stack_)) | 1054 if (scm_is_pair (pitchname_tab_stack_)) |
1017 handle = scm_hashq_get_handle (scm_cdar (pitchname_tab_s
tack_), sym); | 1055 handle = scm_hashq_get_handle (scm_cdar (pitchname_tab_s
tack_), sym); |
1018 ················ | 1056 ················ |
1019 if (scm_is_pair (handle)) { | 1057 if (scm_is_pair (handle)) { |
1020 yylval = scm_cdr (handle); | 1058 yylval = scm_cdr (handle); |
1021 if (unsmob_pitch (yylval)) | 1059 if (unsmob_pitch (yylval)) |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1091 { | 1129 { |
1092 error_level_ = 1; | 1130 error_level_ = 1; |
1093 return SCM_UNSPECIFIED; | 1131 return SCM_UNSPECIFIED; |
1094 } | 1132 } |
1095 | 1133 |
1096 if (extra_token && SCM_VALUESP (sval)) | 1134 if (extra_token && SCM_VALUESP (sval)) |
1097 { | 1135 { |
1098 sval = scm_struct_ref (sval, SCM_INUM0); | 1136 sval = scm_struct_ref (sval, SCM_INUM0); |
1099 | 1137 |
1100 if (scm_is_pair (sval)) { | 1138 if (scm_is_pair (sval)) { |
1101 » » » for (SCM v = scm_reverse (scm_cdr (sval)); | 1139 » » » for (SCM p = scm_reverse (scm_cdr (sval)); |
1102 » » » scm_is_pair (v); | 1140 » » » scm_is_pair (p); |
1103 » » » v = scm_cdr (v)) | 1141 » » » p = scm_cdr (p)) |
1104 { | 1142 { |
| 1143 SCM v = scm_car (p); |
| 1144 if (Music *m = unsmob_music (v)) |
| 1145 { |
| 1146 if (!unsmob_input (m->get_property ("ori
gin"))) |
| 1147 m->set_spot (override_input (las
t_input_)); |
| 1148 } |
| 1149 ········································ |
1105 int token; | 1150 int token; |
1106 switch (extra_token) { | 1151 switch (extra_token) { |
1107 case '$': | 1152 case '$': |
1108 » » » » » token = scan_scm_id (scm_car (v)); | 1153 » » » » » token = scan_scm_id (v); |
1109 if (!scm_is_eq (yylval, SCM_UNSPECIFIED)
) | 1154 if (!scm_is_eq (yylval, SCM_UNSPECIFIED)
) |
1110 push_extra_token (token, yylval)
; | 1155 push_extra_token (token, yylval)
; |
1111 break; | 1156 break; |
1112 case '#': | 1157 case '#': |
1113 » » » » » push_extra_token (SCM_IDENTIFIER, scm_ca
r (v)); | 1158 » » » » » push_extra_token (SCM_IDENTIFIER, v); |
1114 break; | 1159 break; |
1115 } | 1160 } |
1116 } | 1161 } |
1117 sval = scm_car (sval); | 1162 sval = scm_car (sval); |
1118 } else | 1163 } else |
1119 sval = SCM_UNSPECIFIED; | 1164 sval = SCM_UNSPECIFIED; |
| 1165 } |
| 1166 |
| 1167 if (Music *m = unsmob_music (sval)) |
| 1168 { |
| 1169 if (!unsmob_input (m->get_property ("origin"))) |
| 1170 m->set_spot (override_input (last_input_)); |
1120 } | 1171 } |
1121 | 1172 |
1122 return sval; | 1173 return sval; |
1123 } | 1174 } |
1124 | 1175 |
1125 /* Check for valid UTF-8 that has no overlong or surrogate codes and | 1176 /* Check for valid UTF-8 that has no overlong or surrogate codes and |
1126 is in the range 0-0x10ffff */ | 1177 is in the range 0-0x10ffff */ |
1127 | 1178 |
1128 const char * | 1179 const char * |
1129 Lily_lexer::YYText_utf8 () | 1180 Lily_lexer::YYText_utf8 () |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1351 { | 1402 { |
1352 (void) yy_start_stack_ptr; | 1403 (void) yy_start_stack_ptr; |
1353 (void) yy_start_stack_depth; | 1404 (void) yy_start_stack_depth; |
1354 (void) yy_start_stack; | 1405 (void) yy_start_stack; |
1355 (void) yy_push_state; | 1406 (void) yy_push_state; |
1356 (void) yy_pop_state; | 1407 (void) yy_pop_state; |
1357 (void) yy_top_state; | 1408 (void) yy_top_state; |
1358 (void) silence_lexer_warnings; | 1409 (void) silence_lexer_warnings; |
1359 } | 1410 } |
1360 #endif | 1411 #endif |
LEFT | RIGHT |