]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/my-lily-parser.cc:
authorJan Nieuwenhuizen <janneke@gnu.org>
Sun, 25 Apr 2004 09:55:27 +0000 (09:55 +0000)
committerJan Nieuwenhuizen <janneke@gnu.org>
Sun, 25 Apr 2004 09:55:27 +0000 (09:55 +0000)
* lily/my-lily-lexer.cc: Another step towards parsing ly code from
SCM string (foo.ly/toto.scm support).

ChangeLog
lily/include/my-lily-lexer.hh
lily/include/my-lily-parser.hh
lily/my-lily-lexer.cc
lily/my-lily-parser.cc

index c4bb55353851762285188283e33ffe95f2f54d37..1361b594f27d4a45311fa9cf445d39b543208909 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2004-04-25  Jan Nieuwenhuizen  <janneke@gnu.org>
+
+       * lily/my-lily-parser.cc:
+       * lily/my-lily-lexer.cc: Another step towards parsing ly code from
+       SCM string (foo.ly/toto.scm support).
+
 2004-04-24  Jan Nieuwenhuizen  <janneke@gnu.org>
 
        * lily/my-lily-parser.cc (ly:parser-parse-string): New function.
index 62f7693bb83b39d29d4908f321d56ceb1c8f0123..44f3966fc01a14e48ad42a6462528dd7e74cdd84 100644 (file)
@@ -6,8 +6,8 @@
   (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
-#ifndef LEXER_HH
-#define LEXER_HH
+#ifndef MY_LILY_LEXER_HH
+#define MY_LILY_LEXER_HH
 
 #include "includable-lexer.hh"
 
@@ -26,29 +26,39 @@ void set_lexer ();
 
 class My_lily_lexer : public Includable_lexer 
 {
+public:
   Protected_scm scopes_;
   Protected_scm encoding_;
+  
+private:
+  int lookup_keyword (String);
+  int scan_bare_word (String);
+  SCM scan_markup_word (String);
+  int scan_escaped_word (String);
+  int identifier_type (SCM);
+  char escaped_char (char) const;
+
 public:
   String main_input_name_;
   void *lexval;
   bool main_input_b_;
   
-  Sources * sources_; 
+  Sources *sources_; 
 
-  /*
-   Scheme hash tables with (oct name acc)  values, and symbol keys
-   */
+  /* Scheme hash tables with (oct name acc)  values, and symbol keys.  */
   Protected_scm chordmodifier_tab_;
   Protected_scm pitchname_tab_stack_;
 
-  Keyword_table * keytable_;
+  Keyword_table *keytable_;
   int error_level_;
+  Input last_input_;
 
   My_lily_lexer (Sources*);
+  My_lily_lexer (My_lily_lexer const&);
   ~My_lily_lexer ();
+
   int yylex ();
 
-  Input last_input_;
   void prepare_for_next_token ();
   int try_special_identifiers (SCM* ,SCM);
   Input here_input () const;
@@ -74,13 +84,6 @@ public:
   bool is_chord_state () const;
   bool is_lyric_state () const;
   bool is_figure_state () const;
-private:
-  int lookup_keyword (String);
-  int scan_bare_word (String);
-  SCM scan_markup_word (String);
-  int scan_escaped_word (String);
-  int identifier_type (SCM);
-  char escaped_char (char) const;
 };
 
-#endif
+#endif /* MY_LILY_LEXER_HH */
index 58afacb25786ae5d6c93d8ad1b420381ef5d5b49..2742ec7530e8752a69c48f90ba0b0a1ecb224a03 100644 (file)
@@ -53,6 +53,7 @@ public:
   SCM last_beam_start_;
 
   My_lily_parser (Sources *sources);
+  My_lily_parser (My_lily_parser const&);
 
   DECLARE_SCHEME_CALLBACK (paper_description, ());
   
index 44ab32fcd37f52fb2fffdbec9c49bd2d03b10bde..51fda8586adf5e00c6da56a8d18b633a2dc25e6a 100644 (file)
@@ -93,19 +93,33 @@ static Keyword_ent the_key_tab[] = {
 };
 
 
-My_lily_lexer::My_lily_lexer (Sources *srcs)
+My_lily_lexer::My_lily_lexer (Sources *sources)
+  
 {
   keytable_ = new Keyword_table (the_key_tab);
   encoding_ = SCM_EOL;
   chordmodifier_tab_ = scm_make_vector (scm_int2num (1), SCM_EOL);
   pitchname_tab_stack_ = SCM_EOL; 
-  sources_ = srcs;
+  sources_ = sources;
   scopes_ = SCM_EOL;
+  error_level_ = 0; 
+  main_input_b_ = false;
   
   add_scope (ly_make_anonymous_module ());
-  error_level_ = 0; 
+}
 
-  main_input_b_ = false;
+My_lily_lexer::My_lily_lexer (My_lily_lexer const &src)
+  : Includable_lexer ()
+{
+  keytable_ = src.keytable_;
+  encoding_ = src.encoding_;
+  chordmodifier_tab_ = src.chordmodifier_tab_;
+  pitchname_tab_stack_ = src.pitchname_tab_stack_;
+  sources_ = src.sources_;
+  scopes_ = src.scopes_;
+  error_level_ = src.error_level_; 
+  //  main_input_b_ = false;
+  main_input_b_ = src.main_input_b_;
 }
 
 SCM
index 5148a238d14bf190d2be13f6d819fbcd6fd9d9fd..c34351f65de66d253ff4a358c890b1751c8ba044 100644 (file)
@@ -39,6 +39,20 @@ My_lily_parser::My_lily_parser (Sources *sources)
   smobify_self ();
 }
 
