1 %{ // -*- mode: c++; c-file-style: "linux" -*-
3 This file is part of LilyPond, the GNU music typesetter.
5 Copyright (C) 1996--2011 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() \
90 yy_push_state (quote);\
91 yylval.string = new string
93 #define start_lyric_quote() \
94 yy_push_state (lyric_quote);\
95 yylval.string = new string
97 #define yylval (*lexval_)
99 #define yylloc (*lexloc_)
101 #define YY_USER_ACTION add_lexed_char (YYLeng ());
104 SCM scan_fraction (string);
105 SCM (* scm_parse_error_handler) (void *);
115 %option yyclass="Lily_lexer"
117 %option never-interactive
134 /* The strategy concerning multibyte characters is to accept them but
135 * call YYText_utf8 for patterns that might contain them, in order to
136 * get a single code path responsible for flagging non-UTF-8 input:
137 * Patterns for accepting only valid UTF-8 without backing up are
138 * really hard to do and complex, and if nice error messages are
139 * wanted, one would need patterns catching the invalid input as well.
141 * Since editors and operating environments don't necessarily behave
142 * reasonably in the presence of mixed encodings, we flag encoding
143 * errors also in identifiers, comments, and strings where it would be
144 * conceivable to just transparently work with the byte string. But
145 * the whole point of caring about UTF-8 in here at all is too avoid
146 * stranger errors later when input passes into backends or log files
147 * or console output or error messages.
158 NATIONAL [\001-\006\021-\027\031\036]
159 TEX {AA}|-|{PUNCT}|{ACCENT}|{NATIONAL}|{SPECIAL_CHAR}
160 DASHED_WORD {A}({AN}|-)*
161 DASHED_KEY_WORD \\{DASHED_WORD}
170 REAL ({INT}\.{N}*)|(-?\.{N}+)
172 HORIZONTALWHITE [ \t]
176 MARKUPCOMMAND \\({A}|[-_])+
177 LYRICS ({AA}|{TEX})[^0-9 \t\n\r\f]*
181 BOM_UTF8 \357\273\277
187 // swallow and ignore carriage returns
190 <extratoken>{ANY_CHAR} {
191 /* Generate a token without swallowing anything */
193 /* First unswallow the eaten character */
194 add_lexed_char (-YYLeng ());
197 /* produce requested token */
198 int type = scm_to_int (scm_caar (extra_tokens_));
199 yylval.scm = scm_cdar (extra_tokens_);
200 extra_tokens_ = scm_cdr (extra_tokens_);
201 if (scm_is_null (extra_tokens_))
207 <extratoken><<EOF>> {
208 /* Generate a token without swallowing anything */
210 /* produce requested token */
211 int type = scm_to_int (scm_caar (extra_tokens_));
212 yylval.scm = scm_cdar (extra_tokens_);
213 extra_tokens_ = scm_cdr (extra_tokens_);
214 if (scm_is_null (extra_tokens_))
220 /* Use the trailing context feature. Otherwise, the BOM will not be
221 found if the file starts with an identifier definition. */
222 <INITIAL,chords,lyrics,figures,notes>{BOM_UTF8}/.* {
223 if (this->lexloc_->line_number () != 1 || this->lexloc_->column_number () != 0)
225 LexerWarning (_ ("stray UTF-8 BOM encountered").c_str ());
228 debug_output (_ ("Skipping UTF-8 BOM"));
231 <INITIAL,chords,figures,incl,lyrics,markup,notes>{
233 yy_push_state (longcomment);
235 %[^{\n\r][^\n\r]*[\n\r] {
236 (void) YYText_utf8 ();
238 %[^{\n\r] { // backup rule
239 (void) YYText_utf8 ();
244 (void) YYText_utf8 ();
251 <INITIAL,notes,figures,chords,markup>{
257 <INITIAL,chords,lyrics,notes,figures>\\version{WHITE}* {
258 yy_push_state (version);
260 <INITIAL,chords,lyrics,notes,figures>\\sourcefilename{WHITE}* {
261 yy_push_state (sourcefilename);
263 <INITIAL,chords,lyrics,notes,figures>\\sourcefileline{WHITE}* {
264 yy_push_state (sourcefileline);
266 <version>\"[^"]*\" { /* got the version number */
267 string s (YYText_utf8 () + 1);
268 s = s.substr (0, s.rfind ('\"'));
272 SCM top_scope = scm_car (scm_last_pair (scopes_));
273 scm_module_define (top_scope, ly_symbol2scm ("version-seen"), SCM_BOOL_T);
275 if (!is_valid_version (s))
280 <sourcefilename>\"[^"]*\" {
281 string s (YYText_utf8 () + 1);
282 s = s.substr (0, s.rfind ('\"'));
285 this->here_input().get_source_file ()->name_ = s;
286 message (_f ("Renaming input to: `%s'", s.c_str ()));
287 progress_indication ("\n");
288 scm_module_define (scm_car (scopes_),
289 ly_symbol2scm ("input-file-name"),
294 <sourcefileline>{INT} {
296 sscanf (YYText (), "%d", &i);
299 this->here_input ().get_source_file ()->set_line (here_input ().start (), i);
302 <version>{ANY_CHAR} {
303 LexerError (_ ("quoted string expected after \\version").c_str ());
306 <sourcefilename>{ANY_CHAR} {
307 LexerError (_ ("quoted string expected after \\sourcefilename").c_str ());
310 <sourcefileline>{ANY_CHAR} {
311 LexerError (_ ("integer expected after \\sourcefileline").c_str ());
316 (void) YYText_utf8 ();
319 (void) YYText_utf8 ();
327 <INITIAL,chords,lyrics,notes,figures>\\maininput {
331 is_main_input_ = true;
334 error (_ ("\\maininput not allowed outside init files"));
337 <INITIAL,chords,lyrics,figures,notes>\\include {
338 yy_push_state (incl);
340 <incl>\"[^""]*\" { /* got the include file name */
341 string s (YYText_utf8 ()+1);
342 s = s.substr (0, s.rfind ('"'));
344 new_input (s, sources_);
347 <incl>\\{BLACK}*{WHITE}? { /* got the include identifier */
348 string s = YYText_utf8 () + 1;
349 strip_trailing_white (s);
350 if (s.length () && (s[s.length () - 1] == ';'))
351 s = s.substr (0, s.length () - 1);
353 SCM sid = lookup_identifier (s);
354 if (scm_is_string (sid)) {
355 new_input (ly_scm2string (sid), sources_);
358 string msg (_f ("wrong or undefined identifier: `%s'", s ));
360 LexerError (msg.c_str ());
361 SCM err = scm_current_error_port ();
362 scm_puts ("This value was found in the table: ", err);
363 scm_display (sid, err);
366 <incl>(\$|#) { // scm for the filename
368 Input hi = here_input();
370 SCM sval = ly_parse_scm (hi.start (), &n, hi,
371 be_safe_global && is_main_input_, parser_);
372 sval = eval_scm (sval);
374 for (int i = 0; i < n; i++)
378 char_count_stack_.back () += n;
380 if (scm_is_string (sval)) {
381 new_input (ly_scm2string (sval), sources_);
384 LexerError (_ ("string expected after \\include").c_str ());
385 if (sval != SCM_UNDEFINED) {
386 SCM err = scm_current_error_port ();
387 scm_puts ("This value was found instead: ", err);
388 scm_display (sval, err);
393 <incl,version,sourcefilename>\"[^""]* { // backup rule
394 error (_ ("end quote missing"));
397 <chords,notes,figures>{RESTNAME} {
398 char const *s = YYText ();
399 yylval.scm = scm_from_locale_string (s);
402 <chords,notes,figures>R {
403 return MULTI_MEASURE_REST;
405 <INITIAL,chords,figures,lyrics,markup,notes># { //embedded scm
407 Input hi = here_input();
409 SCM sval = ly_parse_scm (hi.start (), &n, hi,
410 be_safe_global && is_main_input_, parser_);
412 if (sval == SCM_UNDEFINED)
415 for (int i = 0; i < n; i++)
419 char_count_stack_.back () += n;
425 <INITIAL,chords,figures,lyrics,markup,notes>\$ { //immediate scm
427 Input hi = here_input();
429 SCM sval = ly_parse_scm (hi.start (), &n, hi,
430 be_safe_global && is_main_input_, parser_);
432 for (int i = 0; i < n; i++)
436 char_count_stack_.back () += n;
438 sval = eval_scm (sval);
440 int token = scan_scm_id (sval);
441 if (!scm_is_eq (yylval.scm, SCM_UNSPECIFIED))
445 <INITIAL,notes,lyrics>{
447 return DOUBLE_ANGLE_OPEN;
450 return DOUBLE_ANGLE_CLOSE;
477 return scan_bare_word (YYText_utf8 ());
481 return scan_escaped_word (YYText_utf8 () + 1);
484 yylval.scm = scan_fraction (YYText ());
487 {UNSIGNED}/\/ | // backup rule
489 yylval.scm = scm_c_read_string (YYText ());
493 yylval.i = String_convert::dec2int (string (YYText () +1));
500 *yylval.string += to_string (escaped_char (YYText ()[1]));
503 *yylval.string += YYText_utf8 ();
509 /* yylval is union. Must remember STRING before setting SCM*/
510 string *sp = yylval.string;
511 yylval.scm = ly_string2scm (*sp);
513 return is_lyric_state () ? LYRICS_STRING : STRING;
516 *yylval.string += YYText ();
522 start_lyric_quote ();
525 yylval.scm = scan_fraction (YYText ());
528 {UNSIGNED}/\/[^0-9] { // backup rule
529 yylval.scm = scm_c_read_string (YYText ());
532 {UNSIGNED}/\/ | // backup rule
534 yylval.scm = scm_c_read_string (YYText ());
538 return scan_escaped_word (YYText_utf8 () + 1);
542 string s (YYText_utf8 ());
544 return yylval.i = EXTENDER;
546 return yylval.i = HYPHEN;
549 char c = s[s.length () - 1];
550 if (c == '{' || c == '}') // brace open is for not confusing dumb tools.
551 here_input ().warning (
552 _ ("Brace found at end of lyric. Did you forget a space?"));
553 yylval.scm = ly_string2scm (s);
556 return LYRICS_STRING;
559 return YYText ()[0]; // LYRICS already catches all multibytes.
564 return scan_bare_word (YYText_utf8 ());
567 return scan_escaped_word (YYText_utf8 () + 1);
570 yylval.scm = scan_fraction (YYText ());
573 {UNSIGNED}/\/[^0-9] { // backup rule
574 yylval.scm = scm_c_read_string (YYText ());
577 {UNSIGNED}/\/ | // backup rule
579 yylval.scm = scm_c_read_string (YYText ());
598 return YYText ()[0]; // ALPHAWORD catches all multibyte.
608 string str (YYText_utf8 () + 1);
610 int token_type = MARKUP_FUNCTION;
611 SCM s = lookup_markup_command (str);
613 // lookup-markup-command returns a pair with the car
614 // being the function to call, and the cdr being the
615 // call signature specified to define-markup-command,
616 // a list of predicates.
618 if (!scm_is_pair (s)) {
619 // If lookup-markup-command was not successful, we
620 // try lookup-markup-list-command instead.
621 // If this fails as well, we just scan and return
623 s = lookup_markup_list_command (str);
625 token_type = MARKUP_LIST_FUNCTION;
627 return scan_escaped_word (str);
630 // If the list of predicates is, say,
631 // (number? number? markup?), then tokens
632 // EXPECT_MARKUP EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
633 // will be generated. Note that we have to push them
634 // in reverse order, so the first token pushed in the
635 // loop will be EXPECT_NO_MORE_ARGS.
637 yylval.scm = scm_car(s);
639 // yylval now contains the function to call as token
640 // value (for token type MARKUP_FUNCTION or
641 // MARKUP_LIST_FUNCTION).
643 push_extra_token(EXPECT_NO_MORE_ARGS);
645 for (; scm_is_pair(s); s = scm_cdr(s)) {
646 SCM predicate = scm_car(s);
648 if (predicate == ly_lily_module_constant ("markup-list?"))
649 push_extra_token(EXPECT_MARKUP_LIST);
650 else if (predicate == ly_lily_module_constant ("markup?"))
651 push_extra_token(EXPECT_MARKUP);
653 push_extra_token(EXPECT_SCM, predicate);
660 [^$#{}\"\\ \t\n\r\f]+ {
661 string s (YYText_utf8 ());
663 char c = s[s.length () - 1];
664 /* brace open is for not confusing dumb tools. */
665 if (c == '{' || c == '}')
666 here_input ().warning (
667 _ ("Brace found at end of markup. Did you forget a space?"));
668 yylval.scm = ly_string2scm (s);
674 return YYText()[0]; // Above is catchall for multibyte
678 <longcomment><<EOF>> {
679 LexerError (_ ("EOF found inside a comment").c_str ());
680 is_main_input_ = false; // should be safe , can't have \include in --safe.
682 yyterminate (); // can't move this, since it actually rets a YY_NULL
685 <<EOF>> { if (is_main_input_)
687 /* 2 = init.ly + current file.
688 > because we're before closing, but is_main_input_ should
691 is_main_input_ = include_stack_.size () > 2;
693 /* Returns YY_NULL */
696 else if (!close_input ())
697 /* Returns YY_NULL */
703 return scan_bare_word (YYText_utf8 ());
706 return scan_escaped_word (YYText_utf8 () + 1);
710 -{UNSIGNED} | // backup rule
712 yylval.scm = scm_c_read_string (YYText ());
716 yylval.scm = scm_from_double (0.0);
721 yylval.scm = scm_c_read_string (YYText ());
731 char c = YYText ()[0];
736 <INITIAL,notes,figures>. {
740 <INITIAL,lyrics,notes,figures>\\. {
741 char c = YYText ()[1];
745 return E_ANGLE_CLOSE;
749 return E_EXCLAMATION;
755 return E_BRACKET_OPEN;
759 return E_BRACKET_CLOSE;
771 string msg = _f ("invalid character: `%s'", YYText_utf8 ());
772 LexerError (msg.c_str ());
773 return '%'; // Better not return half a utf8 character.
778 /* Make the lexer generate a token of the given type as the next token.
779 TODO: make it possible to define a value for the token as well */
781 Lily_lexer::push_extra_token (int token_type, SCM scm)
783 if (scm_is_null (extra_tokens_))
785 if (YY_START != extratoken)
786 hidden_state_ = YY_START;
787 yy_push_state (extratoken);
789 extra_tokens_ = scm_acons (scm_from_int (token_type), scm, extra_tokens_);
793 Lily_lexer::push_chord_state (SCM tab)
795 pitchname_tab_stack_ = scm_cons (tab, pitchname_tab_stack_);
796 yy_push_state (chords);
800 Lily_lexer::push_figuredbass_state ()
802 yy_push_state (figures);
806 Lily_lexer::push_initial_state ()
808 yy_push_state (INITIAL);
812 Lily_lexer::push_lyric_state ()
814 yy_push_state (lyrics);
818 Lily_lexer::push_markup_state ()
820 yy_push_state (markup);
824 Lily_lexer::push_note_state (SCM tab)
826 pitchname_tab_stack_ = scm_cons (tab, pitchname_tab_stack_);
827 yy_push_state (notes);
831 Lily_lexer::pop_state ()
833 if (YYSTATE == notes || YYSTATE == chords)
834 pitchname_tab_stack_ = scm_cdr (pitchname_tab_stack_);
840 Lily_lexer::identifier_type (SCM sid)
842 int k = try_special_identifiers (&yylval.scm , sid);
843 return k >= 0 ? k : SCM_IDENTIFIER;
848 Lily_lexer::scan_escaped_word (string str)
850 // use more SCM for this.
852 // SCM sym = ly_symbol2scm (str.c_str ());
854 int i = lookup_keyword (str);
855 if (i == MARKUP && is_lyric_state ())
860 SCM sid = lookup_identifier (str);
861 if (sid != SCM_UNDEFINED)
862 return scan_scm_id (sid);
864 string msg (_f ("unknown escaped string: `\\%s'", str));
865 LexerError (msg.c_str ());
867 yylval.scm = ly_string2scm (str);
873 Lily_lexer::scan_scm_id (SCM sid)
875 if (is_music_function (sid))
877 int funtype = SCM_FUNCTION;
879 yylval.scm = get_music_function_transform (sid);
881 SCM s = scm_object_property (yylval.scm, ly_symbol2scm ("music-function-signature"));
882 SCM cs = scm_car (s);
884 if (scm_is_pair (cs))
889 if (scm_is_eq (cs, ly_lily_module_constant ("ly:music?")))
890 funtype = MUSIC_FUNCTION;
891 else if (scm_is_eq (cs, ly_lily_module_constant ("ly:event?")))
892 funtype = EVENT_FUNCTION;
893 else if (ly_is_procedure (cs))
894 funtype = SCM_FUNCTION;
895 else programming_error ("Bad syntax function predicate");
897 push_extra_token (EXPECT_NO_MORE_ARGS);
898 for (s = scm_cdr (s); scm_is_pair (s); s = scm_cdr (s))
900 SCM optional = SCM_UNDEFINED;
903 if (scm_is_pair (cs))
905 optional = SCM_CDR (cs);
909 if (cs == Pitch_type_p_proc)
910 push_extra_token (EXPECT_PITCH);
911 else if (cs == Duration_type_p_proc)
912 push_extra_token (EXPECT_DURATION);
913 else if (ly_is_procedure (cs))
914 push_extra_token (EXPECT_SCM, cs);
917 programming_error ("Function parameter without type-checking predicate");
920 if (!scm_is_eq (optional, SCM_UNDEFINED))
921 push_extra_token (EXPECT_OPTIONAL, optional);
926 return identifier_type (sid);
930 Lily_lexer::scan_bare_word (string str)
932 SCM sym = ly_symbol2scm (str.c_str ());
933 if ((YYSTATE == notes) || (YYSTATE == chords)) {
934 SCM handle = SCM_BOOL_F;
935 if (scm_is_pair (pitchname_tab_stack_))
936 handle = scm_hashq_get_handle (scm_car (pitchname_tab_stack_), sym);
938 if (scm_is_pair (handle)) {
939 yylval.scm = scm_cdr (handle);
940 if (unsmob_pitch (yylval.scm))
941 return (YYSTATE == notes) ? NOTENAME_PITCH : TONICNAME_PITCH;
942 else if (scm_is_symbol (yylval.scm))
945 else if ((YYSTATE == chords)
946 && (handle = scm_hashq_get_handle (chordmodifier_tab_, sym))!= SCM_BOOL_F)
948 yylval.scm = scm_cdr (handle);
949 return CHORD_MODIFIER;
951 if ((chord_repetition_.repetition_symbol_ != SCM_EOL)
952 && to_boolean (scm_equal_p (chord_repetition_.repetition_symbol_, sym)))
953 return CHORD_REPETITION;
956 yylval.scm = ly_string2scm (str);
961 Lily_lexer::get_state () const
963 if (YY_START == extratoken)
964 return hidden_state_;
970 Lily_lexer::is_note_state () const
972 return get_state () == notes;
976 Lily_lexer::is_chord_state () const
978 return get_state () == chords;
982 Lily_lexer::is_lyric_state () const
984 return get_state () == lyrics;
988 Lily_lexer::is_figure_state () const
990 return get_state () == figures;
994 Lily_lexer::eval_scm (SCM readerdata)
996 SCM sval = SCM_UNDEFINED;
998 if (!SCM_UNBNDP (readerdata))
1000 sval = ly_eval_scm (scm_car (readerdata),
1001 *unsmob_input (scm_cdr (readerdata)),
1002 be_safe_global && is_main_input_,
1006 if (SCM_UNBNDP (sval))
1009 return SCM_UNSPECIFIED;
1014 /* Check for valid UTF-8 that has no overlong or surrogate codes and
1015 is in the range 0-0x10ffff */
1018 Lily_lexer::YYText_utf8 ()
1020 const char * const p = YYText ();
1021 for (int i=0; p[i];) {
1022 if ((p[i] & 0xff) < 0x80) {
1026 int oldi = i; // start of character
1027 int more = 0; // # of followup bytes, 0 if bad
1028 switch (p[i++] & 0xff) {
1029 // 0xc0 and 0xc1 are overlong prefixes for
1030 // 0x00-0x3f and 0x40-0x7f respectively, bad.
1031 case 0xc2: // 0x80-0xbf
1032 case 0xc3: // 0xc0-0xff
1033 case 0xc4: // 0x100-0x13f
1034 case 0xc5: // 0x140-0x17f
1035 case 0xc6: // 0x180-0x1bf
1036 case 0xc7: // 0x1c0-0x1ff
1037 case 0xc8: // 0x200-0x23f
1038 case 0xc9: // 0x240-0x27f
1039 case 0xca: // 0x280-0x2bf
1040 case 0xcb: // 0x2c0-0x2ff
1041 case 0xcc: // 0x300-0x33f
1042 case 0xcd: // 0x340-0x37f
1043 case 0xce: // 0x380-0x3bf
1044 case 0xcf: // 0x3c0-0x3ff
1045 case 0xd0: // 0x400-0x43f
1046 case 0xd1: // 0x440-0x47f
1047 case 0xd2: // 0x480-0x4bf
1048 case 0xd3: // 0x4c0-0x4ff
1049 case 0xd4: // 0x500-0x53f
1050 case 0xd5: // 0x540-0x57f
1051 case 0xd6: // 0x580-0x5bf
1052 case 0xd7: // 0x5c0-0x5ff
1053 case 0xd8: // 0x600-0x63f
1054 case 0xd9: // 0x640-0x67f
1055 case 0xda: // 0x680-0x6bf
1056 case 0xdb: // 0x6c0-0x6ff
1057 case 0xdc: // 0x700-0x73f
1058 case 0xdd: // 0x740-0x77f
1059 case 0xde: // 0x780-0x7bf
1060 case 0xdf: // 0x7c0-0x7ff
1061 more = 1; // 2-byte sequences, 0x80-0x7ff
1064 // don't allow overlong sequences for 0-0x7ff
1065 if ((p[i] & 0xff) < 0xa0)
1067 case 0xe1: // 0x1000-0x1fff
1068 case 0xe2: // 0x2000-0x2fff
1069 case 0xe3: // 0x3000-0x3fff
1070 case 0xe4: // 0x4000-0x4fff
1071 case 0xe5: // 0x5000-0x5fff
1072 case 0xe6: // 0x6000-0x6fff
1073 case 0xe7: // 0x7000-0x7fff
1074 case 0xe8: // 0x8000-0x8fff
1075 case 0xe9: // 0x9000-0x9fff
1076 case 0xea: // 0xa000-0xafff
1077 case 0xeb: // 0xb000-0xbfff
1078 case 0xec: // 0xc000-0xcfff
1079 more = 2; // 3-byte sequences, 0x7ff-0xcfff
1081 case 0xed: // 0xd000-0xdfff
1082 // Don't allow surrogate codes 0xd800-0xdfff
1083 if ((p[i] & 0xff) >= 0xa0)
1085 case 0xee: // 0xe000-0xefff
1086 case 0xef: // 0xf000-0xffff
1087 more = 2; // 3-byte sequences,
1088 // 0xd000-0xd7ff, 0xe000-0xffff
1091 // don't allow overlong sequences for 0-0xffff
1092 if ((p[i] & 0xff) < 0x90)
1094 case 0xf1: // 0x40000-0x7ffff
1095 case 0xf2: // 0x80000-0xbffff
1096 case 0xf3: // 0xc0000-0xfffff
1097 more = 3; // 4-byte sequences, 0x10000-0xfffff
1100 // don't allow more than 0x10ffff
1101 if ((p[i] & 0xff) >= 0x90)
1103 more = 3; // 4-byte sequence, 0x100000-0x10ffff
1107 // check that all continuation bytes are valid
1109 if ((p[i++] & 0xc0) != 0x80)
1115 Input h = here_input ();
1116 h.set (h.get_source_file (), h.start () + oldi, h.start () + i);
1117 h.warning (_ ("non-UTF-8 input").c_str ());
1124 urg, belong to string (_convert)
1125 and should be generalised
1128 strip_leading_white (string&s)
1131 for (; i < s.length (); i++)
1132 if (!isspace (s[i]))
1139 strip_trailing_white (string&s)
1141 ssize i = s.length ();
1143 if (!isspace (s[i]))
1146 s = s.substr (0, i + 1);
1151 Lilypond_version oldest_version ("2.7.38");
1155 is_valid_version (string s)
1157 Lilypond_version current ( MAJOR_VERSION "." MINOR_VERSION "." PATCH_LEVEL );
1158 Lilypond_version ver (s);
1159 if (int (ver) < oldest_version)
1161 non_fatal_error (_f ("file too old: %s (oldest supported: %s)", ver.to_string (), oldest_version.to_string ()));
1162 non_fatal_error (_ ("consider updating the input with the convert-ly script"));
1168 non_fatal_error (_f ("program too old: %s (file requires: %s)", current.to_string (), ver.to_string ()));
1179 lyric_fudge (string s)
1183 while ((i = s.find ('_', i)) != string::npos)
1191 Convert "NUM/DEN" into a '(NUM . DEN) cons.
1194 scan_fraction (string frac)
1196 ssize i = frac.find ('/');
1197 string left = frac.substr (0, i);
1198 string right = frac.substr (i + 1, (frac.length () - i + 1));
1200 int n = String_convert::dec2int (left);
1201 int d = String_convert::dec2int (right);
1202 return scm_cons (scm_from_int (n), scm_from_int (d));
1206 lookup_markup_command (string s)
1208 SCM proc = ly_lily_module_constant ("lookup-markup-command");
1209 return scm_call_1 (proc, ly_string2scm (s));
1213 lookup_markup_list_command (string s)
1215 SCM proc = ly_lily_module_constant ("lookup-markup-list-command");
1216 return scm_call_1 (proc, ly_string2scm (s));
1219 /* Shut up lexer warnings. */
1239 silence_lexer_warnings ()
1241 (void) yy_start_stack_ptr;
1242 (void) yy_start_stack_depth;
1243 (void) yy_start_stack;
1244 (void) yy_push_state;
1245 (void) yy_pop_state;
1246 (void) yy_top_state;
1247 (void) silence_lexer_warnings;