CVSROOT:        /cvsroot/lilypond
Module name:    lilypond
Branch:         
Changes by:     Han-Wen Nienhuys <[EMAIL PROTECTED]>    05/06/10 10:58:50

Modified files:
        .              : ChangeLog 
        input/regression: beam-quant-standard.ly 
        lily           : lily-lexer.cc lily-parser-scheme.cc 
                         lily-parser.cc 
        lily/include   : lily-lexer.hh lily-parser.hh 
        ly             : spanners-init.ly 
        scm            : ly-from-scheme.scm 
Added files:
        lily           : default-actions.cc 

Log message:
        * lily/default-actions.cc (Module): new file. default
        {book,score}-print functions.
        
        * scm/ly-from-scheme.scm (ly:parse-string-result): use new setup:
        pass results via parseStringResult, lookup via ly:parser-lookup.
        
        * lily/lily-parser.cc (Lily_parser): only clone lexer in
        constructors.
        (parse_file): encapsulate do_yyparse() in scm_set_current_module()
        (parse_string): idem.
        
        * ly/spanners-init.ly (assertBeamQuant): don't use #{ #} in init.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/ChangeLog.diff?tr1=1.3757&tr2=1.3758&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/input/regression/beam-quant-standard.ly.diff?tr1=1.11&tr2=1.12&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/lily/default-actions.cc?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/lily/lily-lexer.cc.diff?tr1=1.30&tr2=1.31&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/lily/lily-parser-scheme.cc.diff?tr1=1.14&tr2=1.15&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/lily/lily-parser.cc.diff?tr1=1.40&tr2=1.41&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/lily/include/lily-lexer.hh.diff?tr1=1.13&tr2=1.14&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/lily/include/lily-parser.hh.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/ly/spanners-init.ly.diff?tr1=1.40&tr2=1.41&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/scm/ly-from-scheme.scm.diff?tr1=1.8&tr2=1.9&r1=text&r2=text

Patches:
Index: lilypond/ChangeLog
diff -u lilypond/ChangeLog:1.3757 lilypond/ChangeLog:1.3758
--- lilypond/ChangeLog:1.3757   Fri Jun 10 09:29:03 2005
+++ lilypond/ChangeLog  Fri Jun 10 10:58:48 2005
@@ -1,5 +1,18 @@
 2005-06-10  Han-Wen Nienhuys  <[EMAIL PROTECTED]>
 
+       * lily/default-actions.cc (Module): new file. default
+       {book,score}-print functions.
+
+       * scm/ly-from-scheme.scm (ly:parse-string-result): use new setup:
+       pass results via parseStringResult, lookup via ly:parser-lookup.  
+
+       * lily/lily-parser.cc (Lily_parser): only clone lexer in
+       constructors.
+       (parse_file): encapsulate do_yyparse() in scm_set_current_module()
+       (parse_string): idem.
+
+       * ly/spanners-init.ly (assertBeamQuant): don't use #{ #} in init.
+
        * lily/main.cc (main_with_guile): copy be_verbose_global into
        ly_set_option()
 
Index: lilypond/input/regression/beam-quant-standard.ly
diff -u lilypond/input/regression/beam-quant-standard.ly:1.11 
lilypond/input/regression/beam-quant-standard.ly:1.12
--- lilypond/input/regression/beam-quant-standard.ly:1.11       Sat Oct 30 
20:55:15 2004
+++ lilypond/input/regression/beam-quant-standard.ly    Fri Jun 10 10:58:49 2005
@@ -142,5 +142,5 @@
     \filler
 }
 
-{ \primes \seconds \primeSixteenths }
+\new Voice { \primes \seconds \primeSixteenths }
 
Index: lilypond/lily/include/lily-lexer.hh
diff -u lilypond/lily/include/lily-lexer.hh:1.13 
lilypond/lily/include/lily-lexer.hh:1.14
--- lilypond/lily/include/lily-lexer.hh:1.13    Fri Jun 10 00:36:22 2005
+++ lilypond/lily/include/lily-lexer.hh Fri Jun 10 10:58:49 2005
@@ -60,7 +60,7 @@
   Input here_input () const;
 
   void add_scope (SCM);
-  void set_current_scope ();
+  SCM set_current_scope ();
   SCM remove_scope ();
 
   void start_main_input ();
