1 %{ // -*- mode: c++; c-file-style: "linux" -*-
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() \
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.
157 NATIONAL [\001-\006\021-\027\031\036]
158 TEX {AA}|-|{PUNCT}|{NATIONAL}|{SPECIAL_CHAR}
159 DASHED_WORD {A}({AN}|-)*
160 DASHED_KEY_WORD \\{DASHED_WORD}
169 REAL ({INT}\.{N}*)|(-?\.{N}+)
171 HORIZONTALWHITE [ \t]
175 MARKUPCOMMAND \\({A}|[-_])+
176 LYRICS ({AA}|{TEX})[^0-9 \t\n\r\f]*
180 BOM_UTF8 \357\273\277
186 // swallow and ignore carriage returns
189 <extratoken>{ANY_CHAR} {
190 /* Generate a token without swallowing anything */
192 /* First unswallow the eaten character */
193 add_lexed_char (-YYLeng ());
196 /* produce requested token */
197 int type = scm_to_int (scm_caar (extra_tokens_));
198 yylval.scm = scm_cdar (extra_tokens_);
199 extra_tokens_ = scm_cdr (extra_tokens_);
200 if (scm_is_null (extra_tokens_))
206 <extratoken><<EOF>> {
207 /* Generate a token without swallowing anything */
209 /* produce requested token */
210 int type = scm_to_int (scm_caar (extra_tokens_));
211 yylval.scm = scm_cdar (extra_tokens_);
212 extra_tokens_ = scm_cdr (extra_tokens_);
213 if (scm_is_null (extra_tokens_))
219 /* Use the trailing context feature. Otherwise, the BOM will not be
220 found if the file starts with an identifier definition. */
221 <INITIAL,chords,lyrics,figures,notes>{BOM_UTF8}/.* {
222 if (this->lexloc_->line_number () != 1 || this->lexloc_->column_number () != 0)
224 LexerWarning (_ ("stray UTF-8 BOM encountered").c_str ());
227 debug_output (_ ("Skipping UTF-8 BOM"));
230 <INITIAL,chords,figures,incl,lyrics,markup,notes>{
232 yy_push_state (longcomment);
234 %[^{\n\r][^\n\r]*[\n\r] {
235 (void) YYText_utf8 ();
237 %[^{\n\r] { // backup rule
238 (void) YYText_utf8 ();
243 (void) YYText_utf8 ();
250 <INITIAL,notes,figures,chords,markup>{
256 <INITIAL,chords,lyrics,notes,figures>\\version{WHITE}* {
257 yy_push_state (version);
259 <INITIAL,chords,lyrics,notes,figures>\\sourcefilename{WHITE}* {
260 yy_push_state (sourcefilename);
262 <INITIAL,chords,lyrics,notes,figures>\\sourcefileline{WHITE}* {
263 yy_push_state (sourcefileline);
265 <version>\"[^"]*\" { /* got the version number */
266 string s (YYText_utf8 () + 1);
267 s = s.substr (0, s.rfind ('\"'));
271 SCM top_scope = scm_car (scm_last_pair (scopes_));
272 scm_module_define (top_scope, ly_symbol2scm ("version-seen"), SCM_BOOL_T);
274 if (!is_valid_version (s))
279 <sourcefilename>\"[^"]*\" {
280 string s (YYText_utf8 () + 1);
281 s = s.substr (0, s.rfind ('\"'));
284 this->here_input().get_source_file ()->name_ = s;
285 message (_f ("Renaming input to: `%s'", s.c_str ()));
286 progress_indication ("\n");
287 scm_module_define (scm_car (scopes_),
288 ly_symbol2scm ("input-file-name"),
293 <sourcefileline>{INT} {
295 sscanf (YYText (), "%d", &i);
298 this->here_input ().get_source_file ()->set_line (here_input ().start (), i);
301 <version>{ANY_CHAR} {
302 LexerError (_ ("quoted string expected after \\version").c_str ());
305 <sourcefilename>{ANY_CHAR} {
306 LexerError (_ ("quoted string expected after \\sourcefilename").c_str ());
309 <sourcefileline>{ANY_CHAR} {
310 LexerError (_ ("integer expected after \\sourcefileline").c_str ());
315 (void) YYText_utf8 ();
318 (void) YYText_utf8 ();
326 <INITIAL,chords,lyrics,notes,figures>\\maininput {
330 is_main_input_ = true;
333 error (_ ("\\maininput not allowed outside init files"));
336 <INITIAL,chords,lyrics,figures,notes>\\include {
337 yy_push_state (incl);
339 <incl>\"[^""]*\" { /* got the include file name */
340 string s (YYText_utf8 ()+1);
341 s = s.substr (0, s.rfind ('"'));
343 new_input (s, sources_);
346 <incl>\\{BLACK}*{WHITE}? { /* got the include identifier */
347 string s = YYText_utf8 () + 1;
348 strip_trailing_white (s);
349 if (s.length () && (s[s.length () - 1] == ';'))
350 s = s.substr (0, s.length () - 1);
352 SCM sid = lookup_identifier (s);
353 if (scm_is_string (sid)) {
354 new_input (ly_scm2string (sid), sources_);
357 string msg (_f ("wrong or undefined identifier: `%s'", s ));
359 LexerError (msg.c_str ());
360 SCM err = scm_current_error_port ();
361 scm_puts ("This value was found in the table: ", err);
362 scm_display (sid, err);
365 <incl>(\$|#) { // scm for the filename
367 Input hi = here_input();
369 SCM sval = ly_parse_scm (hi.start (), &n, hi,
370 be_safe_global && is_main_input_, parser_);
371 sval = eval_scm (sval);
373 for (int i = 0; i < n; i++)
377 char_count_stack_.back () += n;
379 if (scm_is_string (sval)) {
380 new_input (ly_scm2string (sval), sources_);
383 LexerError (_ ("string expected after \\include").c_str ());
384 if (sval != SCM_UNDEFINED) {
385 SCM err = scm_current_error_port ();
386 scm_puts ("This value was found instead: ", err);
387 scm_display (sval, err);
392 <incl,version,sourcefilename>\"[^""]* { // backup rule
393 error (_ ("end quote missing"));
396 <chords,notes,figures>{RESTNAME} {
397 char const *s = YYText ();
398 yylval.scm = scm_from_locale_string (s);
401 <chords,notes,figures>q {
402 return CHORD_REPETITION;
405 <chords,notes,figures>R {
406 return MULTI_MEASURE_REST;
408 <INITIAL,chords,figures,lyrics,markup,notes># { //embedded scm
410 Input hi = here_input();
412 SCM sval = ly_parse_scm (hi.start (), &n, hi,
413 be_safe_global && is_main_input_, parser_);
415 if (sval == SCM_UNDEFINED)
418 for (int i = 0; i < n; i++)
422 char_count_stack_.back () += n;
428 <INITIAL,chords,figures,lyrics,markup,notes>\$ { //immediate scm
430 Input hi = here_input();
432 SCM sval = ly_parse_scm (hi.start (), &n, hi,
433 be_safe_global && is_main_input_, parser_);
435 for (int i = 0; i < n; i++)
439 char_count_stack_.back () += n;
441 sval = eval_scm (sval);
443 int token = scan_scm_id (sval);
444 if (!scm_is_eq (yylval.scm, SCM_UNSPECIFIED))
448 <INITIAL,notes,lyrics>{
450 return DOUBLE_ANGLE_OPEN;
453 return DOUBLE_ANGLE_CLOSE;
480 return scan_bare_word (YYText_utf8 ());
484 return scan_escaped_word (YYText_utf8 () + 1);
487 yylval.scm = scan_fraction (YYText ());
490 {UNSIGNED}/\/ | // backup rule
492 yylval.scm = scm_c_read_string (YYText ());
496 yylval.i = String_convert::dec2int (string (YYText () +1));
503 *yylval.string += to_string (escaped_char (YYText ()[1]));
506 *yylval.string += YYText_utf8 ();
512 /* yylval is union. Must remember STRING before setting SCM*/
513 string *sp = yylval.string;
514 yylval.scm = ly_string2scm (*sp);
516 return is_lyric_state () ? LYRICS_STRING : STRING;
519 *yylval.string += YYText ();
525 start_lyric_quote ();
528 yylval.scm = scan_fraction (YYText ());
531 {UNSIGNED}/\/[^0-9] { // backup rule
532 yylval.scm = scm_c_read_string (YYText ());
535 {UNSIGNED}/\/ | // backup rule
537 yylval.scm = scm_c_read_string (YYText ());
541 return scan_escaped_word (YYText_utf8 () + 1);
545 string s (YYText_utf8 ());
547 return yylval.i = EXTENDER;
549 return yylval.i = HYPHEN;
552 char c = s[s.length () - 1];
553 if (c == '{' || c == '}') // brace open is for not confusing dumb tools.
554 here_input ().warning (
555 _ ("Brace found at end of lyric. Did you forget a space?"));
556 yylval.scm = ly_string2scm (s);
559 return LYRICS_STRING;
562 return YYText ()[0]; // LYRICS already catches all multibytes.
567 return scan_bare_word (YYText_utf8 ());
570 return scan_escaped_word (YYText_utf8 () + 1);
573 yylval.scm = scan_fraction (YYText ());
576 {UNSIGNED}/\/[^0-9] { // backup rule
577 yylval.scm = scm_c_read_string (YYText ());
580 {UNSIGNED}/\/ | // backup rule
582 yylval.scm = scm_c_read_string (YYText ());
601 return YYText ()[0]; // ALPHAWORD catches all multibyte.
611 string str (YYText_utf8 () + 1);
613 int token_type = MARKUP_FUNCTION;
614 SCM s = lookup_markup_command (str);
616 // lookup-markup-command returns a pair with the car
617 // being the function to call, and the cdr being the
618 // call signature specified to define-markup-command,
619 // a list of predicates.
621 if (!scm_is_pair (s)) {
622 // If lookup-markup-command was not successful, we
623 // try lookup-markup-list-command instead.
624 // If this fails as well, we just scan and return
626 s = lookup_markup_list_command (str);
628 token_type = MARKUP_LIST_FUNCTION;
630 return scan_escaped_word (str);
633 // If the list of predicates is, say,
634 // (number? number? markup?), then tokens
635 // EXPECT_MARKUP EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
636 // will be generated. Note that we have to push them
637 // in reverse order, so the first token pushed in the
638 // loop will be EXPECT_NO_MORE_ARGS.
640 yylval.scm = scm_car(s);
642 // yylval now contains the function to call as token
643 // value (for token type MARKUP_FUNCTION or
644 // MARKUP_LIST_FUNCTION).
646 push_extra_token(EXPECT_NO_MORE_ARGS);
648 for (; scm_is_pair(s); s = scm_cdr(s)) {
649 SCM predicate = scm_car(s);
651 if (predicate == ly_lily_module_constant ("markup-list?"))
652 push_extra_token(EXPECT_MARKUP_LIST);
653 else if (predicate == ly_lily_module_constant ("markup?"))
654 push_extra_token(EXPECT_MARKUP);
656 push_extra_token(EXPECT_SCM, predicate);
663 [^$#{}\"\\ \t\n\r\f]+ {
664 string s (YYText_utf8 ());
666 char c = s[s.length () - 1];
667 /* brace open is for not confusing dumb tools. */
668 if (c == '{' || c == '}')
669 here_input ().warning (
670 _ ("Brace found at end of markup. Did you forget a space?"));
671 yylval.scm = ly_string2scm (s);
677 return YYText()[0]; // Above is catchall for multibyte
681 <longcomment><<EOF>> {
682 LexerError (_ ("EOF found inside a comment").c_str ());
683 is_main_input_ = false; // should be safe , can't have \include in --safe.
685 yyterminate (); // can't move this, since it actually rets a YY_NULL
688 <<EOF>> { if (is_main_input_)
690 /* 2 = init.ly + current file.
691 > because we're before closing, but is_main_input_ should
694 is_main_input_ = include_stack_.size () > 2;
696 /* Returns YY_NULL */
699 else if (!close_input ())
700 /* Returns YY_NULL */
706 return scan_bare_word (YYText_utf8 ());
709 return scan_escaped_word (YYText_utf8 () + 1);
714 yylval.scm = scan_fraction (YYText ());
718 -{UNSIGNED} | // backup rule
720 yylval.scm = scm_c_read_string (YYText ());
724 yylval.scm = scm_from_double (0.0);
728 {UNSIGNED}/\/ | // backup rule
730 yylval.scm = scm_c_read_string (YYText ());
740 char c = YYText ()[0];
745 <INITIAL,notes,figures>. {
749 <INITIAL,lyrics,notes,figures>\\. {
750 char c = YYText ()[1];
754 return E_ANGLE_CLOSE;
758 return E_EXCLAMATION;
764 return E_BRACKET_OPEN;
768 return E_BRACKET_CLOSE;
780 string msg = _f ("invalid character: `%s'", YYText_utf8 ());
781 LexerError (msg.c_str ());
782 return '%'; // Better not return half a utf8 character.
787 /* Make the lexer generate a token of the given type as the next token.
788 TODO: make it possible to define a value for the token as well */
790 Lily_lexer::push_extra_token (int token_type, SCM scm)
792 if (scm_is_null (extra_tokens_))
794 if (YY_START != extratoken)
795 hidden_state_ = YY_START;
796 yy_push_state (extratoken);
798 extra_tokens_ = scm_acons (scm_from_int (token_type), scm, extra_tokens_);
802 Lily_lexer::push_chord_state (SCM tab)
804 pitchname_tab_stack_ = scm_cons (tab, pitchname_tab_stack_);
805 yy_push_state (chords);
809 Lily_lexer::push_figuredbass_state ()
811 yy_push_state (figures);
815 Lily_lexer::push_initial_state ()
817 yy_push_state (INITIAL);
821 Lily_lexer::push_lyric_state ()
823 yy_push_state (lyrics);
827 Lily_lexer::push_markup_state ()
829 yy_push_state (markup);
833 Lily_lexer::push_note_state (SCM tab)
835 pitchname_tab_stack_ = scm_cons (tab, pitchname_tab_stack_);
836 yy_push_state (notes);
840 Lily_lexer::pop_state ()
842 bool extra = (YYSTATE == extratoken);
847 if (YYSTATE == notes || YYSTATE == chords)
848 pitchname_tab_stack_ = scm_cdr (pitchname_tab_stack_);
853 hidden_state_ = YYSTATE;
854 yy_push_state (extratoken);
859 Lily_lexer::identifier_type (SCM sid)
861 int k = try_special_identifiers (&yylval.scm , sid);
862 return k >= 0 ? k : SCM_IDENTIFIER;
867 Lily_lexer::scan_escaped_word (string str)
869 // use more SCM for this.
871 // SCM sym = ly_symbol2scm (str.c_str ());
873 int i = lookup_keyword (str);
874 if (i == MARKUP && is_lyric_state ())
879 SCM sid = lookup_identifier (str);
880 if (sid != SCM_UNDEFINED)
881 return scan_scm_id (sid);
883 string msg (_f ("unknown escaped string: `\\%s'", str));
884 LexerError (msg.c_str ());
886 yylval.scm = ly_string2scm (str);
892 Lily_lexer::scan_scm_id (SCM sid)
894 if (is_music_function (sid))
896 int funtype = SCM_FUNCTION;
900 SCM s = get_music_function_signature (sid);
901 SCM cs = scm_car (s);
903 if (scm_is_pair (cs))
908 if (scm_is_eq (cs, ly_lily_module_constant ("ly:music?")))
909 funtype = MUSIC_FUNCTION;
910 else if (scm_is_eq (cs, ly_lily_module_constant ("ly:event?")))
911 funtype = EVENT_FUNCTION;
912 else if (ly_is_procedure (cs))
913 funtype = SCM_FUNCTION;
914 else programming_error ("Bad syntax function predicate");
916 push_extra_token (EXPECT_NO_MORE_ARGS);
917 for (s = scm_cdr (s); scm_is_pair (s); s = scm_cdr (s))
919 SCM optional = SCM_UNDEFINED;
922 if (scm_is_pair (cs))
924 optional = SCM_CDR (cs);
928 if (cs == Pitch_type_p_proc)
929 push_extra_token (EXPECT_PITCH);
930 else if (cs == Duration_type_p_proc)
931 push_extra_token (EXPECT_DURATION);
932 else if (ly_is_procedure (cs))
933 push_extra_token (EXPECT_SCM, cs);
936 programming_error ("Function parameter without type-checking predicate");
939 if (!scm_is_eq (optional, SCM_UNDEFINED))
940 push_extra_token (EXPECT_OPTIONAL, optional);
945 return identifier_type (sid);
949 Lily_lexer::scan_bare_word (string str)
951 SCM sym = ly_symbol2scm (str.c_str ());
952 if ((YYSTATE == notes) || (YYSTATE == chords)) {
953 SCM handle = SCM_BOOL_F;
954 if (scm_is_pair (pitchname_tab_stack_))
955 handle = scm_hashq_get_handle (scm_car (pitchname_tab_stack_), sym);
957 if (scm_is_pair (handle)) {
958 yylval.scm = scm_cdr (handle);
959 if (unsmob_pitch (yylval.scm))
960 return (YYSTATE == notes) ? NOTENAME_PITCH : TONICNAME_PITCH;
961 else if (scm_is_symbol (yylval.scm))
964 else if ((YYSTATE == chords)
965 && (handle = scm_hashq_get_handle (chordmodifier_tab_, sym))!= SCM_BOOL_F)
967 yylval.scm = scm_cdr (handle);
968 return CHORD_MODIFIER;
971 yylval.scm = ly_string2scm (str);
976 Lily_lexer::get_state () const
978 if (YY_START == extratoken)
979 return hidden_state_;
985 Lily_lexer::is_note_state () const
987 return get_state () == notes;
991 Lily_lexer::is_chord_state () const
993 return get_state () == chords;
997 Lily_lexer::is_lyric_state () const
999 return get_state () == lyrics;
1003 Lily_lexer::is_figure_state () const
1005 return get_state () == figures;
1009 Lily_lexer::eval_scm (SCM readerdata)
1011 SCM sval = SCM_UNDEFINED;
1013 if (!SCM_UNBNDP (readerdata))
1015 sval = ly_eval_scm (scm_car (readerdata),
1016 *unsmob_input (scm_cdr (readerdata)),
1017 be_safe_global && is_main_input_,
1021 if (SCM_UNBNDP (sval))
1024 return SCM_UNSPECIFIED;
1029 /* Check for valid UTF-8 that has no overlong or surrogate codes and
1030 is in the range 0-0x10ffff */
1033 Lily_lexer::YYText_utf8 ()
1035 const char * const p = YYText ();
1036 for (int i=0; p[i];) {
1037 if ((p[i] & 0xff) < 0x80) {
1041 int oldi = i; // start of character
1042 int more = 0; // # of followup bytes, 0 if bad
1043 switch (p[i++] & 0xff) {
1044 // 0xc0 and 0xc1 are overlong prefixes for
1045 // 0x00-0x3f and 0x40-0x7f respectively, bad.
1046 case 0xc2: // 0x80-0xbf
1047 case 0xc3: // 0xc0-0xff
1048 case 0xc4: // 0x100-0x13f
1049 case 0xc5: // 0x140-0x17f
1050 case 0xc6: // 0x180-0x1bf
1051 case 0xc7: // 0x1c0-0x1ff
1052 case 0xc8: // 0x200-0x23f
1053 case 0xc9: // 0x240-0x27f
1054 case 0xca: // 0x280-0x2bf
1055 case 0xcb: // 0x2c0-0x2ff
1056 case 0xcc: // 0x300-0x33f
1057 case 0xcd: // 0x340-0x37f
1058 case 0xce: // 0x380-0x3bf
1059 case 0xcf: // 0x3c0-0x3ff
1060 case 0xd0: // 0x400-0x43f
1061 case 0xd1: // 0x440-0x47f
1062 case 0xd2: // 0x480-0x4bf
1063 case 0xd3: // 0x4c0-0x4ff
1064 case 0xd4: // 0x500-0x53f
1065 case 0xd5: // 0x540-0x57f
1066 case 0xd6: // 0x580-0x5bf
1067 case 0xd7: // 0x5c0-0x5ff
1068 case 0xd8: // 0x600-0x63f
1069 case 0xd9: // 0x640-0x67f
1070 case 0xda: // 0x680-0x6bf
1071 case 0xdb: // 0x6c0-0x6ff
1072 case 0xdc: // 0x700-0x73f
1073 case 0xdd: // 0x740-0x77f
1074 case 0xde: // 0x780-0x7bf
1075 case 0xdf: // 0x7c0-0x7ff
1076 more = 1; // 2-byte sequences, 0x80-0x7ff
1079 // don't allow overlong sequences for 0-0x7ff
1080 if ((p[i] & 0xff) < 0xa0)
1082 case 0xe1: // 0x1000-0x1fff
1083 case 0xe2: // 0x2000-0x2fff
1084 case 0xe3: // 0x3000-0x3fff
1085 case 0xe4: // 0x4000-0x4fff
1086 case 0xe5: // 0x5000-0x5fff
1087 case 0xe6: // 0x6000-0x6fff
1088 case 0xe7: // 0x7000-0x7fff
1089 case 0xe8: // 0x8000-0x8fff
1090 case 0xe9: // 0x9000-0x9fff
1091 case 0xea: // 0xa000-0xafff
1092 case 0xeb: // 0xb000-0xbfff
1093 case 0xec: // 0xc000-0xcfff
1094 more = 2; // 3-byte sequences, 0x7ff-0xcfff
1096 case 0xed: // 0xd000-0xdfff
1097 // Don't allow surrogate codes 0xd800-0xdfff
1098 if ((p[i] & 0xff) >= 0xa0)
1100 case 0xee: // 0xe000-0xefff
1101 case 0xef: // 0xf000-0xffff
1102 more = 2; // 3-byte sequences,
1103 // 0xd000-0xd7ff, 0xe000-0xffff
1106 // don't allow overlong sequences for 0-0xffff
1107 if ((p[i] & 0xff) < 0x90)
1109 case 0xf1: // 0x40000-0x7ffff
1110 case 0xf2: // 0x80000-0xbffff
1111 case 0xf3: // 0xc0000-0xfffff
1112 more = 3; // 4-byte sequences, 0x10000-0xfffff
1115 // don't allow more than 0x10ffff
1116 if ((p[i] & 0xff) >= 0x90)
1118 more = 3; // 4-byte sequence, 0x100000-0x10ffff
1122 // check that all continuation bytes are valid
1124 if ((p[i++] & 0xc0) != 0x80)
1130 Input h = here_input ();
1131 h.set (h.get_source_file (), h.start () + oldi, h.start () + i);
1132 h.warning (_ ("non-UTF-8 input").c_str ());
1139 urg, belong to string (_convert)
1140 and should be generalised
1143 strip_leading_white (string&s)
1146 for (; i < s.length (); i++)
1147 if (!isspace (s[i]))
1154 strip_trailing_white (string&s)
1156 ssize i = s.length ();
1158 if (!isspace (s[i]))
1161 s = s.substr (0, i + 1);
1166 Lilypond_version oldest_version ("2.7.38");
1170 is_valid_version (string s)
1172 Lilypond_version current ( MAJOR_VERSION "." MINOR_VERSION "." PATCH_LEVEL );
1173 Lilypond_version ver (s);
1174 if (int (ver) < oldest_version)
1176 non_fatal_error (_f ("file too old: %s (oldest supported: %s)", ver.to_string (), oldest_version.to_string ()));
1177 non_fatal_error (_ ("consider updating the input with the convert-ly script"));
1183 non_fatal_error (_f ("program too old: %s (file requires: %s)", current.to_string (), ver.to_string ()));
1194 lyric_fudge (string s)
1198 while ((i = s.find ('_', i)) != string::npos)
1206 Convert "NUM/DEN" into a '(NUM . DEN) cons.
1209 scan_fraction (string frac)
1211 ssize i = frac.find ('/');
1212 string left = frac.substr (0, i);
1213 string right = frac.substr (i + 1, (frac.length () - i + 1));
1215 int n = String_convert::dec2int (left);
1216 int d = String_convert::dec2int (right);
1217 return scm_cons (scm_from_int (n), scm_from_int (d));
1221 lookup_markup_command (string s)
1223 SCM proc = ly_lily_module_constant ("lookup-markup-command");
1224 return scm_call_1 (proc, ly_string2scm (s));
1228 lookup_markup_list_command (string s)
1230 SCM proc = ly_lily_module_constant ("lookup-markup-list-command");
1231 return scm_call_1 (proc, ly_string2scm (s));
1234 /* Shut up lexer warnings. */
1254 silence_lexer_warnings ()
1256 (void) yy_start_stack_ptr;
1257 (void) yy_start_stack_depth;
1258 (void) yy_start_stack;
1259 (void) yy_push_state;
1260 (void) yy_pop_state;
1261 (void) yy_top_state;
1262 (void) silence_lexer_warnings;