]> git.donarmstrong.com Git - lilypond.git/commitdiff
Fix #268.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Thu, 29 May 2008 02:44:39 +0000 (23:44 -0300)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Thu, 29 May 2008 02:44:39 +0000 (23:44 -0300)
Define 'parser in anonymous modules, so trusted functions (that have
access to ly:parser-XXX functions) can access the toplevel module.

lily/include/parse-scm.hh
lily/lexer.ll
lily/lily-parser.cc
lily/parse-scm.cc
scm/paper.scm

index 2939bc2f5c228702476732a828343257e8c586c9..3e3f956634528b336abf93aba06db95d881f01a8 100644 (file)
@@ -21,10 +21,18 @@ struct Parse_start
   int nchars;
   Input start_location_;
   bool safe_;
+  Lily_parser *parser_;
+
+  Parse_start() {
+    str = 0;
+    nchars = 0;
+    safe_ = false;
+    parser_ = 0;
+  }     
 };
 
 SCM catch_protected_parse_body (void *);
 SCM protected_ly_parse_scm (Parse_start *, bool);
-SCM ly_parse_scm (char const *, int *, Input, bool);
+SCM ly_parse_scm (char const *, int *, Input, bool, Lily_parser *);
 
 #endif /* PARSE_SCM_HH */
index b444704ea5890bd5b26d26d335a66a4c6a55baa2..bec065347b56aa3b055688b69d02e14c5c614986 100644 (file)
@@ -337,7 +337,7 @@ BOM_UTF8    \357\273\277
        Input hi = here_input();
        hi.step_forward ();
        SCM sval = ly_parse_scm (hi.start (), &n, hi,
-               be_safe_global && is_main_input_);
+               be_safe_global && is_main_input_, parser_);
 
        if (sval == SCM_UNDEFINED)
        {
index b508860efa2acd19c93dba40c2d338fe39a9de48..13d62ebc5c762eb68873bace69250e14687026dd 100644 (file)
@@ -15,6 +15,7 @@
 #include "international.hh"
 #include "lily-lexer.hh"
 #include "lily-version.hh"
+#include "ly-module.hh"
 #include "main.hh"
 #include "output-def.hh"
 #include "paper-book.hh"
@@ -250,5 +251,6 @@ get_header (Lily_parser *parser)
 SCM 
 Lily_parser::make_scope () const
 {
-  return ly_make_anonymous_module (be_safe_global);
+  SCM module = ly_make_anonymous_module (be_safe_global);
+  return module;    
 }
index 51acd6e6ca658793d5b41e2f146bad608d45bd6e..087d2e5951e09940c5aa9fecd947c0111ed6911e 100644 (file)
@@ -11,6 +11,7 @@
 #include <cstdio>
 using namespace std;
 
+#include "lily-parser.hh"
 #include "international.hh"
 #include "main.hh"
 #include "paper-book.hh"
@@ -37,7 +38,6 @@ internal_ly_parse_scm (Parse_start *ps)
   SCM answer = SCM_UNSPECIFIED;
   SCM form = scm_read (port);
 
-
   /* Reset read_buf for scm_ftell.
      Shouldn't scm_read () do this for us?  */
   scm_fill_input (port);
@@ -56,6 +56,12 @@ internal_ly_parse_scm (Parse_start *ps)
              SCM function = ly_lily_module_constant ("make-safe-lilypond-module");
              module = scm_call_0 (function);
            }
+         
+         // We define the parser so trusted Scheme functions can
+         // access the real namespace underlying the parser.
+         if (ps->parser_)
+           scm_module_define (module, ly_symbol2scm ("parser"),
+                              ps->parser_->self_scm());
          answer = scm_eval (form, module);
        }
       else
@@ -113,12 +119,13 @@ bool parsed_objects_should_be_dead = false;
 /* Try parsing.  Upon failure return SCM_UNDEFINED.
    FIXME: shouldn't we return SCM_UNSCPECIFIED -- jcn  */
 SCM
-ly_parse_scm (char const *s, int *n, Input i, bool safe)
+ly_parse_scm (char const *s, int *n, Input i, bool safe, Lily_parser *parser)
 {
   Parse_start ps;
   ps.str = s;
   ps.start_location_ = i;
   ps.safe_ = safe;
+  ps.parser_ = parser;
 
   SCM ans = parse_protect_global ? protected_ly_parse_scm (&ps)
     : internal_ly_parse_scm (&ps);
index 8c2b5dc71025a7e18fe5deef9dd5c866e8ff560a..8acf4e8d1049f391e88203219d34be54065c8fd1 100644 (file)
@@ -70,7 +70,8 @@ size. SZ is in points"
 (define-safe-public (set-global-staff-size sz)
   "Set the default staff size, where SZ is thought to be in PT."
   (let* ((current-mod (current-module))
-        (pap (eval '$defaultpaper current-mod))
+        (parser (eval 'parser current-mod))
+        (pap (ly:parser-lookup parser '$defaultpaper))
         (in-layout? (or (module-defined? current-mod 'is-paper)
                         (module-defined? current-mod 'is-layout)))