Index: lilypond/lily/include/lily-parser.hh
diff -u lilypond/lily/include/lily-parser.hh:1.7 
lilypond/lily/include/lily-parser.hh:1.8
--- lilypond/lily/include/lily-parser.hh:1.7    Thu Jun  9 18:05:31 2005
+++ lilypond/lily/include/lily-parser.hh        Fri Jun 10 10:58:50 2005
@@ -6,8 +6,8 @@
   (c) 1997--2005 Han-Wen Nienhuys <[EMAIL PROTECTED]>
 */
 
-#ifndef MY_LILY_PARSER_HH
-#define MY_LILY_PARSER_HH
+#ifndef LILY_PARSER_HH
+#define LILY_PARSER_HH
 
 #include "duration.hh"
 #include "input.hh"
@@ -62,7 +62,7 @@
   void set_yydebug (bool);
 };
 
-DECLARE_UNSMOB (Lily_parser, my_lily_parser);
+DECLARE_UNSMOB (Lily_parser, lily_parser);
 
 SCM ly_parse_file (SCM);
 SCM ly_parse_string (SCM);
@@ -76,4 +76,4 @@
 Output_def *get_midi (Lily_parser *parser);
 Output_def *get_paper (Lily_parser *parser);
 
-#endif /* MY_LILY_PARSER_HH */
+#endif /* LILY_PARSER_HH */
Index: lilypond/lily/lily-lexer.cc
diff -u lilypond/lily/lily-lexer.cc:1.30 lilypond/lily/lily-lexer.cc:1.31
--- lilypond/lily/lily-lexer.cc:1.30    Fri Jun 10 00:36:21 2005
+++ lilypond/lily/lily-lexer.cc Fri Jun 10 10:58:49 2005
@@ -143,12 +143,13 @@
   if (!scm_is_pair (scopes_))
     start_module_ = scm_current_module ();
   
-  scm_set_current_module (module);
   for (SCM s = scopes_; scm_is_pair (s); s = scm_cdr (s))
     {
       ly_use_module (module, scm_car (s));
     }
   scopes_ = scm_cons (module, scopes_);
+
+  set_current_scope ();
 }
 
 
@@ -161,13 +162,17 @@
   return sc;
 }
 
-void
+SCM
 Lily_lexer::set_current_scope ()
 {
+  SCM old = scm_current_module ();
+  
   if (scm_is_pair (scopes_))
     scm_set_current_module (scm_car (scopes_));
   else
     scm_set_current_module (start_module_);
+
+  return old;
 }
 
 int
@@ -300,13 +305,17 @@
 
   scm_gc_mark (lexer->chordmodifier_tab_);
   scm_gc_mark (lexer->pitchname_tab_stack_);
+  scm_gc_mark (lexer->start_module_);
   return lexer->scopes_;
 }
 
 int
-Lily_lexer::print_smob (SCM, SCM port, scm_print_state*)
+Lily_lexer::print_smob (SCM s, SCM port, scm_print_state*)
 {
+  Lily_lexer *lexer = Lily_lexer::unsmob (s);
+
   scm_puts ("#<Lily_lexer ", port);
+  scm_display (lexer->scopes_, port);
   scm_puts (" >", port);
   return 1;
 }
Index: lilypond/lily/lily-parser-scheme.cc
diff -u lilypond/lily/lily-parser-scheme.cc:1.14 
lilypond/lily/lily-parser-scheme.cc:1.15
--- lilypond/lily/lily-parser-scheme.cc:1.14    Thu Jun  9 11:52:07 2005
+++ lilypond/lily/lily-parser-scheme.cc Fri Jun 10 10:58:49 2005
@@ -15,12 +15,7 @@
 #include "warn.hh"
 #include "source.hh"
 #include "lily-lexer.hh"
-#include "score.hh"
-#include "lilypond-key.hh"
 #include "ly-module.hh"
-#include "output-def.hh"
-#include "book.hh"
-#include "paper-book.hh"
 #include "file-name-map.hh"
 
 /* Do not append `!' suffix, since 1st argument is not modified. */
@@ -156,10 +151,9 @@
           1, 0, 0, (SCM parser_smob),
           "Return a clone of PARSER_SMOB.")
 {
-  Lily_parser *parser = unsmob_my_lily_parser (parser_smob);
+  Lily_parser *parser = unsmob_lily_parser (parser_smob);
   Lily_parser *clone = new Lily_parser (*parser);
 
-  /* FIXME: should copy scopes too. */
   return scm_gc_unprotect_object (clone->self_scm ());
 }
 
