2 my-lily-lexer.cc -- implement My_lily_lexer
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
12 #include "lily-proto.hh"
13 #include "scm-hash.hh"
14 #include "interval.hh"
15 #include "input-file-results.hh"
16 #include "lily-guile.hh"
19 #include "my-lily-lexer.hh"
21 #include "source-file.hh"
25 #include "ly-modules.hh"
28 static Keyword_ent the_key_tab[]={
31 {"autochange", AUTOCHANGE},
32 {"simultaneous", SIMULTANEOUS},
33 {"sequential", SEQUENTIAL},
35 {"alternative", ALTERNATIVE},
38 {"chordmodifiers", CHORDMODIFIERS},
41 {"consists", CONSISTS},
42 {"consistsend", CONSISTSEND},
46 {"duration", DURATION},
47 {"grobdescriptions", GROBDESCRIPTIONS},
60 {"pitchnames", PITCHNAMES},
62 {"outputproperty", OUTPUTPROPERTY},
63 {"override", OVERRIDE},
69 {"property", PROPERTY},
70 {"relative", RELATIVE},
73 {"addlyrics", ADDLYRICS},
74 {"partcombine", PARTCOMBINE},
78 {"translator", TRANSLATOR},
79 {"transpose", TRANSPOSE},
86 My_lily_lexer::My_lily_lexer ()
88 keytable_ = new Keyword_table (the_key_tab);
91 add_scope(ly_make_anonymous_module());
94 main_input_b_ = false;
98 My_lily_lexer::add_scope (SCM module)
100 ly_reexport_module (scm_current_module());
101 scm_set_current_module (module);
102 for (SCM s = scopes_; gh_pair_p (s); s = gh_cdr (s))
105 UGH. how to do this more neatly?
107 SCM expr = scm_list_n (ly_symbol2scm ("module-use!"),
108 module, scm_list_n (ly_symbol2scm ("module-public-interface"),
109 gh_car (s), SCM_UNDEFINED),
112 scm_primitive_eval(expr);
115 scopes_ = scm_cons (module, scopes_);
119 My_lily_lexer::remove_scope ()
121 SCM sc = gh_car (scopes_);
122 scopes_ = gh_cdr (scopes_);
123 scm_set_current_module (gh_car (scopes_));
130 My_lily_lexer::lookup_keyword (String s)
132 return keytable_->lookup (s.to_str0 ());
136 My_lily_lexer::lookup_identifier (String s)
138 SCM sym = ly_symbol2scm (s.to_str0());
139 for (SCM s = scopes_; gh_pair_p (s); s = gh_cdr (s))
141 SCM var = ly_module_lookup (gh_car (s), sym);
142 if (var != SCM_BOOL_F)
143 return scm_variable_ref(var);
146 return SCM_UNSPECIFIED;
150 My_lily_lexer::start_main_input ()
152 new_input (main_input_string_, &global_input_file->sources_);
153 allow_includes_b_ = allow_includes_b_ && ! (safe_global_b);
157 My_lily_lexer::set_identifier (SCM name, SCM s)
159 assert (gh_string_p (name));
161 if (lookup_keyword (ly_scm2string (name)) >= 0)
164 char * str = gh_scm2newstr (name, &sz) ;
165 warning (_f ("Identifier name is a keyword: `%s'", str));
169 SCM sym = scm_string_to_symbol (name);
170 SCM mod = gh_car (scopes_);
172 scm_module_define (mod, sym, s);
175 My_lily_lexer::~My_lily_lexer ()
183 My_lily_lexer::LexerError (char const *s)
185 if (include_stack_.empty ())
187 progress_indication (_f ("error at EOF: %s", s)+ String ("\n"));
192 Input spot (get_source_file (), here_str0 ());
198 My_lily_lexer::escaped_char (char c) const
216 My_lily_lexer::here_input () const
218 Source_file * f= get_source_file ();
219 return Input (f, (char*)here_str0 ());
223 My_lily_lexer::prepare_for_next_token ()
225 last_input_ = here_input();