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); \
94 #define yylval (*lexval_)
96 #define yylloc (*lexloc_)
98 #define YY_USER_ACTION add_lexed_char (YYLeng ());
101 SCM scan_fraction (string);
102 SCM (* scm_parse_error_handler) (void *);
112 %option yyclass="Lily_lexer"
114 %option never-interactive
131 /* The strategy concerning multibyte characters is to accept them but
132 * call YYText_utf8 for patterns that might contain them, in order to
133 * get a single code path responsible for flagging non-UTF-8 input:
134 * Patterns for accepting only valid UTF-8 without backing up are
135 * really hard to do and complex, and if nice error messages are
136 * wanted, one would need patterns catching the invalid input as well.
138 * Since editors and operating environments don't necessarily behave
139 * reasonably in the presence of mixed encodings, we flag encoding
140 * errors also in identifiers, comments, and strings where it would be
141 * conceivable to just transparently work with the byte string. But
142 * the whole point of caring about UTF-8 in here at all is too avoid
143 * stranger errors later when input passes into backends or log files
144 * or console output or error messages.
151 WORD {A}([-_]{A}|{A})*
158 REAL ({INT}\.{N}*)|(-?\.{N}+)
160 HORIZONTALWHITE [ \t]
166 BOM_UTF8 \357\273\277
172 // swallow and ignore carriage returns
175 <extratoken>{ANY_CHAR} {
176 /* Generate a token without swallowing anything */
178 /* First unswallow the eaten character */
179 add_lexed_char (-YYLeng ());
182 /* produce requested token */
183 int type = scm_to_int (scm_caar (extra_tokens_));
184 yylval = scm_cdar (extra_tokens_);
185 extra_tokens_ = scm_cdr (extra_tokens_);
186 if (scm_is_null (extra_tokens_))
192 <extratoken><<EOF>> {
193 /* Generate a token without swallowing anything */
195 /* produce requested token */
196 int type = scm_to_int (scm_caar (extra_tokens_));
197 yylval = scm_cdar (extra_tokens_);
198 extra_tokens_ = scm_cdr (extra_tokens_);
199 if (scm_is_null (extra_tokens_))
205 /* Use the trailing context feature. Otherwise, the BOM will not be
206 found if the file starts with an identifier definition. */
207 <INITIAL,chords,lyrics,figures,notes>{BOM_UTF8}/.* {
208 if (this->lexloc_->line_number () != 1 || this->lexloc_->column_number () != 0)
210 LexerWarning (_ ("stray UTF-8 BOM encountered").c_str ());
213 debug_output (_ ("Skipping UTF-8 BOM"));
216 <INITIAL,chords,figures,incl,lyrics,markup,notes>{
218 yy_push_state (longcomment);
220 %[^{\n\r][^\n\r]*[\n\r] {
221 (void) YYText_utf8 ();
223 %[^{\n\r] { // backup rule
224 (void) YYText_utf8 ();
229 (void) YYText_utf8 ();
236 <INITIAL,notes,figures,chords,markup>{
242 <INITIAL,chords,lyrics,notes,figures>\\version{WHITE}* {
243 yy_push_state (version);
245 <INITIAL,chords,lyrics,notes,figures>\\sourcefilename{WHITE}* {
246 yy_push_state (sourcefilename);
248 <INITIAL,chords,lyrics,notes,figures>\\sourcefileline{WHITE}* {
249 yy_push_state (sourcefileline);
251 <version>\"[^""]*\" { /* got the version number */
252 string s (YYText_utf8 () + 1);
253 s = s.substr (0, s.rfind ('\"'));
257 SCM top_scope = scm_car (scm_last_pair (scopes_));
258 scm_module_define (top_scope, ly_symbol2scm ("version-seen"), SCM_BOOL_T);
260 if (!is_valid_version (s)) {
261 yylval = SCM_UNSPECIFIED;
265 <sourcefilename>\"[^""]*\" {
266 string s (YYText_utf8 () + 1);
267 s = s.substr (0, s.rfind ('\"'));
270 this->here_input().get_source_file ()->name_ = s;
271 message (_f ("Renaming input to: `%s'", s.c_str ()));
272 progress_indication ("\n");
273 scm_module_define (scm_car (scopes_),
274 ly_symbol2scm ("input-file-name"),
279 <sourcefileline>{INT} {
281 sscanf (YYText (), "%d", &i);
284 this->here_input ().get_source_file ()->set_line (here_input ().start (), i);
287 <version>{ANY_CHAR} {
288 LexerError (_ ("quoted string expected after \\version").c_str ());
291 <sourcefilename>{ANY_CHAR} {
292 LexerError (_ ("quoted string expected after \\sourcefilename").c_str ());
295 <sourcefileline>{ANY_CHAR} {
296 LexerError (_ ("integer expected after \\sourcefileline").c_str ());
301 (void) YYText_utf8 ();
304 (void) YYText_utf8 ();
312 <INITIAL,chords,lyrics,notes,figures>\\maininput {
316 main_input_level_ = include_stack_.size ();
317 is_main_input_ = true;
319 yy_push_state (maininput);
320 yy_push_state (state);
323 error (_ ("\\maininput not allowed outside init files"));
326 <INITIAL,chords,lyrics,figures,notes>\\include {
327 yy_push_state (incl);
329 <incl>\"[^""]*\" { /* got the include file name */
330 string s (YYText_utf8 ()+1);
331 s = s.substr (0, s.rfind ('"'));
333 new_input (s, sources_);
336 <incl>\\{BLACK}*{WHITE}? { /* got the include identifier */
337 string s = YYText_utf8 () + 1;
338 strip_trailing_white (s);
339 if (s.length () && (s[s.length () - 1] == ';'))
340 s = s.substr (0, s.length () - 1);
342 SCM sid = lookup_identifier (s);
343 if (scm_is_string (sid)) {
344 new_input (ly_scm2string (sid), sources_);
347 string msg (_f ("wrong or undefined identifier: `%s'", s ));
349 LexerError (msg.c_str ());
350 SCM err = scm_current_error_port ();
351 scm_puts ("This value was found in the table: ", err);
352 scm_display (sid, err);
355 <incl>(\$|#) { // scm for the filename
357 Input hi = here_input();
359 SCM sval = ly_parse_scm (hi.start (), &n, hi,
360 be_safe_global && is_main_input_, parser_);
361 sval = eval_scm (sval);
363 for (int i = 0; i < n; i++)
367 char_count_stack_.back () += n;
369 if (scm_is_string (sval)) {
370 new_input (ly_scm2string (sval), sources_);
373 LexerError (_ ("string expected after \\include").c_str ());
374 if (sval != SCM_UNDEFINED) {
375 SCM err = scm_current_error_port ();
376 scm_puts ("This value was found instead: ", err);
377 scm_display (sval, err);
382 <incl,version,sourcefilename>\"[^""]* { // backup rule
383 error (_ ("end quote missing"));
387 /* Flex picks the longest matching pattern including trailing
388 * contexts. Without the backup pattern, r-. does not trigger the
389 * {RESTNAME} rule but rather the {WORD}/[-_] rule coming later,
390 * needed for avoiding backup states.
393 <chords,notes,figures>{RESTNAME}/[-_] | // pseudo backup rule
394 <chords,notes,figures>{RESTNAME} {
395 char const *s = YYText ();
396 yylval = scm_from_locale_string (s);
399 <chords,notes,figures>q/[-_] | // pseudo backup rule
400 <chords,notes,figures>q {
401 yylval = SCM_UNSPECIFIED;
402 return CHORD_REPETITION;
405 <chords,notes,figures>R/[-_] | // pseudo backup rule
406 <chords,notes,figures>R {
407 yylval = SCM_UNSPECIFIED;
408 return MULTI_MEASURE_REST;
410 <INITIAL,chords,figures,lyrics,markup,notes># { //embedded scm
412 Input hi = here_input();
414 SCM sval = ly_parse_scm (hi.start (), &n, hi,
415 be_safe_global && is_main_input_, parser_);
417 if (sval == SCM_UNDEFINED)
420 for (int i = 0; i < n; i++)
424 char_count_stack_.back () += n;
430 <INITIAL,chords,figures,lyrics,markup,notes>\$ { //immediate scm
432 Input hi = here_input();
434 SCM sval = ly_parse_scm (hi.start (), &n, hi,
435 be_safe_global && is_main_input_, parser_);
437 for (int i = 0; i < n; i++)
441 char_count_stack_.back () += n;
443 sval = eval_scm (sval, '$');
445 int token = scan_scm_id (sval);
446 if (!scm_is_eq (yylval, SCM_UNSPECIFIED))
450 <INITIAL,notes,lyrics>{
452 yylval = SCM_UNSPECIFIED;
453 return DOUBLE_ANGLE_OPEN;
456 yylval = SCM_UNSPECIFIED;
457 return DOUBLE_ANGLE_CLOSE;
463 yylval = SCM_UNSPECIFIED;
467 yylval = SCM_UNSPECIFIED;
474 yylval = SCM_UNSPECIFIED;
478 yylval = SCM_UNSPECIFIED;
482 yylval = SCM_UNSPECIFIED;
488 {WORD}/[-_] | // backup rule
490 return scan_bare_word (YYText_utf8 ());
493 {COMMAND}/[-_] | // backup rule
495 return scan_escaped_word (YYText_utf8 () + 1);
498 yylval = scan_fraction (YYText ());
501 {UNSIGNED}/\/ | // backup rule
503 yylval = scm_c_read_string (YYText ());
507 yylval = scm_c_read_string (YYText () + 1);
514 char c = escaped_char (YYText ()[1]);
515 yylval = scm_cons (scm_from_locale_stringn (&c, 1),
519 yylval = scm_cons (scm_from_locale_string (YYText_utf8 ()),
526 /* yylval is union. Must remember STRING before setting SCM*/
528 yylval = scm_string_concatenate_reverse (yylval,
535 yylval = scm_cons (scm_from_locale_string (YYText ()),
545 yylval = scan_fraction (YYText ());
548 {UNSIGNED}/\/ | // backup rule
550 yylval = scm_c_read_string (YYText ());
553 {COMMAND}/[-_] | // backup rule
555 return scan_escaped_word (YYText_utf8 () + 1);
557 /* Characters needed to express durations, assignments, barchecks */
559 yylval = SCM_UNSPECIFIED;
562 [^$#{}\"\\ \t\n\r\f0-9]+ {
564 string s (YYText_utf8 ());
565 yylval = SCM_UNSPECIFIED;
571 yylval = ly_string2scm (s);
575 /* This should really just cover {} */
577 yylval = SCM_UNSPECIFIED;
578 return YYText ()[0]; // above catches all multibytes.
582 {WORD}/[-_] | // backup rule
584 return scan_bare_word (YYText_utf8 ());
586 {COMMAND}/[-_] | // backup rule
588 return scan_escaped_word (YYText_utf8 () + 1);
591 yylval = scan_fraction (YYText ());
594 {UNSIGNED}/\/ | // backup rule
596 yylval = scm_c_read_string (YYText ());
600 yylval = SCM_UNSPECIFIED;
604 yylval = SCM_UNSPECIFIED;
608 yylval = SCM_UNSPECIFIED;
612 yylval = SCM_UNSPECIFIED;
616 yylval = SCM_UNSPECIFIED;
620 yylval = SCM_UNSPECIFIED;
621 return YYText ()[0]; // WORD catches all multibyte.
628 yylval = SCM_UNSPECIFIED;
631 {COMMAND}/[-_] | // backup rule
633 string str (YYText_utf8 () + 1);
635 int token_type = MARKUP_FUNCTION;
636 SCM s = lookup_markup_command (str);
638 // lookup-markup-command returns a pair with the car
639 // being the function to call, and the cdr being the
640 // call signature specified to define-markup-command,
641 // a list of predicates.
643 if (!scm_is_pair (s)) {
644 // If lookup-markup-command was not successful, we
645 // try lookup-markup-list-command instead.
646 // If this fails as well, we just scan and return
648 s = lookup_markup_list_command (str);
650 token_type = MARKUP_LIST_FUNCTION;
652 return scan_escaped_word (str);
655 // If the list of predicates is, say,
656 // (number? number? markup?), then tokens
657 // EXPECT_MARKUP EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
658 // will be generated. Note that we have to push them
659 // in reverse order, so the first token pushed in the
660 // loop will be EXPECT_NO_MORE_ARGS.
664 // yylval now contains the function to call as token
665 // value (for token type MARKUP_FUNCTION or
666 // MARKUP_LIST_FUNCTION).
668 push_extra_token(EXPECT_NO_MORE_ARGS);
670 for (; scm_is_pair(s); s = scm_cdr(s)) {
671 SCM predicate = scm_car(s);
673 if (predicate == ly_lily_module_constant ("markup-list?"))
674 push_extra_token(EXPECT_MARKUP_LIST);
675 else if (predicate == ly_lily_module_constant ("markup?"))
676 push_extra_token(EXPECT_MARKUP);
678 push_extra_token(EXPECT_SCM, predicate);
682 [^$#{}\"\\ \t\n\r\f]+ {
683 string s (YYText_utf8 ());
685 yylval = ly_string2scm (s);
689 yylval = SCM_UNSPECIFIED;
690 return YYText ()[0]; // Above is catchall for multibyte
694 <longcomment><<EOF>> {
695 LexerError (_ ("EOF found inside a comment").c_str ());
700 LexerError (_ ("EOF found inside string").c_str ());
705 yylval = SCM_UNSPECIFIED;
708 is_main_input_ = include_stack_.size () > main_input_level_;
711 main_input_level_ = 0;
713 if (YYSTATE != maininput)
715 LexerError (_ ("Unfinished main input").c_str ());
718 } while (YYSTATE != maininput);
722 if (!close_input () || !is_main_input_)
723 /* Returns YY_NULL */
726 else if (!close_input ())
727 /* Returns YY_NULL */
732 while (include_stack_.size () > main_input_level_
739 {WORD}/[-_] | // backup rule
741 return scan_bare_word (YYText_utf8 ());
743 {COMMAND}/[-_] | // backup rule
745 return scan_escaped_word (YYText_utf8 () + 1);
750 yylval = scan_fraction (YYText ());
754 -{UNSIGNED} | // backup rule
756 yylval = scm_c_read_string (YYText ());
760 {UNSIGNED}/\/ | // backup rule
762 yylval = scm_c_read_string (YYText ());
768 yylval = SCM_UNSPECIFIED;
772 -/\. | // backup rule
774 yylval = SCM_UNSPECIFIED;
778 <INITIAL,notes,figures>. {
779 yylval = SCM_UNSPECIFIED;
783 <INITIAL,lyrics,notes,figures>\\. {
784 yylval = SCM_UNSPECIFIED;
785 char c = YYText ()[1];
789 return E_ANGLE_CLOSE;
793 return E_EXCLAMATION;
799 return E_BRACKET_OPEN;
803 return E_BRACKET_CLOSE;
815 string msg = _f ("invalid character: `%s'", YYText_utf8 ());
816 LexerError (msg.c_str ());
817 yylval = SCM_UNSPECIFIED;
818 return '%'; // Better not return half a utf8 character.
823 /* Make the lexer generate a token of the given type as the next token.
824 TODO: make it possible to define a value for the token as well */
826 Lily_lexer::push_extra_token (int token_type, SCM scm)
828 if (scm_is_null (extra_tokens_))
830 if (YY_START != extratoken)
831 hidden_state_ = YY_START;
832 yy_push_state (extratoken);
834 extra_tokens_ = scm_acons (scm_from_int (token_type), scm, extra_tokens_);
838 Lily_lexer::push_chord_state (SCM alist)
840 SCM p = scm_assq (alist, pitchname_tab_stack_);
842 if (scm_is_false (p))
843 p = scm_cons (alist, alist_to_hashq (alist));
844 pitchname_tab_stack_ = scm_cons (p, pitchname_tab_stack_);
845 yy_push_state (chords);
849 Lily_lexer::push_figuredbass_state ()
851 yy_push_state (figures);
855 Lily_lexer::push_initial_state ()
857 yy_push_state (INITIAL);
861 Lily_lexer::push_lyric_state ()
863 yy_push_state (lyrics);
867 Lily_lexer::push_markup_state ()
869 yy_push_state (markup);
873 Lily_lexer::push_note_state (SCM alist)
875 bool extra = (YYSTATE == extratoken);
877 SCM p = scm_assq (alist, pitchname_tab_stack_);
882 if (scm_is_false (p))
883 p = scm_cons (alist, alist_to_hashq (alist));
884 pitchname_tab_stack_ = scm_cons (p, pitchname_tab_stack_);
885 yy_push_state (notes);
888 hidden_state_ = YYSTATE;
889 yy_push_state (extratoken);
894 Lily_lexer::pop_state ()
896 bool extra = (YYSTATE == extratoken);
901 if (YYSTATE == notes || YYSTATE == chords)
902 pitchname_tab_stack_ = scm_cdr (pitchname_tab_stack_);
907 hidden_state_ = YYSTATE;
908 yy_push_state (extratoken);
913 Lily_lexer::identifier_type (SCM sid)
915 int k = try_special_identifiers (&yylval , sid);
916 return k >= 0 ? k : SCM_IDENTIFIER;
921 Lily_lexer::scan_escaped_word (string str)
923 // use more SCM for this.
925 // SCM sym = ly_symbol2scm (str.c_str ());
927 yylval = SCM_UNSPECIFIED;
928 int i = lookup_keyword (str);
933 SCM sid = lookup_identifier (str);
934 if (sid != SCM_UNDEFINED)
935 return scan_scm_id (sid);
937 string msg (_f ("unknown escaped string: `\\%s'", str));
938 LexerError (msg.c_str ());
940 yylval = ly_string2scm (str);
946 Lily_lexer::scan_scm_id (SCM sid)
948 if (is_music_function (sid))
950 int funtype = SCM_FUNCTION;
954 SCM s = get_music_function_signature (sid);
955 SCM cs = scm_car (s);
957 if (scm_is_pair (cs))
962 if (scm_is_eq (cs, ly_lily_module_constant ("ly:music?")))
963 funtype = MUSIC_FUNCTION;
964 else if (scm_is_eq (cs, ly_lily_module_constant ("ly:event?")))
965 funtype = EVENT_FUNCTION;
966 else if (ly_is_procedure (cs))
967 funtype = SCM_FUNCTION;
968 else programming_error ("Bad syntax function predicate");
970 push_extra_token (EXPECT_NO_MORE_ARGS);
971 for (s = scm_cdr (s); scm_is_pair (s); s = scm_cdr (s))
973 SCM optional = SCM_UNDEFINED;
976 if (scm_is_pair (cs))
978 optional = SCM_CDR (cs);
982 if (cs == Pitch_type_p_proc)
983 push_extra_token (EXPECT_PITCH);
984 else if (cs == Duration_type_p_proc)
985 push_extra_token (EXPECT_DURATION);
986 else if (ly_is_procedure (cs))
987 push_extra_token (EXPECT_SCM, cs);
990 programming_error ("Function parameter without type-checking predicate");
993 if (!scm_is_eq (optional, SCM_UNDEFINED))
994 push_extra_token (EXPECT_OPTIONAL, optional);
999 return identifier_type (sid);
1003 Lily_lexer::scan_bare_word (string str)
1005 SCM sym = ly_symbol2scm (str.c_str ());
1006 if ((YYSTATE == notes) || (YYSTATE == chords)) {
1007 SCM handle = SCM_BOOL_F;
1008 if (scm_is_pair (pitchname_tab_stack_))
1009 handle = scm_hashq_get_handle (scm_cdar (pitchname_tab_stack_), sym);
1011 if (scm_is_pair (handle)) {
1012 yylval = scm_cdr (handle);
1013 if (unsmob_pitch (yylval))
1014 return (YYSTATE == notes) ? NOTENAME_PITCH : TONICNAME_PITCH;
1015 else if (scm_is_symbol (yylval))
1018 else if ((YYSTATE == chords)
1019 && (handle = scm_hashq_get_handle (chordmodifier_tab_, sym))!= SCM_BOOL_F)
1021 yylval = scm_cdr (handle);
1022 return CHORD_MODIFIER;
1025 yylval = ly_string2scm (str);
1030 Lily_lexer::get_state () const
1032 if (YY_START == extratoken)
1033 return hidden_state_;
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 v = scm_reverse (scm_cdr (sval));
1098 switch (extra_token) {
1100 token = scan_scm_id (scm_car (v));
1101 if (!scm_is_eq (yylval, SCM_UNSPECIFIED))
1102 push_extra_token (token, yylval);
1105 push_extra_token (SCM_IDENTIFIER, scm_car (v));
1109 sval = scm_car (sval);
1111 sval = SCM_UNSPECIFIED;
1117 /* Check for valid UTF-8 that has no overlong or surrogate codes and
1118 is in the range 0-0x10ffff */
1121 Lily_lexer::YYText_utf8 ()
1123 const char * const p = YYText ();
1124 for (int i=0; p[i];) {
1125 if ((p[i] & 0xff) < 0x80) {
1129 int oldi = i; // start of character
1130 int more = 0; // # of followup bytes, 0 if bad
1131 switch (p[i++] & 0xff) {
1132 // 0xc0 and 0xc1 are overlong prefixes for
1133 // 0x00-0x3f and 0x40-0x7f respectively, bad.
1134 case 0xc2: // 0x80-0xbf
1135 case 0xc3: // 0xc0-0xff
1136 case 0xc4: // 0x100-0x13f
1137 case 0xc5: // 0x140-0x17f
1138 case 0xc6: // 0x180-0x1bf
1139 case 0xc7: // 0x1c0-0x1ff
1140 case 0xc8: // 0x200-0x23f
1141 case 0xc9: // 0x240-0x27f
1142 case 0xca: // 0x280-0x2bf
1143 case 0xcb: // 0x2c0-0x2ff
1144 case 0xcc: // 0x300-0x33f
1145 case 0xcd: // 0x340-0x37f
1146 case 0xce: // 0x380-0x3bf
1147 case 0xcf: // 0x3c0-0x3ff
1148 case 0xd0: // 0x400-0x43f
1149 case 0xd1: // 0x440-0x47f
1150 case 0xd2: // 0x480-0x4bf
1151 case 0xd3: // 0x4c0-0x4ff
1152 case 0xd4: // 0x500-0x53f
1153 case 0xd5: // 0x540-0x57f
1154 case 0xd6: // 0x580-0x5bf
1155 case 0xd7: // 0x5c0-0x5ff
1156 case 0xd8: // 0x600-0x63f
1157 case 0xd9: // 0x640-0x67f
1158 case 0xda: // 0x680-0x6bf
1159 case 0xdb: // 0x6c0-0x6ff
1160 case 0xdc: // 0x700-0x73f
1161 case 0xdd: // 0x740-0x77f
1162 case 0xde: // 0x780-0x7bf
1163 case 0xdf: // 0x7c0-0x7ff
1164 more = 1; // 2-byte sequences, 0x80-0x7ff
1167 // don't allow overlong sequences for 0-0x7ff
1168 if ((p[i] & 0xff) < 0xa0)
1170 case 0xe1: // 0x1000-0x1fff
1171 case 0xe2: // 0x2000-0x2fff
1172 case 0xe3: // 0x3000-0x3fff
1173 case 0xe4: // 0x4000-0x4fff
1174 case 0xe5: // 0x5000-0x5fff
1175 case 0xe6: // 0x6000-0x6fff
1176 case 0xe7: // 0x7000-0x7fff
1177 case 0xe8: // 0x8000-0x8fff
1178 case 0xe9: // 0x9000-0x9fff
1179 case 0xea: // 0xa000-0xafff
1180 case 0xeb: // 0xb000-0xbfff
1181 case 0xec: // 0xc000-0xcfff
1182 more = 2; // 3-byte sequences, 0x7ff-0xcfff
1184 case 0xed: // 0xd000-0xdfff
1185 // Don't allow surrogate codes 0xd800-0xdfff
1186 if ((p[i] & 0xff) >= 0xa0)
1188 case 0xee: // 0xe000-0xefff
1189 case 0xef: // 0xf000-0xffff
1190 more = 2; // 3-byte sequences,
1191 // 0xd000-0xd7ff, 0xe000-0xffff
1194 // don't allow overlong sequences for 0-0xffff
1195 if ((p[i] & 0xff) < 0x90)
1197 case 0xf1: // 0x40000-0x7ffff
1198 case 0xf2: // 0x80000-0xbffff
1199 case 0xf3: // 0xc0000-0xfffff
1200 more = 3; // 4-byte sequences, 0x10000-0xfffff
1203 // don't allow more than 0x10ffff
1204 if ((p[i] & 0xff) >= 0x90)
1206 more = 3; // 4-byte sequence, 0x100000-0x10ffff
1210 // check that all continuation bytes are valid
1212 if ((p[i++] & 0xc0) != 0x80)
1218 Input h = here_input ();
1219 h.set (h.get_source_file (), h.start () + oldi, h.start () + i);
1220 h.warning (_ ("non-UTF-8 input").c_str ());
1227 urg, belong to string (_convert)
1228 and should be generalised
1231 strip_leading_white (string&s)
1234 for (; i < s.length (); i++)
1235 if (!isspace (s[i]))
1242 strip_trailing_white (string&s)
1244 ssize i = s.length ();
1246 if (!isspace (s[i]))
1249 s = s.substr (0, i + 1);
1254 Lilypond_version oldest_version ("2.7.38");
1258 is_valid_version (string s)
1260 Lilypond_version current ( MAJOR_VERSION "." MINOR_VERSION "." PATCH_LEVEL );
1261 Lilypond_version ver (s);
1262 if (int (ver) < oldest_version)
1264 non_fatal_error (_f ("file too old: %s (oldest supported: %s)", ver.to_string (), oldest_version.to_string ()));
1265 non_fatal_error (_ ("consider updating the input with the convert-ly script"));
1271 non_fatal_error (_f ("program too old: %s (file requires: %s)", current.to_string (), ver.to_string ()));
1282 lyric_fudge (string s)
1286 while ((i = s.find ('_', i)) != string::npos)
1294 Convert "NUM/DEN" into a '(NUM . DEN) cons.
1297 scan_fraction (string frac)
1299 ssize i = frac.find ('/');
1300 string left = frac.substr (0, i);
1301 string right = frac.substr (i + 1, (frac.length () - i + 1));
1303 int n = String_convert::dec2int (left);
1304 int d = String_convert::dec2int (right);
1305 return scm_cons (scm_from_int (n), scm_from_int (d));
1309 lookup_markup_command (string s)
1311 SCM proc = ly_lily_module_constant ("lookup-markup-command");
1312 return scm_call_1 (proc, ly_string2scm (s));
1316 lookup_markup_list_command (string s)
1318 SCM proc = ly_lily_module_constant ("lookup-markup-list-command");
1319 return scm_call_1 (proc, ly_string2scm (s));
1322 /* Shut up lexer warnings. */
1342 silence_lexer_warnings ()
1344 (void) yy_start_stack_ptr;
1345 (void) yy_start_stack_depth;
1346 (void) yy_start_stack;
1347 (void) yy_push_state;
1348 (void) yy_pop_state;
1349 (void) yy_top_state;
1350 (void) silence_lexer_warnings;