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 {"arpeggio", ARPEGGIO },
32 {"autochange", AUTOCHANGE},
33 {"spanrequest", SPANREQUEST},
34 {"commandspanrequest", COMMANDSPANREQUEST},
35 {"simultaneous", SIMULTANEOUS},
36 {"sequential", SEQUENTIAL},
38 {"alternative", ALTERNATIVE},
42 {"chordmodifiers", CHORDMODIFIERS},
46 {"consists", CONSISTS},
47 {"consistsend", CONSISTSEND},
51 {"duration", DURATION},
52 {"grobdescriptions", GROBDESCRIPTIONS},
55 {"glissando", GLISSANDO},
68 {"pitchnames", PITCHNAMES},
70 {"outputproperty", OUTPUTPROPERTY},
71 {"override", OVERRIDE},
78 {"property", PROPERTY},
80 {"relative", RELATIVE},
83 {"addlyrics", ADDLYRICS},
84 {"partcombine", PARTCOMBINE},
87 {"stylesheet", STYLESHEET},
90 {"translator", TRANSLATOR},
91 {"transpose", TRANSPOSE},
98 My_lily_lexer::My_lily_lexer ()
100 keytable_ = new Keyword_table (the_key_tab);
103 add_scope(ly_make_anonymous_module());
106 main_input_b_ = false;
110 My_lily_lexer::add_scope (SCM module)
112 ly_reexport_module (scm_current_module());
113 scm_set_current_module (module);
114 for (SCM s = scopes_; gh_pair_p (s); s = gh_cdr (s))
117 UGH. how to do this more neatly?
119 SCM expr = scm_list_n (ly_symbol2scm ("module-use!"),
120 module, scm_list_n (ly_symbol2scm ("module-public-interface"),
121 gh_car (s), SCM_UNDEFINED),
124 scm_primitive_eval(expr);
127 scopes_ = scm_cons (module, scopes_);
131 My_lily_lexer::remove_scope ()
133 SCM sc = gh_car (scopes_);
134 scopes_ = gh_cdr (scopes_);
135 scm_set_current_module (gh_car (scopes_));
142 My_lily_lexer::lookup_keyword (String s)
144 return keytable_->lookup (s.to_str0 ());
148 My_lily_lexer::lookup_identifier (String s)
150 SCM sym = ly_symbol2scm (s.to_str0());
151 for (SCM s = scopes_; gh_pair_p (s); s = gh_cdr (s))
153 SCM var = ly_module_lookup (gh_car (s), sym);
154 if (var != SCM_BOOL_F)
155 return scm_variable_ref(var);
158 return SCM_UNSPECIFIED;
162 My_lily_lexer::start_main_input ()
164 new_input (main_input_string_, &global_input_file->sources_);
165 allow_includes_b_ = allow_includes_b_ && ! (safe_global_b);
169 My_lily_lexer::set_identifier (SCM name, SCM s)
171 assert (gh_string_p (name));
173 if (lookup_keyword (ly_scm2string (name)) >= 0)
176 char * str = gh_scm2newstr (name, &sz) ;
177 warning (_f ("Identifier name is a keyword: `%s'", str));
181 SCM sym = scm_string_to_symbol (name);
182 SCM mod = gh_car (scopes_);
184 scm_module_define (mod, sym, s);
187 My_lily_lexer::~My_lily_lexer ()
195 My_lily_lexer::LexerError (char const *s)
197 if (include_stack_.empty ())
199 progress_indication (_f ("error at EOF: %s", s)+ String ("\n"));
204 Input spot (get_source_file (), here_str0 ());
210 My_lily_lexer::escaped_char (char c) const
228 My_lily_lexer::here_input () const
230 Source_file * f= get_source_file ();
231 return Input (f, (char*)here_str0 ());
235 My_lily_lexer::prepare_for_next_token ()
237 last_input_ = here_input();