]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/my-lily-lexer.cc
* lily/parser.yy (command_element): move clef stuff into Scheme.
[lilypond.git] / lily / my-lily-lexer.cc
index 48005225d18c895bc4f3bf781d24df77ab1a55cb..925cc607d8ff917f765c86e3e2e38ece97e6b9e7 100644 (file)
@@ -23,6 +23,8 @@
 #include "main.hh"
 #include "input.hh"
 #include "moment.hh"
+#include "ly-modules.hh"
+
 
 static Keyword_ent the_key_tab[]={
   {"alias", ALIAS},
@@ -94,16 +96,50 @@ static Keyword_ent the_key_tab[]={
   {0,0}
 };
 
+
 My_lily_lexer::My_lily_lexer ()
 {
   keytable_ = new Keyword_table (the_key_tab);
-  toplevel_variable_tab_ = new Scheme_hash_table ;
-  scopes_.push (toplevel_variable_tab_);
+  scopes_ = SCM_EOL;
   
-  errorlevel_ = 0;
+  add_scope(ly_make_anonymous_module());
+  errorlevel_ =0; 
+
   main_input_b_ = false;
 }
 
+void
+My_lily_lexer::add_scope (SCM module)
+{
+  ly_reexport_module (scm_current_module());
+  scm_set_current_module (module);
+  for (SCM s = scopes_; gh_pair_p (s); s = gh_cdr (s))
+    {
+      /*
+       UGH. how to do this more neatly? 
+      */      
+      SCM expr = scm_list_n (ly_symbol2scm ("module-use!"),
+                            module, scm_list_n (ly_symbol2scm ("module-public-interface"),
+                                                gh_car (s), SCM_UNDEFINED),
+                            SCM_UNDEFINED);
+      
+      scm_primitive_eval(expr);
+    }
+  
+  scopes_ = scm_cons (module, scopes_);
+}
+
+SCM
+My_lily_lexer::remove_scope ()
+{
+  SCM sc = gh_car (scopes_);
+  scopes_ = gh_cdr (scopes_);
+  scm_set_current_module (gh_car (scopes_));
+
+  return sc;
+}
+
+
 int
 My_lily_lexer::lookup_keyword (String s)
 {
@@ -113,14 +149,14 @@ My_lily_lexer::lookup_keyword (String s)
 SCM
 My_lily_lexer::lookup_identifier (String s)
 {
-  SCM sym = ly_symbol2scm (s.to_str0 ());
-  
-  for (int i = scopes_.size (); i--;)
+  SCM sym = ly_symbol2scm (s.to_str0());
+  for (SCM s = scopes_; gh_pair_p (s); s = gh_cdr (s))
     {
-      SCM val = SCM_UNSPECIFIED;
-      if (scopes_[i]->try_retrieve (sym, &val))
-       return val;
+      SCM var = ly_module_lookup (gh_car (s), sym);
+      if (var != SCM_BOOL_F)
+       return scm_variable_ref(var);
     }
+
   return SCM_UNSPECIFIED;
 }
 
@@ -143,14 +179,16 @@ My_lily_lexer::set_identifier (SCM name, SCM s)
       warning (_f ("Identifier name is a keyword: `%s'", str));
       free  (str);
     }
-  
-  scopes_.top ()->set (scm_string_to_symbol (name), s);
+
+  SCM sym = scm_string_to_symbol (name);
+  SCM mod = gh_car (scopes_);
+
+  scm_module_define (mod, sym, s);
 }
 
 My_lily_lexer::~My_lily_lexer ()
 {
   delete keytable_;
-  scm_gc_unprotect_object (toplevel_variable_tab_->self_scm ());
 }