@@ -167,7 +161,7 @@
           3, 0, 0, (SCM parser_smob, SCM symbol, SCM val),
           "Bind SYMBOL to VAL in PARSER_SMOB's module.")
 {
-  Lily_parser *parser = unsmob_my_lily_parser (parser_smob);
+  Lily_parser *parser = unsmob_lily_parser (parser_smob);
   SCM_ASSERT_TYPE (scm_is_symbol (symbol), symbol, SCM_ARG2, __FUNCTION__, 
"symbol");
   SCM_ASSERT_TYPE (parser, parser_smob, SCM_ARG2, __FUNCTION__, "parser");
 
@@ -180,7 +174,7 @@
           "Lookup @var{symbol} in @var{parser_smob}'s module.  "
           "Undefined is '().")
 {
-  Lily_parser *parser = unsmob_my_lily_parser (parser_smob);
+  Lily_parser *parser = unsmob_lily_parser (parser_smob);
 
   SCM_ASSERT_TYPE (scm_is_symbol (symbol), symbol, SCM_ARG2, __FUNCTION__, 
"symbol");
   SCM_ASSERT_TYPE (parser, parser_smob, SCM_ARG2, __FUNCTION__, "parser");
@@ -197,7 +191,7 @@
           "Parse the string LY_CODE with PARSER_SMOB."
           "Upon failure, throw @code{ly-file-failed} key.")
 {
-  Lily_parser *parser = unsmob_my_lily_parser (parser_smob);
+  Lily_parser *parser = unsmob_lily_parser (parser_smob);
 
   SCM_ASSERT_TYPE (parser, parser_smob, SCM_ARG1, __FUNCTION__, "parser");
   SCM_ASSERT_TYPE (scm_is_string (ly_code), ly_code, SCM_ARG2, __FUNCTION__, 
"string");
@@ -207,63 +201,13 @@
   return SCM_UNSPECIFIED;
 }
 
-/* TODO: move this to Scheme?  Why take the parser arg, and all the back
-   & forth between scm and c++? */
-LY_DEFINE (ly_parser_print_score, "ly:parser-print-score",
-          2, 0, 0,
-          (SCM parser_smob, SCM score_smob),
-          "Print score, i.e., the classic way.")
-{
-  Lily_parser *parser = unsmob_my_lily_parser (parser_smob);
-  Score *score = unsmob_score (score_smob);
-
-  Object_key *key = new Lilypond_general_key (0, score->user_key_, 0);
-
-  if (score->error_found_)
-    return SCM_UNSPECIFIED;
-
-  SCM_ASSERT_TYPE (parser, parser_smob, SCM_ARG1, __FUNCTION__, "parser");
-  SCM_ASSERT_TYPE (score, score_smob, SCM_ARG2, __FUNCTION__, "score");
-
-  SCM header = ly_c_module_p (score->header_)
-    ? score->header_
-    : parser->lexer_->lookup_identifier ("$globalheader");
-
-  File_name outname (parser->output_basename_);
-  int *c = &parser->book_count_;
-  if (*c)
-    outname.base_ += "-" + to_string (*c);
-  (*c)++;
-
-  SCM os = scm_makfrom0str (outname.to_string ().to_str0 ());
-  SCM paper = get_paper (parser)->self_scm ();
-  for (int i = 0; i < score->defs_.size (); i++)
-    default_rendering (score->get_music (), score->defs_[i]->self_scm (),
-                      paper, header, os, key->self_scm ());
-
-  if (score->defs_.is_empty ())
-    {
-      Output_def *layout = get_layout (parser);
-      default_rendering (score->get_music (),
-                        layout->self_scm (),
-                        paper,
-                        header, os, key->self_scm ());
-      
-      scm_gc_unprotect_object (layout->self_scm ());
-    }
-
-  scm_gc_unprotect_object (paper);
-  scm_gc_unprotect_object (key->self_scm ());
-  return SCM_UNSPECIFIED;
-}
-
 LY_DEFINE (ly_parser_set_note_names, "ly:parser-set-note-names",
           2, 0, 0, (SCM parser, SCM names),
           "Replace current note names in @var{parser}. "
           "@var{names} is an alist of symbols.  "
           "This only has effect if the current mode is notes.")
 {
-  Lily_parser *p = unsmob_my_lily_parser (parser);
+  Lily_parser *p = unsmob_lily_parser (parser);
   SCM_ASSERT_TYPE (p, parser, SCM_ARG1, __FUNCTION__, "Lilypond parser");
 
   if (p->lexer_->is_note_state ())
@@ -274,37 +218,3 @@
 
   return SCM_UNSPECIFIED;
 }
