]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/my-lily-lexer.cc (set_encoding): New method.
authorJan Nieuwenhuizen <janneke@gnu.org>
Mon, 5 Apr 2004 21:46:52 +0000 (21:46 +0000)
committerJan Nieuwenhuizen <janneke@gnu.org>
Mon, 5 Apr 2004 21:46:52 +0000 (21:46 +0000)
* lily/lexer.ll: Grok \encoding.

ChangeLog
lily/includable-lexer.cc
lily/include/my-lily-lexer.hh
lily/include/source-file.hh
lily/lexer.ll
lily/my-lily-lexer.cc
lily/parser.yy

index ebd395ce1b17544be2be1e735123463e117b27ba..dae08f1149db05ef24ce407bdcfe3665f1346145 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2004-04-05  Jan Nieuwenhuizen  <janneke@gnu.org>
 
+       * 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.
index 299e72a6388c96dc8e36279e0255410bc7f38e2f..0d420616aa4d1fe265c0d97901e3f7f8e2fc006b 100644 (file)
@@ -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 ());
index 6f012b35491253a758b30cec06c07333a5a3c28b..e8aa8c10b87f903e34326b720d1cbe26bf7bd25a 100644 (file)
@@ -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;
index d1aa173c1512426c33f5b0232c77c164f1ca880d..b50ca1ffe18da6aeac7a7501f96e81377e63003c 100644 (file)
@@ -1,3 +1,10 @@
+/*   
+  source-file.hh -- declare Source_file
+  
+  source file of the GNU LilyPond music typesetter
+  
+  (c) 1999--2004 Jan Nieuwenhuizen <janneke@gnu.org>
+*/
 
 #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 */
 
index af4afebe88877b74c387ef6f786cbfff37418e73..a70a1af4789f829d6f1af1e8fd2df2d241bd360b 100644 (file)
@@ -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            --
   }
 }
 
+<INITIAL>\\encoding{WHITE}*    {
+       yy_push_state (encoding);
+}
 <INITIAL,chords,lyrics,notes,figures>\\version{WHITE}* {
        yy_push_state (version);
 }
 <INITIAL,chords,lyrics,notes,figures>\\renameinput{WHITE}*     {
        yy_push_state (renameinput);
 }
+<encoding>\"[^"]*\"     {
+       String s (YYText () + 1);
+       s = s.left_string (s.index_last ('\"'));
+       set_encoding (s);
+       yy_pop_state ();
+}
 <version>\"[^"]*\"     { /* 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;
 }
-<renameinput>\"[^"]*\"     { /* got the version number */
+<renameinput>\"[^"]*\"     {
        String s (YYText ()+1);
        s = s.left_string (s.index_last ('\"'));
 
@@ -188,13 +194,16 @@ HYPHEN            --
                     scm_makfrom0str (s.to_str0()));
 
 }
-
+<encoding>.    {
+       LexerError (_ ("No quoted string found after \\encoding").to_str0 ());
+       yy_pop_state ();
+}
 <version>.     {
-       LexerError ("No quoted string found after \\version");
+       LexerError (_ ("No quoted string found after \\version").to_str0 ());
        yy_pop_state ();
 }
 <renameinput>.         {
-       LexerError ("No quoted string found after \\renameinput");
+       LexerError (_ ("No quoted string found after \\renameinput").to_str0 ());
        yy_pop_state ();
 }
 <longcomment>{
@@ -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 ()));
 }
index c36b546c8640d5c948750e1c4d4727c27bac0236..941d150715f024fc9d6dae297aa5586d9ea4b5cb 100644 (file)
@@ -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;
+}
index dcda1be7cc6a35559eb9ada4e119af1d59982812..f0e96c87b098d61aee15d576c2ab6c00457c57b7 100644 (file)
@@ -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;