From cf8be9ab0b6c3bd56fe17f001ee74e3c9c774031 Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Mon, 14 Nov 2011 10:28:56 +0100 Subject: [PATCH] lexer.ll: Allow include file names to be specified as Scheme expression --- lily/lexer.ll | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/lily/lexer.ll b/lily/lexer.ll index 1a79dbdec8..32fa5f2b68 100644 --- a/lily/lexer.ll +++ b/lily/lexer.ll @@ -311,7 +311,7 @@ BOM_UTF8 \357\273\277 \\include { yy_push_state (incl); } -\"[^"]*\" { /* got the include file name */ +\"[^""]*\" { /* got the include file name */ string s (YYText ()+1); s = s.substr (0, s.rfind ('"')); @@ -328,7 +328,7 @@ BOM_UTF8 \357\273\277 if (scm_is_string (sid)) { new_input (ly_scm2string (sid), sources_); yy_pop_state (); - } else { + } else { string msg (_f ("wrong or undefined identifier: `%s'", s )); LexerError (msg.c_str ()); @@ -337,7 +337,34 @@ BOM_UTF8 \357\273\277 scm_display (sid, err); } } -\"[^"]* { // backup rule +(\$|#) { // scm for the filename + int n = 0; + Input hi = here_input(); + hi.step_forward (); + SCM sval = ly_parse_scm (hi.start (), &n, hi, + be_safe_global && is_main_input_, parser_); + sval = eval_scm (sval); + + for (int i = 0; i < n; i++) + { + yyinput (); + } + char_count_stack_.back () += n; + + if (scm_is_string (sval)) { + new_input (ly_scm2string (sval), sources_); + yy_pop_state (); + } else { + LexerError (_ ("string expected after \\include").c_str ()); + if (sval != SCM_UNDEFINED) { + SCM err = scm_current_error_port (); + scm_puts ("This value was found instead: ", err); + scm_display (sval, err); + } + } +} + +\"[^""]* { // backup rule error (_ ("end quote missing")); exit (1); } -- 2.39.5