From c4762562d9d82f9726838e48c4dbcbbcc1f831fa Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Mon, 5 Apr 2004 21:46:52 +0000 Subject: [PATCH] * lily/my-lily-lexer.cc (set_encoding): New method. * lily/lexer.ll: Grok \encoding. --- ChangeLog | 4 ++++ lily/includable-lexer.cc | 6 ++--- lily/include/my-lily-lexer.hh | 4 +++- lily/include/source-file.hh | 11 +++++++-- lily/lexer.ll | 45 +++++++++++++++++++++-------------- lily/my-lily-lexer.cc | 31 ++++++++++++------------ lily/parser.yy | 17 ++++++++----- 7 files changed, 73 insertions(+), 45 deletions(-) diff --git a/ChangeLog b/ChangeLog index ebd395ce1b..dae08f1149 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2004-04-05 Jan Nieuwenhuizen + * lily/my-lily-lexer.cc (set_encoding): New method. + + * lily/lexer.ll: Grok \encoding. + * lily/font-metric.cc (get_encoded_index): New function. * lily/include/font-metric.hh (coding_scheme): New method. diff --git a/lily/includable-lexer.cc b/lily/includable-lexer.cc index 299e72a638..0d420616aa 100644 --- a/lily/includable-lexer.cc +++ b/lily/includable-lexer.cc @@ -51,15 +51,15 @@ Includable_lexer::new_input (String s, Sources * global_sources) return; } - Source_file * sl = global_sources->get_file (s); + Source_file *sl = global_sources->get_file (s); if (!sl) { String msg = _f ("can't find file: `%s'", s); msg += "\n"; - msg += _f ("(search path: `%s')", global_sources->path_->to_string ().to_str0 ()); + msg += _f ("(search path: `%s')", + global_sources->path_->to_string ().to_str0 ()); msg += "\n"; LexerError (msg.to_str0 ()); - return; } filename_strings_.push (sl->name_string ()); diff --git a/lily/include/my-lily-lexer.hh b/lily/include/my-lily-lexer.hh index 6f012b3549..e8aa8c10b8 100644 --- a/lily/include/my-lily-lexer.hh +++ b/lily/include/my-lily-lexer.hh @@ -30,7 +30,8 @@ class My_lily_lexer : public Includable_lexer Protected_scm scopes_; public: String main_input_name_; - void * lexval; + String encoding_; + void *lexval; bool main_input_b_; /* @@ -63,6 +64,7 @@ public: void push_lyric_state (); void pop_state (); void LexerError (char const *); + void set_encoding (String); void set_identifier (SCM name_string, SCM); bool is_note_state () const; bool is_chord_state () const; diff --git a/lily/include/source-file.hh b/lily/include/source-file.hh index d1aa173c15..b50ca1ffe1 100644 --- a/lily/include/source-file.hh +++ b/lily/include/source-file.hh @@ -1,3 +1,10 @@ +/* + source-file.hh -- declare Source_file + + source file of the GNU LilyPond music typesetter + + (c) 1999--2004 Jan Nieuwenhuizen +*/ #ifndef SOURCE_FILE_HH #define SOURCE_FILE_HH @@ -71,7 +78,7 @@ private: Protected_scm str_port_; }; -char * gulp_file (String fn, int *len); +char *gulp_file (String fn, int *len); -#endif // SOURCE_FILE_HH // +#endif /* SOURCE_FILE_HH */ diff --git a/lily/lexer.ll b/lily/lexer.ll index af4afebe88..a70a1af478 100644 --- a/lily/lexer.ll +++ b/lily/lexer.ll @@ -59,12 +59,8 @@ void strip_trailing_white (String&); void strip_leading_white (String&); String lyric_fudge (String s); -SCM -lookup_markup_command (String s); - -bool -is_valid_version (String s); - +SCM lookup_markup_command (String s); +bool is_valid_version (String s); #define start_quote() \ @@ -98,6 +94,7 @@ SCM (* scm_parse_error_handler) (void *); %option never-interactive %option warn +%x encoding %x renameinput %x version %x chords @@ -160,21 +157,30 @@ HYPHEN -- } } +\\encoding{WHITE}* { + yy_push_state (encoding); +} \\version{WHITE}* { yy_push_state (version); } \\renameinput{WHITE}* { yy_push_state (renameinput); } +\"[^"]*\" { + String s (YYText () + 1); + s = s.left_string (s.index_last ('\"')); + set_encoding (s); + yy_pop_state (); +} \"[^"]*\" { /* got the version number */ - String s (YYText ()+1); + String s (YYText () + 1); s = s.left_string (s.index_last ('\"')); - yy_pop_state(); - if (!is_valid_version (s)) + yy_pop_state (); + if (!is_valid_version (s)) return INVALID; } -\"[^"]*\" { /* got the version number */ +\"[^"]*\" { String s (YYText ()+1); s = s.left_string (s.index_last ('\"')); @@ -188,13 +194,16 @@ HYPHEN -- scm_makfrom0str (s.to_str0())); } - +. { + LexerError (_ ("No quoted string found after \\encoding").to_str0 ()); + yy_pop_state (); +} . { - LexerError ("No quoted string found after \\version"); + LexerError (_ ("No quoted string found after \\version").to_str0 ()); yy_pop_state (); } . { - LexerError ("No quoted string found after \\renameinput"); + LexerError (_ ("No quoted string found after \\renameinput").to_str0 ()); yy_pop_state (); } { @@ -457,7 +466,7 @@ HYPHEN -- return '>'; } {MARKUPCOMMAND} { - String str (YYText() + 1); + String str (YYText () + 1); SCM s = lookup_markup_command (str); if (gh_pair_p (s) && gh_symbol_p (gh_cdr (s)) ) { @@ -479,7 +488,7 @@ HYPHEN -- return MARKUP_HEAD_SCM0_MARKUP1; else if (tag == ly_symbol2scm ("scheme0-scheme1-markup2")) return MARKUP_HEAD_SCM0_SCM1_MARKUP2; - else if (tag == ly_symbol2scm ("scheme0-scheme1-scheme2")) + else if (tag ==4 ly_symbol2scm ("scheme0-scheme1-scheme2")) return MARKUP_HEAD_SCM0_SCM1_SCM2; else { programming_error ("No parser tag defined for this signature. Abort"); @@ -490,13 +499,14 @@ HYPHEN -- return scan_escaped_word (str); } [{}] { - return YYText()[0]; + return YYText ()[0]; } [^#{}"\\ \t\n\r\f]+ { String s (YYText ()); char c = s[s.length () - 1]; - if (c == '{' || c == '}') // brace open is for not confusing dumb tools. + /* brace open is for not confusing dumb tools. */ + if (c == '{' || c == '}') here_input ().warning ( _ ("Brace found at end of markup. Did you forget a space?")); yylval.scm = scm_makfrom0str (s.to_str0 ()); @@ -826,6 +836,5 @@ SCM lookup_markup_command (String s) { SCM proc = ly_scheme_function ("lookup-markup-command"); - return scm_call_1 (proc, scm_makfrom0str (s.to_str0 ())); } diff --git a/lily/my-lily-lexer.cc b/lily/my-lily-lexer.cc index c36b546c86..941d150715 100644 --- a/lily/my-lily-lexer.cc +++ b/lily/my-lily-lexer.cc @@ -25,7 +25,7 @@ #include "ly-module.hh" -static Keyword_ent the_key_tab[]={ +static Keyword_ent the_key_tab[] = { {"acciaccatura", ACCIACCATURA}, {"accepts", ACCEPTS}, {"addlyrics", ADDLYRICS}, @@ -88,7 +88,7 @@ static Keyword_ent the_key_tab[]={ {"type", TYPE}, {"unset", UNSET}, {"with", WITH}, - {0,0} + {0, 0} }; @@ -102,7 +102,7 @@ My_lily_lexer::My_lily_lexer () scopes_ = SCM_EOL; add_scope (ly_make_anonymous_module ()); - errorlevel_ =0; + errorlevel_ = 0; main_input_b_ = false; } @@ -114,17 +114,14 @@ My_lily_lexer::add_scope (SCM module) scm_set_current_module (module); for (SCM s = scopes_; gh_pair_p (s); s = gh_cdr (s)) { - /* - UGH. how to do this more neatly? - */ - SCM expr = scm_list_n (ly_symbol2scm ("module-use!"), - module, scm_list_n (ly_symbol2scm ("module-public-interface"), - gh_car (s), SCM_UNDEFINED), - SCM_UNDEFINED); - + /* UGH. how to do this more neatly? */ + SCM expr + = scm_list_3 (ly_symbol2scm ("module-use!"), + module, + scm_list_2 (ly_symbol2scm ("module-public-interface"), + gh_car (s))); scm_primitive_eval (expr); } - scopes_ = scm_cons (module, scopes_); } @@ -203,9 +200,7 @@ void My_lily_lexer::LexerError (char const *s) { if (include_stack_.is_empty ()) - { - progress_indication (_f ("error at EOF: %s", s)+ String ("\n")); - } + progress_indication (_f ("error at EOF: %s", s) + String ("\n")); else { errorlevel_ |= 1; @@ -244,3 +239,9 @@ My_lily_lexer::prepare_for_next_token () { last_input_ = here_input (); } + +void +My_lily_lexer::set_encoding (String s) +{ + encoding_ = s; +} diff --git a/lily/parser.yy b/lily/parser.yy index dcda1be7cc..f0e96c87b0 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -107,8 +107,15 @@ SCM make_simple_markup (SCM a) { SCM simple = ly_scheme_function ("simple-markup"); - - return scm_list_2 (simple, a); + SCM markup = scm_list_2 (simple, a); +#if 0 + if (THIS->lexer_->encoding_ != "") + return scm_list_2 + (scm_cons (ly_scheme_function ("encoding"), + scm_makfrom0str (THIS->lexer_->encoding_.to_str0 ())), + markup); +#endif +return markup; } @@ -122,9 +129,7 @@ void set_music_properties (Music *p, SCM a) { for (SCM k = a; gh_pair_p (k); k = ly_cdr (k)) - { - p->internal_set_property (ly_caar (k), ly_cdar (k)); - } + p->internal_set_property (ly_caar (k), ly_cdar (k)); } SCM @@ -186,7 +191,7 @@ of the parse stack onto the heap. */ int yylex (YYSTYPE *s, void *v) { - My_lily_parser *pars = (My_lily_parser*) v; + My_lily_parser *pars = (My_lily_parser*) v; My_lily_lexer *lex = pars->lexer_; lex->lexval = (void*) s; -- 2.39.2