]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 2939: Fix relations between \maininput, EOF and safe mode
authorDavid Kastrup <dak@gnu.org>
Wed, 31 Oct 2012 11:33:15 +0000 (12:33 +0100)
committerDavid Kastrup <dak@gnu.org>
Mon, 5 Nov 2012 13:56:47 +0000 (14:56 +0100)
In lexer.ll, assumptions about the depth of include_stack_ were hardwired
that only were valid for parsers started from the normal chain of input.

One consequence was that something like

    #{ \book { \include "line-arrows.ly" } #}

worked even in safe mode (where \include should be prohibited) but
might complain about unexpected EOF.  This commit adds a member
variable main_input_level to Lily_lexer for keeping track of when to
drop restrictions and deliver EOF in each parser separately.

lily/include/lily-lexer.hh
lily/lexer.ll
lily/lily-lexer.cc

index 4c5f9268c249b60dd7d1ca97f837ee4ab08a2e3a..8da28072660aebb6b30aebc0063ba5e46f63f864 100644 (file)
@@ -57,6 +57,7 @@ public:
   SCM *lexval_;
   Input *lexloc_;
   bool is_main_input_;
+  vsize main_input_level_;
 
   Sources *sources_;
 
index 9e4941674a8339614866d2f4e214b2cf1a5f2f3a..e74dced0885534a2bee9ad22115dec42d60b4ef5 100644 (file)
@@ -309,9 +309,10 @@ BOM_UTF8   \357\273\277
 
 
 <INITIAL,chords,lyrics,notes,figures>\\maininput           {
-       if (!is_main_input_ && include_stack_.size () == 1)
+       if (!is_main_input_)
        {
                start_main_input ();
+               main_input_level_ = include_stack_.size ();
                is_main_input_ = true;
        }
        else
@@ -698,11 +699,9 @@ BOM_UTF8   \357\273\277
         yylval = SCM_UNSPECIFIED;
         if (is_main_input_)
        {
-               /* 2 = init.ly + current file.
-                  > because we're before closing, but is_main_input_ should
-                  reflect after.
-               */ 
-               is_main_input_ = include_stack_.size () > 2;
+               is_main_input_ = include_stack_.size () > main_input_level_;
+               if (!is_main_input_)
+                       main_input_level_ = 0;
                if (!close_input () || !is_main_input_)
                /* Returns YY_NULL */
                        yyterminate ();
index 39aeb78dd14c0fe9cd9bce93f50cb365f748e5c3..c529da7c43a1efaa97d41b1ec336185b44358ccc 100644 (file)
@@ -96,6 +96,7 @@ Lily_lexer::Lily_lexer (Sources *sources, Lily_parser *parser)
   scopes_ = SCM_EOL;
   error_level_ = 0;
   is_main_input_ = false;
+  main_input_level_ = 0;
   start_module_ = SCM_EOL;
   extra_tokens_ = SCM_EOL;
   smobify_self ();
@@ -118,6 +119,7 @@ Lily_lexer::Lily_lexer (Lily_lexer const &src, Lily_parser *parser)
 
   error_level_ = 0;
   is_main_input_ = src.is_main_input_;
+  main_input_level_ = 0;
 
   extra_tokens_ = SCM_EOL;