]> git.donarmstrong.com Git - lilypond.git/commitdiff
Add new exported function: ly:parser-include-string.
authorBenjamin Peterson <benjamin@python.org>
Mon, 19 Jul 2010 22:50:34 +0000 (23:50 +0100)
committerNeil Puttock <n.puttock@gmail.com>
Mon, 19 Jul 2010 23:54:47 +0000 (00:54 +0100)
input/regression/include-string.ly [new file with mode: 0644]
lily/includable-lexer.cc
lily/include/includable-lexer.hh
lily/include/lily-parser.hh
lily/lexer.ll
lily/lily-parser-scheme.cc
lily/lily-parser.cc

diff --git a/input/regression/include-string.ly b/input/regression/include-string.ly
new file mode 100644 (file)
index 0000000..256cc5a
--- /dev/null
@@ -0,0 +1,8 @@
+\version "2.13.29"
+
+\header {
+  texidoc = "@code{ly:parser-include-string} should include the current
+string like a file @code{\include}."
+}
+
+#(ly:parser-include-string parser "\\relative c' { a4 b c d }")
index 2ddfdd38c0390ea60b8503059a7f95ecb0e5b5bd..8c78481316a1aa418ac2ccf5614e04883d341f9d 100644 (file)
@@ -121,6 +121,12 @@ Includable_lexer::new_input (string name, string data, Sources *sources)
   yy_switch_to_buffer (yy_create_buffer (file->get_istream (), YY_BUF_SIZE));
 }
 
+void
+Includable_lexer::add_string_include (string data)
+{
+  pending_string_includes_.push_back (data);
+}
+
 /** pop the inputstack.  conceptually this is a destructor, but it
     does not destruct the Source_file that Includable_lexer::new_input
     creates.  */
index 9df81461dbf1a352c16d5f74b90529ddb401a089..cad1e45d71bd3181ed2879e5c065193fa0e2d38f 100644 (file)
@@ -42,6 +42,7 @@ protected:
   bool close_input ();
   vector<Source_file*> include_stack_;
   vector<int> char_count_stack_;
+  vector<string> pending_string_includes_;
 
 public:
 
@@ -56,6 +57,7 @@ public:
   virtual void new_input (string s, Sources *);
   
   void new_input (string name, string data, Sources *);
+  void add_string_include (string data);
   
   char const *here_str0 () const;
 };
index a3f5667b74abb9a2f96a5f651227d6adfc19d14e..2961ffbb908b7dfd2dab8c53c26e63c860962547 100644 (file)
@@ -63,6 +63,7 @@ public:
   void clear ();
   void do_init_file ();
   void do_yyparse ();
+  void include_string (string ly_code);
   void parse_file (string init, string name, string out_name);
   void parse_string (string ly_code);
   void parser_error (string);
index aaa95d79807454ffccf058d6790563b622493574..5f4aa8ef6259d40436aace19684cc33a8ec0b2ea 100644 (file)
@@ -51,6 +51,7 @@ using namespace std;
 #include "interval.hh"
 #include "lily-guile.hh"
 #include "lily-lexer.hh"
+#include "lily-parser.hh"
 #include "lilypond-version.hh"
 #include "main.hh"
 #include "music.hh"
@@ -366,6 +367,11 @@ BOM_UTF8   \357\273\277
                yylval.scm = unpack_identifier(sval);
                return identifier_type (yylval.scm);
        }
+
+       for (size_t i = 0; i < pending_string_includes_.size (); i++)
+               new_input ("<included string>", pending_string_includes_[i],
+                          parser_->sources_);
+       pending_string_includes_.clear ();
                
        yylval.scm = sval;
        return SCM_TOKEN;
index a608111dcab2648bd814b3a63b31767b0ee1b0f5..2b968b46c00c124baef36f283771d31705c6784c 100644 (file)
@@ -205,6 +205,20 @@ LY_DEFINE (ly_parser_parse_string, "ly:parser-parse-string",
   return SCM_UNSPECIFIED;
 }
 
+LY_DEFINE (ly_parser_include_string, "ly:parser-include-string",
+          2, 0, 0, (SCM parser_smob, SCM ly_code),
+          "Include the string @var{ly-code} into the input stream"
+          " for @var{parser-smob}.")
+{
+  LY_ASSERT_SMOB (Lily_parser, parser_smob, 1);
+  Lily_parser *parser = unsmob_lily_parser (parser_smob);
+  LY_ASSERT_TYPE (scm_is_string, ly_code, 2);
+
+  parser->include_string (ly_scm2string (ly_code));
+
+  return SCM_UNSPECIFIED;
+}
+
 LY_DEFINE (ly_parser_set_note_names, "ly:parser-set-note-names",
           2, 0, 0, (SCM parser, SCM names),
           "Replace current note names in @var{parser}."
index 4d4b3ac33e609d8375c17b51bad8a4a86a49a14e..e0722fd9800fbc9167c27abaaece0151a6be709d 100644 (file)
@@ -164,6 +164,12 @@ Lily_parser::parse_string (string ly_code)
   error_level_ = error_level_ | lexer_->error_level_;
 }
 
+void
+Lily_parser::include_string (string ly_code)
+{
+  lexer_->add_string_include (ly_code);
+}
+
 void
 Lily_parser::clear ()
 {