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--2012 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"
72 #include "string-convert.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 WORD {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 (this->lexloc_->line_number () != 1 || this->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 this->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 this->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
334 Input hi = here_input();
336 SCM sval = ly_parse_scm (hi.start (), &n, hi,
337 be_safe_global && is_main_input_, parser_);
338 sval = eval_scm (sval);
340 for (int i = 0; i < n; i++)
344 char_count_stack_.back () += n;
346 if (scm_is_string (sval)) {
347 new_input (ly_scm2string (sval), sources_);
350 LexerError (_ ("string expected after \\include").c_str ());
351 if (sval != SCM_UNDEFINED) {
352 SCM err = scm_current_error_port ();
353 scm_puts ("This value was found instead: ", err);
354 scm_display (sval, err);
359 <incl,version,sourcefilename>\"[^""]* { // backup rule
360 LexerError (_ ("end quote missing").c_str ());
364 /* Flex picks the longest matching pattern including trailing
365 * contexts. Without the backup pattern, r-. does not trigger the
366 * {RESTNAME} rule but rather the {WORD}/[-_] rule coming later,
367 * needed for avoiding backup states.
370 <chords,notes,figures>{RESTNAME}/[-_] | // pseudo backup rule
371 <chords,notes,figures>{RESTNAME} {
372 char const *s = YYText ();
373 yylval = scm_from_locale_string (s);
376 <chords,notes,figures>q/[-_] | // pseudo backup rule
377 <chords,notes,figures>q {
378 yylval = SCM_UNSPECIFIED;
379 return CHORD_REPETITION;
382 <chords,notes,figures>R/[-_] | // pseudo backup rule
383 <chords,notes,figures>R {
384 yylval = SCM_UNSPECIFIED;
385 return MULTI_MEASURE_REST;
387 <INITIAL,chords,figures,lyrics,markup,notes># { //embedded scm
389 Input hi = here_input();
391 SCM sval = ly_parse_scm (hi.start (), &n, hi,
392 be_safe_global && is_main_input_, parser_);
394 if (sval == SCM_UNDEFINED)
397 for (int i = 0; i < n; i++)
401 char_count_stack_.back () += n;
407 <INITIAL,chords,figures,lyrics,markup,notes>\$ { //immediate scm
409 Input hi = here_input();
411 SCM sval = ly_parse_scm (hi.start (), &n, hi,
412 be_safe_global && is_main_input_, parser_);
414 for (int i = 0; i < n; i++)
418 char_count_stack_.back () += n;
420 sval = eval_scm (sval, '$');
422 int token = scan_scm_id (sval);
423 if (!scm_is_eq (yylval, SCM_UNSPECIFIED))
427 <INITIAL,notes,lyrics>{
429 yylval = SCM_UNSPECIFIED;
430 return DOUBLE_ANGLE_OPEN;
433 yylval = SCM_UNSPECIFIED;
434 return DOUBLE_ANGLE_CLOSE;
440 yylval = SCM_UNSPECIFIED;
444 yylval = SCM_UNSPECIFIED;
451 yylval = SCM_UNSPECIFIED;
455 yylval = SCM_UNSPECIFIED;
459 yylval = SCM_UNSPECIFIED;
463 yylval = SCM_UNSPECIFIED;
467 yylval = SCM_UNSPECIFIED;
468 return E_EXCLAMATION;
471 yylval = SCM_UNSPECIFIED;
475 yylval = SCM_UNSPECIFIED;
481 {WORD}/[-_] | // backup rule
483 return scan_bare_word (YYText_utf8 ());
486 start_command_quote ();
488 {COMMAND}/[-_] | // backup rule
490 return scan_escaped_word (YYText_utf8 () + 1);
493 yylval = scan_fraction (YYText ());
497 yylval = scm_c_read_string (YYText ());
500 {UNSIGNED}/[/.] | // backup rule
502 yylval = scm_c_read_string (YYText ());
506 yylval = scm_c_read_string (YYText () + 1);
511 <quote,commandquote>{
513 char c = escaped_char (YYText ()[1]);
514 yylval = scm_cons (scm_from_locale_stringn (&c, 1),
518 yylval = scm_cons (scm_from_locale_string (YYText_utf8 ()),
523 /* yylval is union. Must remember STRING before setting SCM*/
525 yylval = scm_string_concatenate_reverse (yylval,
529 if (get_state () == commandquote) {
531 return scan_escaped_word (ly_scm2string (yylval));
539 yylval = scm_cons (scm_from_locale_string (YYText ()),
549 yylval = scan_fraction (YYText ());
553 yylval = scm_c_read_string (YYText ());
556 {UNSIGNED}/[/.] | // backup rule
558 yylval = scm_c_read_string (YYText ());
562 start_command_quote ();
564 {COMMAND}/[-_] | // backup rule
566 return scan_escaped_word (YYText_utf8 () + 1);
569 // UTF-8 already covered by COMMAND
570 return scan_shorthand (YYText ());
572 /* Characters needed to express durations, assignments */
574 yylval = SCM_UNSPECIFIED;
577 [^|*.=$#{}\"\\ \t\n\r\f0-9][^$#{}\"\\ \t\n\r\f0-9]* {
579 string s (YYText_utf8 ());
580 yylval = SCM_UNSPECIFIED;
586 yylval = ly_string2scm (s);
590 /* This should really just cover {} */
592 yylval = SCM_UNSPECIFIED;
597 {WORD}/[-_] | // backup rule
599 return scan_bare_word (YYText_utf8 ());
602 start_command_quote ();
604 {COMMAND}/[-_] | // backup rule
606 return scan_escaped_word (YYText_utf8 () + 1);
609 yylval = scan_fraction (YYText ());
612 {UNSIGNED}/\/ | // backup rule
614 yylval = scm_c_read_string (YYText ());
618 yylval = SCM_UNSPECIFIED;
622 yylval = SCM_UNSPECIFIED;
626 yylval = SCM_UNSPECIFIED;
630 yylval = SCM_UNSPECIFIED;
634 yylval = SCM_UNSPECIFIED;
642 yylval = SCM_UNSPECIFIED;
646 yylval = SCM_UNSPECIFIED;
650 start_command_quote ();
652 {COMMAND}/[-_] | // backup rule
654 string str (YYText_utf8 () + 1);
656 int token_type = MARKUP_FUNCTION;
657 SCM s = lookup_markup_command (str);
659 // lookup-markup-command returns a pair with the car
660 // being the function to call, and the cdr being the
661 // call signature specified to define-markup-command,
662 // a list of predicates.
664 if (!scm_is_pair (s)) {
665 // If lookup-markup-command was not successful, we
666 // try lookup-markup-list-command instead.
667 // If this fails as well, we just scan and return
669 s = lookup_markup_list_command (str);
671 token_type = MARKUP_LIST_FUNCTION;
673 return scan_escaped_word (str);
676 // If the list of predicates is, say,
677 // (number? number? markup?), then tokens
678 // EXPECT_MARKUP EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
679 // will be generated. Note that we have to push them
680 // in reverse order, so the first token pushed in the
681 // loop will be EXPECT_NO_MORE_ARGS.
685 // yylval now contains the function to call as token
686 // value (for token type MARKUP_FUNCTION or
687 // MARKUP_LIST_FUNCTION).
689 push_extra_token(EXPECT_NO_MORE_ARGS);
691 for (; scm_is_pair(s); s = scm_cdr(s)) {
692 SCM predicate = scm_car(s);
694 if (predicate == ly_lily_module_constant ("markup-list?"))
695 push_extra_token(EXPECT_MARKUP_LIST);
696 else if (predicate == ly_lily_module_constant ("markup?"))
697 push_extra_token(EXPECT_MARKUP);
699 push_extra_token(EXPECT_SCM, predicate);
703 [^$#{}\"\\ \t\n\r\f]+ {
704 string s (YYText_utf8 ());
706 yylval = ly_string2scm (s);
710 yylval = SCM_UNSPECIFIED;
715 <longcomment><<EOF>> {
716 LexerError (_ ("EOF found inside a comment").c_str ());
720 <quote,commandquote><<EOF>> {
721 LexerError (_ ("EOF found inside string").c_str ());
726 yylval = SCM_UNSPECIFIED;
729 is_main_input_ = include_stack_.size () > main_input_level_;
732 main_input_level_ = 0;
734 if (YYSTATE != maininput)
736 LexerError (_ ("Unfinished main input").c_str ());
739 } while (YYSTATE != maininput);
741 extra_tokens_ = SCM_EOL;
744 if (!close_input () || !is_main_input_)
745 /* Returns YY_NULL */
748 else if (!close_input ())
749 /* Returns YY_NULL */
753 <maininput>{ANY_CHAR} {
754 while (include_stack_.size () > main_input_level_
761 {WORD}/[-_] | // backup rule
763 return scan_bare_word (YYText_utf8 ());
766 start_command_quote ();
768 {COMMAND}/[-_] | // backup rule
770 return scan_escaped_word (YYText_utf8 () + 1);
775 yylval = scan_fraction (YYText ());
779 -{UNSIGNED} | // backup rule
781 yylval = scm_c_read_string (YYText ());
785 {UNSIGNED}/\/ | // backup rule
787 yylval = scm_c_read_string (YYText ());
792 -/\. { // backup rule
793 yylval = SCM_UNSPECIFIED;
797 <INITIAL,chords,lyrics,figures,notes>{SPECIAL} {
798 yylval = SCM_UNSPECIFIED;
802 <INITIAL,chords,lyrics,figures,notes>{SHORTHAND} {
803 return scan_shorthand (YYText_utf8 ()); // should not be utf-8
807 string msg = _f ("invalid character: `%s'", YYText_utf8 ());
808 LexerError (msg.c_str ());
809 yylval = SCM_UNSPECIFIED;
810 return '%'; // Better not return half a utf8 character.
815 /* Make the lexer generate a token of the given type as the next token.
816 TODO: make it possible to define a value for the token as well */
818 Lily_lexer::push_extra_token (int token_type, SCM scm)
820 extra_tokens_ = scm_acons (scm_from_int (token_type), scm, extra_tokens_);
824 Lily_lexer::pop_extra_token ()
826 if (scm_is_null (extra_tokens_))
829 /* produce requested token */
830 int type = scm_to_int (scm_caar (extra_tokens_));
831 yylval = scm_cdar (extra_tokens_);
832 extra_tokens_ = scm_cdr (extra_tokens_);
837 Lily_lexer::push_chord_state (SCM alist)
839 SCM p = scm_assq (alist, pitchname_tab_stack_);
841 if (scm_is_false (p))
842 p = scm_cons (alist, alist_to_hashq (alist));
843 pitchname_tab_stack_ = scm_cons (p, pitchname_tab_stack_);
844 yy_push_state (chords);
848 Lily_lexer::push_figuredbass_state ()
850 yy_push_state (figures);
854 Lily_lexer::push_initial_state ()
856 yy_push_state (INITIAL);
860 Lily_lexer::push_lyric_state ()
862 yy_push_state (lyrics);
866 Lily_lexer::push_markup_state ()
868 yy_push_state (markup);
872 Lily_lexer::push_note_state (SCM alist)
874 SCM p = scm_assq (alist, pitchname_tab_stack_);
876 if (scm_is_false (p))
877 p = scm_cons (alist, alist_to_hashq (alist));
878 pitchname_tab_stack_ = scm_cons (p, pitchname_tab_stack_);
879 yy_push_state (notes);
883 Lily_lexer::pop_state ()
885 if (YYSTATE == notes || YYSTATE == chords)
886 pitchname_tab_stack_ = scm_cdr (pitchname_tab_stack_);
888 // don't cross the maininput threshold
889 if (YYSTATE != maininput)
895 Lily_lexer::identifier_type (SCM sid)
897 int k = try_special_identifiers (&yylval , sid);
898 return k >= 0 ? k : SCM_IDENTIFIER;
903 Lily_lexer::scan_escaped_word (const string &str)
905 // use more SCM for this.
907 // SCM sym = ly_symbol2scm (str.c_str ());
909 yylval = SCM_UNSPECIFIED;
910 int i = lookup_keyword (str);
915 SCM sid = lookup_identifier (str);
916 if (Music *m = unsmob_music (sid))
918 m->set_spot (override_input (here_input ()));
921 if (sid != SCM_UNDEFINED)
922 return scan_scm_id (sid);
924 string msg (_f ("unknown escaped string: `\\%s'", str));
925 LexerError (msg.c_str ());
927 yylval = ly_string2scm (str);
933 Lily_lexer::scan_shorthand (const string &str)
935 SCM sid = lookup_identifier (str);
936 if (Music *m = unsmob_music (sid))
938 m->set_spot (override_input (here_input ()));
941 if (sid != SCM_UNDEFINED)
942 return scan_scm_id (sid);
944 string msg (_f ("undefined character or shorthand: %s", str));
945 LexerError (msg.c_str ());
947 yylval = ly_string2scm (str);
953 Lily_lexer::scan_scm_id (SCM sid)
955 if (is_music_function (sid))
957 int funtype = SCM_FUNCTION;
961 SCM s = get_music_function_signature (sid);
962 SCM cs = scm_car (s);
964 if (scm_is_pair (cs))
969 if (scm_is_eq (cs, ly_lily_module_constant ("ly:music?")))
970 funtype = MUSIC_FUNCTION;
971 else if (scm_is_eq (cs, ly_lily_module_constant ("ly:event?")))
972 funtype = EVENT_FUNCTION;
973 else if (ly_is_procedure (cs))
974 funtype = SCM_FUNCTION;
975 else programming_error ("Bad syntax function predicate");
977 push_extra_token (EXPECT_NO_MORE_ARGS);
978 for (s = scm_cdr (s); scm_is_pair (s); s = scm_cdr (s))
980 SCM optional = SCM_UNDEFINED;
983 if (scm_is_pair (cs))
985 optional = SCM_CDR (cs);
989 if (ly_is_procedure (cs))
990 push_extra_token (EXPECT_SCM, cs);
993 programming_error ("Function parameter without type-checking predicate");
996 if (!scm_is_eq (optional, SCM_UNDEFINED))
997 push_extra_token (EXPECT_OPTIONAL, optional);
1002 return identifier_type (sid);
1006 Lily_lexer::scan_bare_word (const string &str)
1008 SCM sym = ly_symbol2scm (str.c_str ());
1009 if ((YYSTATE == notes) || (YYSTATE == chords)) {
1010 SCM handle = SCM_BOOL_F;
1011 if (scm_is_pair (pitchname_tab_stack_))
1012 handle = scm_hashq_get_handle (scm_cdar (pitchname_tab_stack_), sym);
1014 if (scm_is_pair (handle)) {
1015 yylval = scm_cdr (handle);
1016 if (unsmob_pitch (yylval))
1017 return (YYSTATE == notes) ? NOTENAME_PITCH : TONICNAME_PITCH;
1018 else if (scm_is_symbol (yylval))
1021 else if ((YYSTATE == chords)
1022 && (handle = scm_hashq_get_handle (chordmodifier_tab_, sym))!= SCM_BOOL_F)
1024 yylval = scm_cdr (handle);
1025 return CHORD_MODIFIER;
1028 yylval = ly_string2scm (str);
1033 Lily_lexer::get_state () const
1039 Lily_lexer::is_note_state () const
1041 return get_state () == notes;
1045 Lily_lexer::is_chord_state () const
1047 return get_state () == chords;
1051 Lily_lexer::is_lyric_state () const
1053 return get_state () == lyrics;
1057 Lily_lexer::is_figure_state () const
1059 return get_state () == figures;
1062 // The extra_token parameter specifies how to convert multiple values
1063 // into additional tokens. For '#', additional values get pushed as
1064 // SCM_IDENTIFIER. For '$', they get checked for their type and get
1065 // pushed as a corresponding *_IDENTIFIER token. Since the latter
1066 // tampers with yylval, it can only be done from the lexer itself, so
1067 // this function is private.
1070 Lily_lexer::eval_scm (SCM readerdata, char extra_token)
1072 SCM sval = SCM_UNDEFINED;
1074 if (!SCM_UNBNDP (readerdata))
1076 sval = ly_eval_scm (scm_car (readerdata),
1077 *unsmob_input (scm_cdr (readerdata)),
1078 be_safe_global && is_main_input_,
1082 if (SCM_UNBNDP (sval))
1085 return SCM_UNSPECIFIED;
1088 if (extra_token && SCM_VALUESP (sval))
1090 sval = scm_struct_ref (sval, SCM_INUM0);
1092 if (scm_is_pair (sval)) {
1093 for (SCM p = scm_reverse (scm_cdr (sval));
1097 SCM v = scm_car (p);
1098 if (Music *m = unsmob_music (v))
1100 if (!unsmob_input (m->get_property ("origin")))
1101 m->set_spot (override_input (here_input ()));
1105 switch (extra_token) {
1107 token = scan_scm_id (v);
1108 if (!scm_is_eq (yylval, SCM_UNSPECIFIED))
1109 push_extra_token (token, yylval);
1112 push_extra_token (SCM_IDENTIFIER, v);
1116 sval = scm_car (sval);
1118 sval = SCM_UNSPECIFIED;
1121 if (Music *m = unsmob_music (sval))
1123 if (!unsmob_input (m->get_property ("origin")))
1124 m->set_spot (override_input (here_input ()));
1130 /* Check for valid UTF-8 that has no overlong or surrogate codes and
1131 is in the range 0-0x10ffff */
1134 Lily_lexer::YYText_utf8 ()
1136 const char * const p = YYText ();
1137 for (int i=0; p[i];) {
1138 if ((p[i] & 0xff) < 0x80) {
1142 int oldi = i; // start of character
1143 int more = 0; // # of followup bytes, 0 if bad
1144 switch (p[i++] & 0xff) {
1145 // 0xc0 and 0xc1 are overlong prefixes for
1146 // 0x00-0x3f and 0x40-0x7f respectively, bad.
1147 case 0xc2: // 0x80-0xbf
1148 case 0xc3: // 0xc0-0xff
1149 case 0xc4: // 0x100-0x13f
1150 case 0xc5: // 0x140-0x17f
1151 case 0xc6: // 0x180-0x1bf
1152 case 0xc7: // 0x1c0-0x1ff
1153 case 0xc8: // 0x200-0x23f
1154 case 0xc9: // 0x240-0x27f
1155 case 0xca: // 0x280-0x2bf
1156 case 0xcb: // 0x2c0-0x2ff
1157 case 0xcc: // 0x300-0x33f
1158 case 0xcd: // 0x340-0x37f
1159 case 0xce: // 0x380-0x3bf
1160 case 0xcf: // 0x3c0-0x3ff
1161 case 0xd0: // 0x400-0x43f
1162 case 0xd1: // 0x440-0x47f
1163 case 0xd2: // 0x480-0x4bf
1164 case 0xd3: // 0x4c0-0x4ff
1165 case 0xd4: // 0x500-0x53f
1166 case 0xd5: // 0x540-0x57f
1167 case 0xd6: // 0x580-0x5bf
1168 case 0xd7: // 0x5c0-0x5ff
1169 case 0xd8: // 0x600-0x63f
1170 case 0xd9: // 0x640-0x67f
1171 case 0xda: // 0x680-0x6bf
1172 case 0xdb: // 0x6c0-0x6ff
1173 case 0xdc: // 0x700-0x73f
1174 case 0xdd: // 0x740-0x77f
1175 case 0xde: // 0x780-0x7bf
1176 case 0xdf: // 0x7c0-0x7ff
1177 more = 1; // 2-byte sequences, 0x80-0x7ff
1180 // don't allow overlong sequences for 0-0x7ff
1181 if ((p[i] & 0xff) < 0xa0)
1183 case 0xe1: // 0x1000-0x1fff
1184 case 0xe2: // 0x2000-0x2fff
1185 case 0xe3: // 0x3000-0x3fff
1186 case 0xe4: // 0x4000-0x4fff
1187 case 0xe5: // 0x5000-0x5fff
1188 case 0xe6: // 0x6000-0x6fff
1189 case 0xe7: // 0x7000-0x7fff
1190 case 0xe8: // 0x8000-0x8fff
1191 case 0xe9: // 0x9000-0x9fff
1192 case 0xea: // 0xa000-0xafff
1193 case 0xeb: // 0xb000-0xbfff
1194 case 0xec: // 0xc000-0xcfff
1195 more = 2; // 3-byte sequences, 0x7ff-0xcfff
1197 case 0xed: // 0xd000-0xdfff
1198 // Don't allow surrogate codes 0xd800-0xdfff
1199 if ((p[i] & 0xff) >= 0xa0)
1201 case 0xee: // 0xe000-0xefff
1202 case 0xef: // 0xf000-0xffff
1203 more = 2; // 3-byte sequences,
1204 // 0xd000-0xd7ff, 0xe000-0xffff
1207 // don't allow overlong sequences for 0-0xffff
1208 if ((p[i] & 0xff) < 0x90)
1210 case 0xf1: // 0x40000-0x7ffff
1211 case 0xf2: // 0x80000-0xbffff
1212 case 0xf3: // 0xc0000-0xfffff
1213 more = 3; // 4-byte sequences, 0x10000-0xfffff
1216 // don't allow more than 0x10ffff
1217 if ((p[i] & 0xff) >= 0x90)
1219 more = 3; // 4-byte sequence, 0x100000-0x10ffff
1223 // check that all continuation bytes are valid
1225 if ((p[i++] & 0xc0) != 0x80)
1231 Input h = here_input ();
1232 h.set (h.get_source_file (), h.start () + oldi, h.start () + i);
1233 h.warning (_ ("non-UTF-8 input").c_str ());
1240 urg, belong to string (_convert)
1241 and should be generalised
1244 strip_leading_white (string&s)
1247 for (; i < s.length (); i++)
1248 if (!isspace (s[i]))
1255 strip_trailing_white (string&s)
1257 ssize i = s.length ();
1259 if (!isspace (s[i]))
1262 s = s.substr (0, i + 1);
1267 Lilypond_version oldest_version ("2.7.38");
1271 is_valid_version (string s)
1273 Lilypond_version current ( MAJOR_VERSION "." MINOR_VERSION "." PATCH_LEVEL );
1274 Lilypond_version ver (s);
1275 if (int (ver) < oldest_version)
1277 non_fatal_error (_f ("file too old: %s (oldest supported: %s)", ver.to_string (), oldest_version.to_string ()));
1278 non_fatal_error (_ ("consider updating the input with the convert-ly script"));
1284 non_fatal_error (_f ("program too old: %s (file requires: %s)", current.to_string (), ver.to_string ()));
1295 lyric_fudge (string s)
1299 while ((i = s.find ('_', i)) != string::npos)
1307 Convert "NUM/DEN" into a '(NUM . DEN) cons.
1310 scan_fraction (string frac)
1312 ssize i = frac.find ('/');
1313 string left = frac.substr (0, i);
1314 string right = frac.substr (i + 1, (frac.length () - i + 1));
1316 int n = String_convert::dec2int (left);
1317 int d = String_convert::dec2int (right);
1318 return scm_cons (scm_from_int (n), scm_from_int (d));
1322 lookup_markup_command (string s)
1324 SCM proc = ly_lily_module_constant ("lookup-markup-command");
1325 return scm_call_1 (proc, ly_string2scm (s));
1329 lookup_markup_list_command (string s)
1331 SCM proc = ly_lily_module_constant ("lookup-markup-list-command");
1332 return scm_call_1 (proc, ly_string2scm (s));
1335 /* Shut up lexer warnings. */
1355 silence_lexer_warnings ()
1357 (void) yy_start_stack_ptr;
1358 (void) yy_start_stack_depth;
1359 (void) yy_start_stack;
1360 (void) yy_push_state;
1361 (void) yy_pop_state;
1362 (void) yy_top_state;
1363 (void) silence_lexer_warnings;