]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/lily-parser-scheme.cc
Merge branch 'jneeman' of git+ssh://jneem@git.sv.gnu.org/srv/git/lilypond into jneeman
[lilypond.git] / lily / lily-parser-scheme.cc
index 2521f4e0391d634ccd658b4f396366be678354d0..83c3826dbdf7bf625f4becc951695b18e19a2d01 100644 (file)
@@ -11,7 +11,6 @@
 #include "file-name-map.hh"
 #include "file-name.hh"
 #include "file-path.hh"
-#include "input-smob.hh"
 #include "international.hh"
 #include "lily-lexer.hh"
 #include "lily-parser.hh"
@@ -37,7 +36,7 @@ LY_DEFINE (ly_parse_file, "ly:parse-file",
           "Upon failure, throw @code{ly-file-failed} key.")
 {
   SCM_ASSERT_TYPE (scm_is_string (name), name, SCM_ARG1, __FUNCTION__, "string");
-  char const *file = scm_i_string_chars (name);
+  string file = ly_scm2string (name);
   char const *extensions[] = {"ly", "", 0};
 
   string file_name = global_path.find (file, extensions);
@@ -65,6 +64,7 @@ LY_DEFINE (ly_parse_file, "ly:parse-file",
 
   if (!output_name_global.empty ())
     {
+      
       /* Interpret --output=DIR to mean --output=DIR/BASE.  */
       string dir;
       if (is_dir (output_name_global))
@@ -73,7 +73,15 @@ LY_DEFINE (ly_parse_file, "ly:parse-file",
          output_name_global = "";
        }
       else
-       dir = dir_name (output_name_global);
+       {
+         File_name out (output_name_global);
+         if (is_dir (out.dir_part ()))
+           {
+             dir = out.dir_part ();
+             out_file_name = out.file_part ();
+           }
+       }         
+
       if (dir != "" && dir != "." && dir != get_working_directory ())
        {
          global_path.prepend (get_working_directory ());
@@ -101,11 +109,12 @@ LY_DEFINE (ly_parse_file, "ly:parse-file",
       exit (2);
     }
 
-  if ((file_name != "-") && global_path.find (file_name).empty ())
+
+  bool error = false;
+  if ((file_name != "-") && file_name.empty ())
     {
-      warning (_f ("can't find file: `%s'", file_name));
-      scm_throw (ly_symbol2scm ("ly-file-failed"),
-                scm_list_1 (scm_makfrom0str (file_name.c_str ())));
+      warning (_f ("can't find file: `%s'", file));
+      error = true;
     }
   else
     {
@@ -120,14 +129,20 @@ LY_DEFINE (ly_parse_file, "ly:parse-file",
 
       parser->parse_file (init, file_name, out_file);
 
-      bool error = parser->error_level_;
+      error = parser->error_level_;
+
+      parser->clear ();
       parser->unprotect ();
-      parser = 0;
-      if (error)
-       /* TODO: pass renamed input file too.  */
-       scm_throw (ly_symbol2scm ("ly-file-failed"),
-                  scm_list_1 (scm_makfrom0str (file_name.c_str ())));
     }
+
+  /*
+    outside the if-else to ensure cleanup fo Sources object, 
+   */
+  if (error)
+    /* TODO: pass renamed input file too.  */
+    scm_throw (ly_symbol2scm ("ly-file-failed"),
+              scm_list_1 (scm_makfrom0str (file_name.c_str ())));
+  
   return SCM_UNSPECIFIED;
 }
 
@@ -148,7 +163,15 @@ LY_DEFINE (ly_parse_string, "ly:parse-string",
   return SCM_UNSPECIFIED;
 }
 
-LY_DEFINE (ly_clone_parser, "ly:clone-parser",
+LY_DEFINE (ly_parser_lexer, "ly:parser-lexer",
+          1, 0, 0, (SCM parser_smob),
+          "Return the lexer for PARSER_SMOB.")
+{
+  Lily_parser *parser = unsmob_lily_parser (parser_smob);
+  return parser->lexer_->self_scm ();
+}
+
+LY_DEFINE (ly_parser_clone, "ly:parser-clone",
           1, 0, 0, (SCM parser_smob),
           "Return a clone of PARSER_SMOB.")
 {