1 %{ // -*- mode: c++; c-file-style: "linux"; indent-tabs-mode: t -*-
3 This file is part of LilyPond, the GNU music typesetter.
5 Copyright (C) 1996--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 Jan Nieuwenhuizen <janneke@gnu.org>
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
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 LilyPond is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
22 /* Mode and indentation are at best a rough approximation based on TAB
23 * formatting (reasonable for compatibility with unspecific editor
24 * modes as Flex modes are hard to find) and need manual correction
25 * frequently. Without a reasonably dependable way of formatting a
26 * Flex file sensibly, there is little point in trying to fix the
27 * inconsistent state of indentation.
33 after making a change to the lexer rules, run
34 flex -b <this lexer file>
37 contains no backup states, but only the reminder
38 Compressed tables always back up.
39 (don-t forget to rm lex.yy.cc :-)
48 /* Flex >= 2.5.29 fix; FlexLexer.h's multiple include bracing breaks
49 when building the actual lexer. */
56 #include "context-def.hh"
57 #include "duration.hh"
58 #include "international.hh"
59 #include "interval.hh"
60 #include "lily-guile.hh"
61 #include "lily-lexer.hh"
62 #include "lily-parser.hh"
63 #include "lilypond-version.hh"
66 #include "music-function.hh"
67 #include "parse-scm.hh"
70 #include "source-file.hh"
71 #include "std-string.hh"
74 #include "lily-imports.hh"
79 #define isatty HORRIBLEKLUDGE
81 void strip_trailing_white (string&);
82 void strip_leading_white (string&);
83 string lyric_fudge (string s);
84 SCM lookup_markup_command (string s);
85 SCM lookup_markup_list_command (string s);
86 bool is_valid_version (string s);
89 #define start_quote() do { \
90 yy_push_state (quote); \
95 The inside of \"violin1" is marked by commandquote mode
98 #define start_command_quote() do { \
99 yy_push_state (commandquote); \
103 #define yylval (*lexval_)
105 #define yylloc (*lexloc_)
107 #define YY_USER_ACTION add_lexed_char (YYLeng ());
110 SCM scan_fraction (string);
111 SCM (* scm_parse_error_handler) (void *);
121 %option yyclass="Lily_lexer"
123 %option never-interactive
140 /* The strategy concerning multibyte characters is to accept them but
141 * call YYText_utf8 for patterns that might contain them, in order to
142 * get a single code path responsible for flagging non-UTF-8 input:
143 * Patterns for accepting only valid UTF-8 without backing up are
144 * really hard to do and complex, and if nice error messages are
145 * wanted, one would need patterns catching the invalid input as well.
147 * Since editors and operating environments don't necessarily behave
148 * reasonably in the presence of mixed encodings, we flag encoding
149 * errors also in identifiers, comments, and strings where it would be
150 * conceivable to just transparently work with the byte string. But
151 * the whole point of caring about UTF-8 in here at all is too avoid
152 * stranger errors later when input passes into backends or log files
153 * or console output or error messages.
160 SYMBOL {A}([-_]{A}|{A})*
162 /* SPECIAL category is for every letter that needs to get passed to
163 * the parser rather than being redefinable by the user */
164 SPECIAL [-+*/=<>{}!?_^'',.:]
170 REAL ({INT}\.{N}*)|(-?\.{N}+)
171 STRICTREAL {UNSIGNED}\.{UNSIGNED}
173 HORIZONTALWHITE [ \t]
179 BOM_UTF8 \357\273\277
185 // swallow and ignore carriage returns
188 /* Use the trailing context feature. Otherwise, the BOM will not be
189 found if the file starts with an identifier definition. */
190 <INITIAL,chords,lyrics,figures,notes>{BOM_UTF8}/.* {
191 if (lexloc_->line_number () != 1 || lexloc_->column_number () != 0)
193 LexerWarning (_ ("stray UTF-8 BOM encountered").c_str ());
196 debug_output (_ ("Skipping UTF-8 BOM"));
199 <INITIAL,chords,figures,incl,lyrics,markup,notes>{
201 yy_push_state (longcomment);
203 %[^{\n\r][^\n\r]*[\n\r]? {
204 (void) YYText_utf8 ();
213 <INITIAL,notes,figures,chords,markup>{
219 <INITIAL,chords,lyrics,notes,figures>\\version{WHITE}* {
220 yy_push_state (version);
222 <INITIAL,chords,lyrics,notes,figures>\\sourcefilename{WHITE}* {
223 yy_push_state (sourcefilename);
225 <INITIAL,chords,lyrics,notes,figures>\\sourcefileline{WHITE}* {
226 yy_push_state (sourcefileline);
228 <version>\"[^""]*\" { /* got the version number */
229 string s (YYText_utf8 () + 1);
230 s = s.substr (0, s.rfind ('\"'));
234 SCM top_scope = scm_car (scm_last_pair (scopes_));
235 scm_module_define (top_scope, ly_symbol2scm ("version-seen"), SCM_BOOL_T);
237 if (!is_valid_version (s)) {
238 yylval = SCM_UNSPECIFIED;
242 <sourcefilename>\"[^""]*\" {
243 string s (YYText_utf8 () + 1);
244 s = s.substr (0, s.rfind ('\"'));
247 here_input().get_source_file ()->name_ = s;
248 message (_f ("Renaming input to: `%s'", s.c_str ()));
249 progress_indication ("\n");
250 scm_module_define (scm_car (scopes_),
251 ly_symbol2scm ("input-file-name"),
256 <sourcefileline>{INT} {
258 sscanf (YYText (), "%d", &i);
261 here_input ().get_source_file ()->set_line (here_input ().start (), i);
264 <version>{ANY_CHAR} {
265 LexerError (_ ("quoted string expected after \\version").c_str ());
268 <sourcefilename>{ANY_CHAR} {
269 LexerError (_ ("quoted string expected after \\sourcefilename").c_str ());
272 <sourcefileline>{ANY_CHAR} {
273 LexerError (_ ("integer expected after \\sourcefileline").c_str ());
278 (void) YYText_utf8 ();
281 (void) YYText_utf8 ();
289 <INITIAL,chords,lyrics,notes,figures>\\maininput {
293 main_input_level_ = include_stack_.size ();
294 is_main_input_ = true;
296 yy_push_state (maininput);
297 yy_push_state (state);
300 LexerError (_ ("\\maininput not allowed outside init files").c_str ());
303 <INITIAL,chords,lyrics,figures,notes>\\include {
304 yy_push_state (incl);
306 <incl>\"[^""]*\" { /* got the include file name */
307 string s (YYText_utf8 ()+1);
308 s = s.substr (0, s.rfind ('"'));
310 new_input (s, sources_);
313 <incl>\\{BLACK}*{WHITE}? { /* got the include identifier */
314 string s = YYText_utf8 () + 1;
315 strip_trailing_white (s);
316 if (s.length () && (s[s.length () - 1] == ';'))
317 s = s.substr (0, s.length () - 1);
319 SCM sid = lookup_identifier (s);
320 if (scm_is_string (sid)) {
321 new_input (ly_scm2string (sid), sources_);
324 string msg (_f ("wrong or undefined identifier: `%s'", s ));
326 LexerError (msg.c_str ());
327 SCM err = scm_current_error_port ();
328 scm_puts ("This value was found in the table: ", err);
329 scm_display (sid, err);
332 <incl>(\$|#) { // scm for the filename
333 Input hi = here_input();
335 SCM sval = ly_parse_scm (hi, be_safe_global && is_main_input_, parser_);
336 sval = eval_scm (sval, hi);
337 int n = hi.end () - hi.start ();
339 for (int i = 0; i < n; i++)
343 char_count_stack_.back () += n;
345 if (scm_is_string (sval)) {
346 new_input (ly_scm2string (sval), sources_);
349 LexerError (_ ("string expected after \\include").c_str ());
350 if (!SCM_UNBNDP (sval)) {
351 SCM err = scm_current_error_port ();
352 scm_puts ("This value was found instead: ", err);
353 scm_display (sval, err);
358 <incl,version,sourcefilename>\"[^""]* { // backup rule
359 LexerError (_ ("end quote missing").c_str ());
363 /* Flex picks the longest matching pattern including trailing
364 * contexts. Without the backup pattern, r-. does not trigger the
365 * {RESTNAME} rule but rather the {SYMBOL}/[-_] rule coming later,
366 * needed for avoiding backup states.
369 <chords,notes,figures>{RESTNAME}/[-_] | // pseudo backup rule
370 <chords,notes,figures>{RESTNAME} {
371 char const *s = YYText ();
372 yylval = scm_from_ascii_string (s);
375 <chords,notes,figures>q/[-_] | // pseudo backup rule
376 <chords,notes,figures>q {
377 yylval = SCM_UNSPECIFIED;
378 return CHORD_REPETITION;
381 <chords,notes,figures>R/[-_] | // pseudo backup rule
382 <chords,notes,figures>R {
383 yylval = SCM_UNSPECIFIED;
384 return MULTI_MEASURE_REST;
386 <INITIAL,chords,figures,lyrics,markup,notes># { //embedded scm
387 Input hi = here_input();
389 SCM sval = ly_parse_scm (hi, be_safe_global && is_main_input_, parser_);
391 if (SCM_UNBNDP (sval))
394 int n = hi.end () - hi.start ();
395 for (int i = 0; i < n; i++)
399 char_count_stack_.back () += n;
405 <INITIAL,chords,figures,lyrics,markup,notes>\$ { //immediate scm
406 Input hi = here_input();
408 SCM sval = ly_parse_scm (hi, be_safe_global && is_main_input_, parser_);
410 int n = hi.end () - hi.start ();
412 for (int i = 0; i < n; i++)
416 char_count_stack_.back () += n;
418 sval = eval_scm (sval, hi, '$');
420 if (YYSTATE == markup && ly_is_procedure (sval))
422 SCM sig = Lily::markup_command_signature (sval);
423 if (scm_is_true (sig))
426 int token = MARKUP_FUNCTION;
427 if (scm_is_true (scm_object_property
428 (sval, ly_symbol2scm ("markup-list-command"))))
429 token = MARKUP_LIST_FUNCTION;
430 push_markup_predicates (sig);
434 int token = scan_scm_id (sval);
435 if (!scm_is_eq (yylval, SCM_UNSPECIFIED))
439 <INITIAL,notes,lyrics,chords>{
441 yylval = SCM_UNSPECIFIED;
442 return DOUBLE_ANGLE_OPEN;
445 yylval = SCM_UNSPECIFIED;
446 return DOUBLE_ANGLE_CLOSE;
450 <INITIAL,notes,chords>{
452 yylval = SCM_UNSPECIFIED;
456 yylval = SCM_UNSPECIFIED;
463 yylval = SCM_UNSPECIFIED;
467 yylval = SCM_UNSPECIFIED;
471 yylval = SCM_UNSPECIFIED;
475 yylval = SCM_UNSPECIFIED;
479 yylval = SCM_UNSPECIFIED;
480 return E_EXCLAMATION;
483 yylval = SCM_UNSPECIFIED;
487 yylval = SCM_UNSPECIFIED;
493 {SYMBOL}/[-_] | // backup rule
495 return scan_bare_word (YYText_utf8 ());
498 start_command_quote ();
500 {COMMAND}/[-_] | // backup rule
502 return scan_escaped_word (YYText_utf8 () + 1);
505 yylval = scan_fraction (YYText ());
509 yylval = scm_c_read_string (YYText ());
512 {UNSIGNED}/[/.] | // backup rule
514 yylval = scm_c_read_string (YYText ());
518 yylval = scm_c_read_string (YYText () + 1);
523 <quote,commandquote>{
525 char c = escaped_char (YYText ()[1]);
526 yylval = scm_cons (scm_from_ascii_stringn (&c, 1),
530 yylval = scm_cons (scm_from_utf8_string (YYText_utf8 ()),
535 /* yylval is union. Must remember STRING before setting SCM*/
537 yylval = scm_string_concatenate_reverse (yylval,
541 if (get_state () == commandquote) {
543 return scan_escaped_word (ly_scm2string (yylval));
551 yylval = scm_cons (scm_from_ascii_string (YYText ()),
561 yylval = scan_fraction (YYText ());
565 yylval = scm_c_read_string (YYText ());
568 {UNSIGNED}/[/.] | // backup rule
570 yylval = scm_c_read_string (YYText ());
574 start_command_quote ();
576 {COMMAND}/[-_] | // backup rule
578 return scan_escaped_word (YYText_utf8 () + 1);
581 // UTF-8 already covered by COMMAND
582 return scan_shorthand (YYText ());
584 /* Characters needed to express durations, assignments */
586 yylval = SCM_UNSPECIFIED;
589 [^|*.=$#{}\"\\ \t\n\r\f0-9][^$#{}\"\\ \t\n\r\f0-9]* {
591 string s (YYText_utf8 ());
592 yylval = SCM_UNSPECIFIED;
598 yylval = ly_string2scm (s);
602 /* This should really just cover {} */
604 yylval = SCM_UNSPECIFIED;
609 {SYMBOL}/[-_] | // backup rule
611 return scan_bare_word (YYText_utf8 ());
614 start_command_quote ();
616 {COMMAND}/[-_] | // backup rule
618 return scan_escaped_word (YYText_utf8 () + 1);
621 yylval = scan_fraction (YYText ());
624 {UNSIGNED}/\/ | // backup rule
626 yylval = scm_c_read_string (YYText ());
630 yylval = SCM_UNSPECIFIED;
634 yylval = SCM_UNSPECIFIED;
638 yylval = SCM_UNSPECIFIED;
642 yylval = SCM_UNSPECIFIED;
646 yylval = SCM_UNSPECIFIED;
654 yylval = SCM_UNSPECIFIED;
658 yylval = SCM_UNSPECIFIED;
662 start_command_quote ();
664 {COMMAND}/[-_] | // backup rule
666 string str (YYText_utf8 () + 1);
668 int token_type = MARKUP_FUNCTION;
669 SCM s = lookup_markup_command (str);
671 // lookup-markup-command returns a pair with the car
672 // being the function to call, and the cdr being the
673 // call signature specified to define-markup-command,
674 // a list of predicates.
676 if (!scm_is_pair (s)) {
677 // If lookup-markup-command was not successful, we
678 // try lookup-markup-list-command instead.
679 // If this fails as well, we just scan and return
681 s = lookup_markup_list_command (str);
683 token_type = MARKUP_LIST_FUNCTION;
685 return scan_escaped_word (str);
688 // If the list of predicates is, say,
689 // (number? number? markup?), then tokens
690 // EXPECT_MARKUP EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
691 // will be generated. Note that we have to push them
692 // in reverse order, so the first token pushed in the
693 // loop will be EXPECT_NO_MORE_ARGS.
697 // yylval now contains the function to call as token
698 // value (for token type MARKUP_FUNCTION or
699 // MARKUP_LIST_FUNCTION).
701 push_markup_predicates (scm_cdr (s));
705 [^$#{}\"\\ \t\n\r\f]+ {
706 string s (YYText_utf8 ());
708 yylval = ly_string2scm (s);
712 yylval = SCM_UNSPECIFIED;
717 <longcomment><<EOF>> {
718 LexerError (_ ("EOF found inside a comment").c_str ());
722 <quote,commandquote><<EOF>> {
723 LexerError (_ ("EOF found inside string").c_str ());
728 yylval = SCM_UNSPECIFIED;
731 is_main_input_ = include_stack_.size () > main_input_level_;
734 main_input_level_ = 0;
736 if (YYSTATE != maininput)
738 LexerError (_ ("Unfinished main input").c_str ());
741 } while (YYSTATE != maininput);
743 extra_tokens_ = SCM_EOL;
746 if (!close_input () || !is_main_input_)
747 /* Returns YY_NULL */
750 else if (!close_input ())
751 /* Returns YY_NULL */
755 <maininput>{ANY_CHAR} {
756 while (include_stack_.size () > main_input_level_
763 {SYMBOL}/[-_] | // backup rule
765 return scan_bare_word (YYText_utf8 ());
768 start_command_quote ();
770 {COMMAND}/[-_] | // backup rule
772 return scan_escaped_word (YYText_utf8 () + 1);
777 yylval = scan_fraction (YYText ());
781 -{UNSIGNED} | // backup rule
783 yylval = scm_c_read_string (YYText ());
787 {UNSIGNED}/\/ | // backup rule
789 yylval = scm_c_read_string (YYText ());
794 -/\. { // backup rule
795 yylval = SCM_UNSPECIFIED;
799 <INITIAL,chords,lyrics,figures,notes>{SPECIAL} {
800 yylval = SCM_UNSPECIFIED;
804 <INITIAL,chords,lyrics,figures,notes>{SHORTHAND} {
805 return scan_shorthand (YYText_utf8 ()); // should not be utf-8
809 string msg = _f ("invalid character: `%s'", YYText_utf8 ());
810 LexerError (msg.c_str ());
811 yylval = SCM_UNSPECIFIED;
812 return '%'; // Better not return half a utf8 character.
817 /* Make the lexer generate a token of the given type as the next token.
818 TODO: make it possible to define a value for the token as well */
820 Lily_lexer::push_extra_token (Input const &where, int token_type, SCM scm)
822 extra_tokens_ = scm_cons (scm_cons2 (where.smobbed_copy (),
823 scm_from_int (token_type),
824 scm), extra_tokens_);
828 Lily_lexer::pop_extra_token ()
830 if (scm_is_null (extra_tokens_))
833 /* produce requested token */
834 yylloc = *unsmob<Input> (scm_caar (extra_tokens_));
835 int type = scm_to_int (scm_cadar (extra_tokens_));
836 yylval = scm_cddar (extra_tokens_);
837 extra_tokens_ = scm_cdr (extra_tokens_);
842 Lily_lexer::push_chord_state (SCM alist)
844 SCM p = scm_assq (alist, pitchname_tab_stack_);
846 if (scm_is_false (p))
847 p = scm_cons (alist, alist_to_hashq (alist));
848 pitchname_tab_stack_ = scm_cons (p, pitchname_tab_stack_);
849 yy_push_state (chords);
853 Lily_lexer::push_figuredbass_state ()
855 yy_push_state (figures);
859 Lily_lexer::push_initial_state ()
861 yy_push_state (INITIAL);
865 Lily_lexer::push_lyric_state ()
867 yy_push_state (lyrics);
871 Lily_lexer::push_markup_state ()
873 yy_push_state (markup);
877 Lily_lexer::push_note_state (SCM alist)
879 SCM p = scm_assq (alist, pitchname_tab_stack_);
881 if (scm_is_false (p))
882 p = scm_cons (alist, alist_to_hashq (alist));
883 pitchname_tab_stack_ = scm_cons (p, pitchname_tab_stack_);
884 yy_push_state (notes);
888 Lily_lexer::pop_state ()
890 if (YYSTATE == notes || YYSTATE == chords)
891 pitchname_tab_stack_ = scm_cdr (pitchname_tab_stack_);
893 // don't cross the maininput threshold
894 if (YYSTATE != maininput)
900 Lily_lexer::push_markup_predicates (SCM sig)
902 push_extra_token (here_input (), EXPECT_NO_MORE_ARGS);
903 for (SCM s = sig; scm_is_pair(s); s = scm_cdr(s)) {
904 SCM predicate = scm_car(s);
906 if (scm_is_eq (predicate, SCM (Lily::markup_list_p)))
907 push_extra_token (here_input (), EXPECT_MARKUP_LIST);
908 else if (scm_is_eq (predicate, SCM (Lily::markup_p)))
909 push_extra_token (here_input (), EXPECT_MARKUP);
911 push_extra_token (here_input (), EXPECT_SCM, predicate);
917 Lily_lexer::identifier_type (SCM sid)
919 int k = try_special_identifiers (&yylval , sid);
920 return k >= 0 ? k : SCM_IDENTIFIER;
925 Lily_lexer::scan_escaped_word (const string &str)
927 // use more SCM for this.
929 // SCM sym = ly_symbol2scm (str.c_str ());
931 yylval = SCM_UNSPECIFIED;
932 int i = lookup_keyword (str);
937 SCM sid = lookup_identifier (str);
938 if (Music *m = unsmob<Music> (sid))
940 m->set_spot (override_input (here_input ()));
943 if (!SCM_UNBNDP (sid))
944 return scan_scm_id (sid);
946 string msg (_f ("unknown escaped string: `\\%s'", str));
947 LexerError (msg.c_str ());
949 yylval = ly_string2scm (str);
951 return STRING; // SYMBOL would cause additional processing
955 Lily_lexer::scan_shorthand (const string &str)
957 SCM sid = lookup_identifier (str);
958 if (Music *m = unsmob<Music> (sid))
960 m->set_spot (override_input (here_input ()));
963 if (!SCM_UNBNDP (sid))
964 return scan_scm_id (sid);
966 string msg (_f ("undefined character or shorthand: %s", str));
967 LexerError (msg.c_str ());
969 yylval = ly_string2scm (str);
975 Lily_lexer::scan_scm_id (SCM sid)
977 if (Music_function *fun = unsmob<Music_function> (sid))
979 int funtype = SCM_FUNCTION;
983 SCM s = fun->get_signature ();
984 SCM cs = scm_car (s);
986 if (scm_is_pair (cs))
991 if (scm_is_eq (cs, SCM (Lily::ly_music_p)))
992 funtype = MUSIC_FUNCTION;
993 else if (scm_is_eq (cs, SCM (Lily::ly_event_p)))
994 funtype = EVENT_FUNCTION;
995 else if (ly_is_procedure (cs))
996 funtype = SCM_FUNCTION;
997 else programming_error ("Bad syntax function predicate");
999 push_extra_token (here_input (), EXPECT_NO_MORE_ARGS);
1000 for (s = scm_cdr (s); scm_is_pair (s); s = scm_cdr (s))
1002 SCM optional = SCM_UNDEFINED;
1005 if (scm_is_pair (cs))
1007 optional = SCM_CDR (cs);
1011 if (ly_is_procedure (cs))
1012 push_extra_token (here_input (), EXPECT_SCM, cs);
1015 programming_error ("Function parameter without type-checking predicate");
1018 if (!scm_is_eq (optional, SCM_UNDEFINED))
1019 push_extra_token (here_input (), EXPECT_OPTIONAL, optional);
1024 return identifier_type (sid);
1028 Lily_lexer::scan_word (SCM & output, SCM sym)
1030 if ((YYSTATE == notes) || (YYSTATE == chords)) {
1031 SCM handle = SCM_BOOL_F;
1032 if (scm_is_pair (pitchname_tab_stack_))
1033 handle = scm_hashq_get_handle (scm_cdar (pitchname_tab_stack_), sym);
1035 if (scm_is_pair (handle)) {
1036 output = scm_cdr (handle);
1037 if (unsmob<Pitch> (yylval))
1038 return (YYSTATE == notes) ? NOTENAME_PITCH : TONICNAME_PITCH;
1039 else if (scm_is_symbol (yylval))
1042 else if ((YYSTATE == chords)
1043 && scm_is_true (handle = scm_hashq_get_handle (chordmodifier_tab_, sym)))
1045 output = scm_cdr (handle);
1046 return CHORD_MODIFIER;
1049 output = SCM_UNDEFINED;
1054 Lily_lexer::scan_bare_word (const string &str)
1056 int state = scan_word (yylval, ly_symbol2scm (str.c_str ()));
1061 yylval = ly_string2scm (str);
1066 Lily_lexer::get_state () const
1072 Lily_lexer::is_note_state () const
1074 return get_state () == notes;
1078 Lily_lexer::is_chord_state () const
1080 return get_state () == chords;
1084 Lily_lexer::is_lyric_state () const
1086 return get_state () == lyrics;
1090 Lily_lexer::is_figure_state () const
1092 return get_state () == figures;
1095 // The extra_token parameter specifies how to convert multiple values
1096 // into additional tokens. For '#', additional values get pushed as
1097 // SCM_IDENTIFIER. For '$', they get checked for their type and get
1098 // pushed as a corresponding *_IDENTIFIER token. Since the latter
1099 // tampers with yylval, it can only be done from the lexer itself, so
1100 // this function is private.
1103 Lily_lexer::eval_scm (SCM readerdata, Input hi, char extra_token)
1105 SCM sval = SCM_UNDEFINED;
1107 if (!SCM_UNBNDP (readerdata))
1109 sval = ly_eval_scm (readerdata,
1111 be_safe_global && is_main_input_,
1115 if (SCM_UNBNDP (sval))
1118 return SCM_UNSPECIFIED;
1121 if (extra_token && SCM_VALUESP (sval))
1123 sval = scm_struct_ref (sval, SCM_INUM0);
1125 if (scm_is_pair (sval)) {
1126 for (SCM p = scm_reverse (scm_cdr (sval));
1130 SCM v = scm_car (p);
1131 if (Music *m = unsmob<Music> (v))
1133 if (!unsmob<Input> (m->get_property ("origin")))
1134 m->set_spot (override_input (here_input ()));
1138 switch (extra_token) {
1140 token = scan_scm_id (v);
1141 if (!scm_is_eq (yylval, SCM_UNSPECIFIED))
1142 push_extra_token (here_input (),
1146 push_extra_token (here_input (),
1151 sval = scm_car (sval);
1153 sval = SCM_UNSPECIFIED;
1156 if (Music *m = unsmob<Music> (sval))
1158 if (!unsmob<Input> (m->get_property ("origin")))
1159 m->set_spot (override_input (here_input ()));
1165 /* Check for valid UTF-8 that has no overlong or surrogate codes and
1166 is in the range 0-0x10ffff */
1169 Lily_lexer::YYText_utf8 ()
1171 const char * const p = YYText ();
1172 for (int i=0; p[i];) {
1173 if ((p[i] & 0xff) < 0x80) {
1177 int oldi = i; // start of character
1178 int more = 0; // # of followup bytes, 0 if bad
1179 switch (p[i++] & 0xff) {
1180 // 0xc0 and 0xc1 are overlong prefixes for
1181 // 0x00-0x3f and 0x40-0x7f respectively, bad.
1182 case 0xc2: // 0x80-0xbf
1183 case 0xc3: // 0xc0-0xff
1184 case 0xc4: // 0x100-0x13f
1185 case 0xc5: // 0x140-0x17f
1186 case 0xc6: // 0x180-0x1bf
1187 case 0xc7: // 0x1c0-0x1ff
1188 case 0xc8: // 0x200-0x23f
1189 case 0xc9: // 0x240-0x27f
1190 case 0xca: // 0x280-0x2bf
1191 case 0xcb: // 0x2c0-0x2ff
1192 case 0xcc: // 0x300-0x33f
1193 case 0xcd: // 0x340-0x37f
1194 case 0xce: // 0x380-0x3bf
1195 case 0xcf: // 0x3c0-0x3ff
1196 case 0xd0: // 0x400-0x43f
1197 case 0xd1: // 0x440-0x47f
1198 case 0xd2: // 0x480-0x4bf
1199 case 0xd3: // 0x4c0-0x4ff
1200 case 0xd4: // 0x500-0x53f
1201 case 0xd5: // 0x540-0x57f
1202 case 0xd6: // 0x580-0x5bf
1203 case 0xd7: // 0x5c0-0x5ff
1204 case 0xd8: // 0x600-0x63f
1205 case 0xd9: // 0x640-0x67f
1206 case 0xda: // 0x680-0x6bf
1207 case 0xdb: // 0x6c0-0x6ff
1208 case 0xdc: // 0x700-0x73f
1209 case 0xdd: // 0x740-0x77f
1210 case 0xde: // 0x780-0x7bf
1211 case 0xdf: // 0x7c0-0x7ff
1212 more = 1; // 2-byte sequences, 0x80-0x7ff
1215 // don't allow overlong sequences for 0-0x7ff
1216 if ((p[i] & 0xff) < 0xa0)
1218 case 0xe1: // 0x1000-0x1fff
1219 case 0xe2: // 0x2000-0x2fff
1220 case 0xe3: // 0x3000-0x3fff
1221 case 0xe4: // 0x4000-0x4fff
1222 case 0xe5: // 0x5000-0x5fff
1223 case 0xe6: // 0x6000-0x6fff
1224 case 0xe7: // 0x7000-0x7fff
1225 case 0xe8: // 0x8000-0x8fff
1226 case 0xe9: // 0x9000-0x9fff
1227 case 0xea: // 0xa000-0xafff
1228 case 0xeb: // 0xb000-0xbfff
1229 case 0xec: // 0xc000-0xcfff
1230 more = 2; // 3-byte sequences, 0x7ff-0xcfff
1232 case 0xed: // 0xd000-0xdfff
1233 // Don't allow surrogate codes 0xd800-0xdfff
1234 if ((p[i] & 0xff) >= 0xa0)
1236 case 0xee: // 0xe000-0xefff
1237 case 0xef: // 0xf000-0xffff
1238 more = 2; // 3-byte sequences,
1239 // 0xd000-0xd7ff, 0xe000-0xffff
1242 // don't allow overlong sequences for 0-0xffff
1243 if ((p[i] & 0xff) < 0x90)
1245 case 0xf1: // 0x40000-0x7ffff
1246 case 0xf2: // 0x80000-0xbffff
1247 case 0xf3: // 0xc0000-0xfffff
1248 more = 3; // 4-byte sequences, 0x10000-0xfffff
1251 // don't allow more than 0x10ffff
1252 if ((p[i] & 0xff) >= 0x90)
1254 more = 3; // 4-byte sequence, 0x100000-0x10ffff
1258 // check that all continuation bytes are valid
1260 if ((p[i++] & 0xc0) != 0x80)
1266 Input h = here_input ();
1267 h.set (h.get_source_file (), h.start () + oldi, h.start () + i);
1268 h.warning (_ ("non-UTF-8 input").c_str ());
1275 urg, belong to string (_convert)
1276 and should be generalised
1279 strip_leading_white (string&s)
1282 for (; i < s.length (); i++)
1283 if (!isspace (s[i]))
1290 strip_trailing_white (string&s)
1292 ssize i = s.length ();
1294 if (!isspace (s[i]))
1297 s = s.substr (0, i + 1);
1302 Lilypond_version oldest_version ("2.7.38");
1306 is_valid_version (string s)
1308 Lilypond_version current ( MAJOR_VERSION "." MINOR_VERSION "." PATCH_LEVEL );
1309 Lilypond_version ver (s);
1312 non_fatal_error (_f ("Invalid version string \"%s\"", s));
1315 if (ver < oldest_version)
1317 non_fatal_error (_f ("file too old: %s (oldest supported: %s)", ver.to_string (), oldest_version.to_string ()));
1318 non_fatal_error (_ ("consider updating the input with the convert-ly script"));
1324 non_fatal_error (_f ("program too old: %s (file requires: %s)", current.to_string (), ver.to_string ()));
1335 lyric_fudge (string s)
1339 while ((i = s.find ('_', i)) != string::npos)
1347 Convert "NUM/DEN" into a '(NUM . DEN) cons.
1350 scan_fraction (string frac)
1352 ssize i = frac.find ('/');
1353 string left = frac.substr (0, i);
1354 string right = frac.substr (i + 1, (frac.length () - i + 1));
1356 return scm_cons (scm_c_read_string (left.c_str ()),
1357 scm_c_read_string (right.c_str ()));
1361 lookup_markup_command (string s)
1363 return Lily::lookup_markup_command (ly_string2scm (s));
1367 lookup_markup_list_command (string s)
1369 return Lily::lookup_markup_list_command (ly_string2scm (s));
1372 /* Shut up lexer warnings. */
1392 silence_lexer_warnings ()
1394 (void) yy_start_stack_ptr;
1395 (void) yy_start_stack_depth;
1396 (void) yy_start_stack;
1397 (void) yy_push_state;
1398 (void) yy_pop_state;
1399 (void) yy_top_state;
1400 (void) silence_lexer_warnings;