From: David Kastrup Date: Wed, 31 Oct 2012 11:33:15 +0000 (+0100) Subject: Issue 2939: Fix relations between \maininput, EOF and safe mode X-Git-Tag: release/2.17.7-1~22 X-Git-Url: https://git.donarmstrong.com/?p=lilypond.git;a=commitdiff_plain;h=a68e2f12c41ddbf91bbea15f345d0eb37bd87e69 Issue 2939: Fix relations between \maininput, EOF and safe mode 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. --- diff --git a/lily/include/lily-lexer.hh b/lily/include/lily-lexer.hh index 4c5f9268c2..8da2807266 100644 --- a/lily/include/lily-lexer.hh +++ b/lily/include/lily-lexer.hh @@ -57,6 +57,7 @@ public: SCM *lexval_; Input *lexloc_; bool is_main_input_; + vsize main_input_level_; Sources *sources_; diff --git a/lily/lexer.ll b/lily/lexer.ll index 9e4941674a..e74dced088 100644 --- a/lily/lexer.ll +++ b/lily/lexer.ll @@ -309,9 +309,10 @@ BOM_UTF8 \357\273\277 \\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 (); diff --git a/lily/lily-lexer.cc b/lily/lily-lexer.cc index 39aeb78dd1..c529da7c43 100644 --- a/lily/lily-lexer.cc +++ b/lily/lily-lexer.cc @@ -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;