-
-LY_DEFINE (ly_parser_print_book, "ly:parser-print-book",
-          2, 0, 0, (SCM parser_smob, SCM book_smob),
-          "Print book.")
-{
-  Lily_parser *parser = unsmob_my_lily_parser (parser_smob);
-  Book *book = unsmob_book (book_smob);
-  Output_def *bp = unsmob_output_def (parser->lexer_->lookup_identifier 
("$defaultpaper"));
-
-  SCM_ASSERT_TYPE (parser, parser_smob, SCM_ARG1, __FUNCTION__, "Lilypond 
parser");
-  SCM_ASSERT_TYPE (book, book_smob, SCM_ARG2, __FUNCTION__, "Book");
-
-  /*  ugh. changing argument.*/
-  book->paper_ = bp;
-
-  File_name outname (parser->output_basename_);
-  int *c = &parser->book_count_;
-  if (*c)
-    outname.base_ += "-" + to_string (*c);
-  (*c)++;
-
-  Output_def *layout = get_layout (parser);
-  Paper_book *pb = book->process (outname.to_string (), layout);
-
-  if (pb)
-    {
-      pb->output (outname.to_string ());
-      scm_gc_unprotect_object (pb->self_scm ());
-    }
-
-  scm_gc_unprotect_object (layout->self_scm ());
-  return SCM_UNSPECIFIED;
-}
-
Index: lilypond/lily/lily-parser.cc
diff -u lilypond/lily/lily-parser.cc:1.40 lilypond/lily/lily-parser.cc:1.41
--- lilypond/lily/lily-parser.cc:1.40   Fri Jun 10 00:36:22 2005
+++ lilypond/lily/lily-parser.cc        Fri Jun 10 10:58:49 2005
@@ -33,6 +33,9 @@
   error_level_ = 0;
 
   smobify_self ();
+
+  lexer_ = new Lily_lexer (sources_);
+  scm_gc_unprotect_object (lexer_->self_scm ());
 }
 
 Lily_parser::Lily_parser (Lily_parser const &src)
@@ -71,9 +74,9 @@
 int
 Lily_parser::print_smob (SCM s, SCM port, scm_print_state*)
 {
-  scm_puts ("#<my_lily_parser ", port);
+  scm_puts ("#<Lily_parser ", port);
   Lily_parser *parser = (Lily_parser *) SCM_CELL_WORD_1 (s);
-  (void) parser;
+  scm_display (parser->lexer_->self_scm (), port);
   scm_puts (" >", port);
   return 1;
 }
@@ -87,10 +90,6 @@
       try_load_text_metrics (out_name);
     }
 
-  SCM oldmod = scm_current_module ();
-
-  lexer_ = new Lily_lexer (sources_);
-  scm_gc_unprotect_object (lexer_->self_scm ());
   // TODO: use $parser 
   lexer_->set_identifier (ly_symbol2scm ("parser"),
                          self_scm ());
@@ -112,8 +111,11 @@
 
   /* Read .ly IN_FILE, lex, parse, write \score blocks from IN_FILE to
      OUT_FILE (unless IN_FILE redefines output file name).  */
-  do_yyparse ();
 
+  SCM mod = lexer_->set_current_scope ();
+  do_yyparse ();
+  scm_set_current_module (mod);
+ 
   if (!define_spots_.is_empty ())
     {
       define_spots_.top ().warning (_ ("braces don't match"));
@@ -122,20 +124,12 @@
 
   error_level_ = error_level_ | lexer_->error_level_;
   lexer_ = 0;
-
-  scm_set_current_module (oldmod);
 }
 
 void
 Lily_parser::parse_string (String ly_code)
 {
-  Lily_lexer *parent = lexer_;
-  lexer_ = (parent == 0 ? new Lily_lexer (sources_)
-           : new Lily_lexer (*parent));
-  scm_gc_unprotect_object (lexer_->self_scm ());
-
-  SCM oldmod = scm_current_module ();
-  // TODO: use $parser 
+   // TODO: use $parser 
   lexer_->set_identifier (ly_symbol2scm ("parser"),
                          self_scm ());
   
@@ -144,8 +138,11 @@
 
   set_yydebug (0);
   lexer_->new_input (lexer_->main_input_name_, ly_code, sources_);
-  do_yyparse ();
 
+  SCM mod = lexer_->set_current_scope ();
+  do_yyparse ();
+  scm_set_current_module (mod);
+  
   if (!define_spots_.is_empty ())
     {
       if (define_spots_.is_empty ()
@@ -154,9 +151,6 @@
     }
 
   error_level_ = error_level_ | lexer_->error_level_;
-
-  scm_set_current_module (oldmod);
-  lexer_ = 0;
 }
 
 char const *
Index: lilypond/ly/spanners-init.ly
diff -u lilypond/ly/spanners-init.ly:1.40 lilypond/ly/spanners-init.ly:1.41
--- lilypond/ly/spanners-init.ly:1.40   Mon Mar 28 00:05:42 2005
+++ lilypond/ly/spanners-init.ly        Fri Jun 10 10:58:50 2005
@@ -96,22 +96,13 @@
 % for regression testing purposes.
 assertBeamQuant =
 #(def-music-function (parser location l r) (pair? pair?)
-  (let* ((f (check-quant-callbacks l r)))
-   
-   #{
-   \once \override Beam #'position-callbacks = $f
-   #}
-   
-))
-
+  (make-grob-property-override 'Beam 'position-callbacks
+   (check-quant-callbacks l r)))
+    
 % for regression testing purposes.
 assertBeamSlope =
 #(def-music-function (parser location comp) (procedure?)
