]> git.donarmstrong.com Git - lilypond.git/commitdiff
Allow --safe testing as a snippet.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Tue, 2 Jan 2007 21:49:12 +0000 (22:49 +0100)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Tue, 2 Jan 2007 21:49:12 +0000 (22:49 +0100)
Add ly:lexer-set-safe!, which sets safety for the rest of the file.

input/no-notation/README [deleted file]
input/no-notation/safe-guile.ly [deleted file]
input/no-notation/safe-include.ly [deleted file]
input/no-notation/safe.ly [new file with mode: 0644]
lily/include/lily-lexer.hh
lily/include/lily-parser.hh
lily/lexer.ll
lily/lily-lexer-scheme.cc
lily/lily-parser.cc
ly/init.ly

diff --git a/input/no-notation/README b/input/no-notation/README
deleted file mode 100644 (file)
index d162aad..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-These examples test various non-typesetting things. Since they 
-do not generate output, they are not in test/ or regression/
-
-Some (notably parse*.ly) are just error/warning generation tests
-and should remain here.
-
-Some (notably midi-*.ly) test midi output, which does not usually
-get tested in ../regression files.
-
diff --git a/input/no-notation/safe-guile.ly b/input/no-notation/safe-guile.ly
deleted file mode 100644 (file)
index eeaf1f2..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-\version "2.10.0"
-
-\header{
-    
-    texidoc = "This should not survive lilypond --safe-mode, and
-    certainly not write /tmp/safe-guile.scm"
-    
-}
-
-#(write "hallo" (open-file "/tmp/safe-guile.scm" "w"))
-
-\score{
-     c''
-}
\ No newline at end of file
diff --git a/input/no-notation/safe-include.ly b/input/no-notation/safe-include.ly
deleted file mode 100644 (file)
index aa26b22..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-\version "2.10.0"
-
-\header{
-    
-    texidoc = "This should not survive lilypond --safe-mode"
-    
-}
-
-\include "safe-ps.ly"
-
-\score{
-     c''
-}
\ No newline at end of file
diff --git a/input/no-notation/safe.ly b/input/no-notation/safe.ly
new file mode 100644 (file)
index 0000000..88d54bd
--- /dev/null
@@ -0,0 +1,19 @@
+\version "2.10.0"
+
+"expect-error" = ##t
+
+#(ly:lexer-set-safe! (ly:parser-lexer parser))
+
+"force-finish" = ##t  
+
+\header{
+    texidoc = "This should not survive lilypond --safe-mode"
+
+    #(open-file "w")
+}
+
+
+#(open-file "/tmp/safe-guile.scm" "r")
+
+\include "this-should-fail.ly"
+
index 994d185f6f36a9b9ff07239e4912443054a44bd4..e8a9c998d162591000e8f7612160314865b730e0 100644 (file)
@@ -42,6 +42,7 @@ public:
   void *lexval;
   Input *lexloc;
   bool is_main_input_;
+  bool be_safe_;
   
   Sources *sources_;
 
index b07734769a1b747a29cf55ceb1cb2ded2d50cb06..3acfd8a59683d1aaf777d8d1ce9ce041f801fc3e 100644 (file)
@@ -57,6 +57,8 @@ public:
   void parser_error (string);
   void parser_error (Input const &, string);
   void set_yydebug (bool);
+
+  SCM make_scope () const; 
 };
 
 DECLARE_UNSMOB (Lily_parser, lily_parser);
index 9cb2cac0c667baae3b1f24a893ab34acaaf3032b..d20b075eb40ffaa292886d88144f1eaa1280f123 100644 (file)
@@ -271,7 +271,7 @@ BOM_UTF8    \357\273\277
        }
        <<EOF>>         {
                LexerError (_ ("EOF found inside a comment").c_str ());
-               is_main_input_ = false;
+               is_main_input_ = false; // should be safe , can't have \include in --safe.
                if (! close_input ()) 
                  yyterminate (); // can't move this, since it actually rets a YY_NULL
        }
@@ -334,7 +334,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_ && is_main_input_);
 
        if (sval == SCM_UNDEFINED)
        {
index 66e47d3d6b5e56b53253b0cd963e3f468f5ab895..424b4fa816adb3227493709edcaf12c8146b7673 100644 (file)
@@ -10,7 +10,7 @@
 #include "lily-lexer.hh"
 
 LY_DEFINE(ly_lexer_keywords, "ly:lexer-keywords",
-         1,0,0, (SCM lexer),
+         1, 0, 0, (SCM lexer),
          "Return a list of (KEY . CODE) pairs, signifying the lilypond reserved words list.")
 {
   Lily_lexer * lex = Lily_lexer::unsmob (lexer);
@@ -18,3 +18,16 @@ LY_DEFINE(ly_lexer_keywords, "ly:lexer-keywords",
   return lex->keyword_list ();
 }
          
+
+LY_DEFINE(ly_lexer_set_safe, "ly:lexer-set-safe!",
+         1, 0, 0, (SCM lexer),
+         "Switch on safe mode for the rest of the file.")
+{
+  Lily_lexer * lex = Lily_lexer::unsmob (lexer);
+  SCM_ASSERT_TYPE(lex, lexer, SCM_ARG1, __FUNCTION__, "lily lexer");
+
+  lex->be_safe_ = true;
+  lex->allow_includes_ = false;
+  
+  return SCM_UNSPECIFIED;
+}
index ae3943dbdb3e89061ba30ee53600b43215ad9123..708b10659db433339a8033b13ff556da7f5daaba 100644 (file)
@@ -140,8 +140,7 @@ Lily_parser::parse_string (string ly_code)
                          self_scm ());
 
   lexer_->main_input_name_ = "<string>";
-  lexer_->is_main_input_ = true;
-
+  lexer_->is_main_input_ = true; 
   lexer_->new_input (lexer_->main_input_name_, ly_code, sources_);
 
   SCM mod = lexer_->set_current_scope ();
@@ -241,13 +240,19 @@ get_header (Lily_parser *parser)
 {
   SCM id = parser->lexer_->lookup_identifier ("$defaultheader");
   if (!ly_is_module (id))
-    id = ly_make_anonymous_module (be_safe_global);
+    id = parser->make_scope ();
   else
     {
-      SCM nid = ly_make_anonymous_module (false);
-      ly_module_copy(nid,id);
+      SCM nid = parser->make_scope ();
+      ly_module_copy (nid, id);
       id = nid;
     }
   
   return id;
 }
+
+SCM 
+Lily_parser::make_scope () const
+{
+  return ly_make_anonymous_module (lexer_->be_safe_);
+}
index 102233c5a4332d8ed6d3edf4e860abe3899d0416..091ae681949b403568838ad94af089a4bca5ca61 100644 (file)
@@ -4,11 +4,6 @@
 #(if (and #t (defined? 'set-debug-cell-accesses!))
   (set-debug-cell-accesses! 5000))
 
-#(define-public midi-debug  #f)
-
-
-
-
 \version "2.10.0"
 
 \include "declarations-init.ly"