]> git.donarmstrong.com Git - lilypond.git/commitdiff
Permit ly:parser-clone to receive an environment
authorDavid Kastrup <dak@gnu.org>
Sun, 6 Nov 2011 18:13:50 +0000 (19:13 +0100)
committerDavid Kastrup <dak@gnu.org>
Thu, 10 Nov 2011 20:15:47 +0000 (21:15 +0100)
lily/include/lily-parser.hh
lily/lily-parser-scheme.cc
lily/lily-parser.cc
lily/parse-scm.cc

index 9839d38f4d04e4e2d859172ba44f999a178bba87..a98c760712cb6914f2a2c7b5ed36ddcbf3c272ec 100644 (file)
@@ -50,13 +50,14 @@ public:
   Sources *sources_;
   Duration default_duration_;
   string output_basename_;
+  SCM local_environment_;
 
   int fatal_error_;
   int error_level_;
   bool ignore_version_b_;
 
   Lily_parser (Sources *sources);
-  Lily_parser (Lily_parser const &);
+  Lily_parser (Lily_parser const &, SCM env = SCM_UNDEFINED);
 
   DECLARE_SCHEME_CALLBACK (layout_description, ());
 
index a5a4e6858f98b6cee46a566398d82cd9520d9a92..50f02051b2cb70fdd2a1604e67754a0108464d91 100644 (file)
@@ -146,12 +146,12 @@ LY_DEFINE (ly_parser_lexer, "ly:parser-lexer",
 }
 
 LY_DEFINE (ly_parser_clone, "ly:parser-clone",
-           1, 0, 0, (SCM parser_smob),
+           1, 1, 0, (SCM parser_smob, SCM local_environment),
            "Return a clone of @var{parser-smob}.")
 {
   LY_ASSERT_SMOB (Lily_parser, parser_smob, 1);
   Lily_parser *parser = unsmob_lily_parser (parser_smob);
-  Lily_parser *clone = new Lily_parser (*parser);
+  Lily_parser *clone = new Lily_parser (*parser, local_environment);
 
   return clone->unprotect ();
 }
index 12646bb3b450e3c6a65313b52a520fc36b4dfe41..d9af8cbb7e43126bc8a8a51c288907532935a1bc 100644 (file)
@@ -44,6 +44,7 @@ Lily_parser::Lily_parser (Sources *sources)
   sources_ = sources;
   default_duration_ = Duration (2, 0);
   error_level_ = 0;
+  local_environment_ = SCM_UNDEFINED;
 
   smobify_self ();
 
@@ -51,13 +52,14 @@ Lily_parser::Lily_parser (Sources *sources)
   lexer_->unprotect ();
 }
 
-Lily_parser::Lily_parser (Lily_parser const &src)
+Lily_parser::Lily_parser (Lily_parser const &src, SCM env)
 {
   lexer_ = 0;
   sources_ = src.sources_;
   default_duration_ = src.default_duration_;
   error_level_ = src.error_level_;
   output_basename_ = src.output_basename_;
+  local_environment_ = env;
 
   smobify_self ();
   if (src.lexer_)
@@ -76,6 +78,7 @@ SCM
 Lily_parser::mark_smob (SCM s)
 {
   Lily_parser *parser = (Lily_parser *) SCM_CELL_WORD_1 (s);
+  scm_gc_mark (parser->local_environment_);
   return (parser->lexer_) ? parser->lexer_->self_scm () : SCM_EOL;
 }
 
index f5092675b3cc124fc730f7e90f00861dfea44b62..0905a8b17ec5fd5320578b973d7796640a36ef56 100644 (file)
@@ -55,7 +55,9 @@ internal_ly_parse_scm (Parse_start *ps)
   /* Read expression from port.  */
   if (!SCM_EOF_OBJECT_P (form))
     {
-      if (ps->safe_)
+      if (ps->parser_ && !SCM_UNBNDP (ps->parser_->local_environment_))
+       answer = scm_local_eval (form, ps->parser_->local_environment_);
+      else if (ps->safe_)
         {
           static SCM module = SCM_BOOL_F;
           if (module == SCM_BOOL_F)