-  (let* ((f (check-slope-callbacks comp)))
-   
-   #{
-   \once \override Beam #'position-callbacks = $f
-   #}
-   
-))
+  (make-grob-property-override 'Beam 'position-callbacks
+   (check-slope-callbacks comp)))
+
 
Index: lilypond/scm/ly-from-scheme.scm
diff -u lilypond/scm/ly-from-scheme.scm:1.8 lilypond/scm/ly-from-scheme.scm:1.9
--- lilypond/scm/ly-from-scheme.scm:1.8 Sun Feb 27 10:06:03 2005
+++ lilypond/scm/ly-from-scheme.scm     Fri Jun 10 10:58:50 2005
@@ -16,18 +16,14 @@
                                                                                
             (char->integer #\0)))))
                                                  (string->list (number->string 
var-idx)))))))))
 
-(define-public (ly:parse-string-result str parser module)
+(define-public (ly:parse-string-result str parser)
   "Parse `str', which is supposed to contain a music expression."
   (let ((music-sym (gen-lily-sym)))
     (ly:parser-parse-string
      parser
-     (format #f "
-~a = { ~a }
-#(ly:export '~a)
-#(module-define! (resolve-module '~a) '~a ~a)
-"
-             music-sym str music-sym (module-name module) music-sym music-sym))
-  (eval `,music-sym module)))
+     (format #f "parseStringResult = { ~a }" str))
+
+    (ly:parser-lookup parser 'parseStringResult)))
 
 (define-public (read-lily-expression chr port)
   "Read a #{ lily music expression #} from port and return
@@ -35,11 +31,14 @@
 scheme forms, typically symbols. $$ may be used to simply write a `$'
 character."
   (let ((bindings '()))
+
     (define (create-binding! val)
       "Create a new symbol, bind it to `val' and return it."
       (let ((tmp-symbol (gen-lily-sym)))
+
         (set! bindings (cons (cons tmp-symbol val) bindings))
         tmp-symbol))
+    
     (define (remove-dollars! form)
       "Generate a form where `$variable' and `$ value' mottos are replaced
       by new symbols, which are binded to the adequate values."
@@ -56,7 +55,8 @@
              (cons (create-binding! (cadr form)) (remove-dollars! (cddr 
form))))
             (else ;; (something ...)
              (cons (remove-dollars! (car form)) (remove-dollars! (cdr 
form))))))
-    (let ((lily-string (call-with-output-string
+    (let*
+       ((lily-string (call-with-output-string
                         (lambda (out)
                           (do ((c (read-char port) (read-char port)))
                              ((and (char=? c #\#)
@@ -78,11 +78,19 @@
                                                      (remove-dollars! expr)))))
                             ;; other caracters
                             (else
-                             (display c out))))))))
-      `(let ((parser-clone (ly:clone-parser parser)))
-         ,@(map (lambda (binding)
-                  `(ly:parser-define parser-clone ',(car binding) ,(cdr 
binding)))
-                (reverse bindings))
-         (ly:parse-string-result ,lily-string parser-clone 
(current-module))))))
+                             (display c out)))))))
+
+         (result
+          `(let ((parser-clone (ly:clone-parser parser)))
+             ,@(map (lambda (binding)
+                      `(ly:parser-define parser-clone ',(car binding) ,(cdr 
binding)))
+                    (reverse bindings))
+             (ly:parse-string-result ,lily-string parser-clone))
+         ))
+
+      
+            
+      result
+      )))
 
 (read-hash-extend #\{ read-lily-expression)


_______________________________________________
Lilypond-cvs mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/lilypond-cvs

Reply via email to