+My_lily_parser::My_lily_parser (My_lily_parser const &src)
+{
+  book_count_ = src.book_count_;
+  score_count_ = src.score_count_;
+  lexer_ = src.lexer_;
+  sources_ = src.sources_;
+  default_duration_ = src.default_duration_;
+  error_level_ = src.error_level_;
+  last_beam_start_ = src.last_beam_start_;
+  header_ = src.header_;
+
+  smobify_self ();
+}
+
 My_lily_parser::~My_lily_parser ()
 {
   delete lexer_;
@@ -97,7 +111,10 @@ My_lily_parser::parse_file (String init, String name, String out_name)
 void
 My_lily_parser::parse_string (String ly_code)
 {
-  lexer_ = new My_lily_lexer (sources_);
+  My_lily_lexer *parent = lexer_;
+  lexer_ = (parent == 0 ? new My_lily_lexer (sources_)
+           : new My_lily_lexer (*parent));
+
   lexer_->main_input_name_ = "<string>";
   lexer_->main_input_b_ = true;
 
@@ -112,6 +129,18 @@ My_lily_parser::parse_string (String ly_code)
     }
 
   error_level_ = error_level_ | lexer_->error_level_;
+
+  if (parent != 0)
+    {
+      parent->keytable_ = lexer_->keytable_;
+      parent->encoding_ = lexer_->encoding_;
+      parent->chordmodifier_tab_ = lexer_->chordmodifier_tab_;
+      parent->pitchname_tab_stack_ = lexer_->pitchname_tab_stack_;
+      parent->sources_ = lexer_->sources_;
+      parent->scopes_ = lexer_->scopes_;
+      parent->error_level_ = lexer_->error_level_; 
+      parent->main_input_b_ = lexer_->main_input_b_;
+    }
 }
 
 void
@@ -133,8 +162,6 @@ My_lily_parser::parser_error (String s)
   error_level_ = 1;
 }
 
-
-
 Input
 My_lily_parser::pop_spot ()
 {
@@ -323,12 +350,15 @@ LY_DEFINE (ly_parser_parse_string, "ly:parser-parse-string",
 #endif
   SCM_ASSERT_TYPE (ly_c_string_p (ly_code), ly_code, SCM_ARG1, __FUNCTION__, "string");
 
-#if 1
+#if 0
   My_lily_parser *parser = unsmob_my_lily_parser (parser_smob);
+  parser->parse_string (ly_scm2string (ly_code));
 #else
-  /* New parser, copy vars but no state?  */
+  My_lily_parser *parser = unsmob_my_lily_parser (parser_smob);
+  My_lily_parser *clone = new My_lily_parser (*parser);
+  clone->parse_string (ly_scm2string (ly_code));
+  clone = 0;
 #endif
-  parser->parse_string (ly_scm2string (ly_code));
   
   return SCM_UNSPECIFIED;
 }