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 {"applycontext", APPLYCONTEXT},
32 {"autochange", AUTOCHANGE},
33 {"simultaneous", SIMULTANEOUS},
34 {"sequential", SEQUENTIAL},
36 {"alternative", ALTERNATIVE},
39 {"chordmodifiers", CHORDMODIFIERS},
42 {"consists", CONSISTS},
43 {"consistsend", CONSISTSEND},
47 {"duration", DURATION},
48 {"grobdescriptions", GROBDESCRIPTIONS},
61 {"pitchnames", PITCHNAMES},
63 {"outputproperty", OUTPUTPROPERTY},
64 {"override", OVERRIDE},
70 {"property", PROPERTY},
71 {"relative", RELATIVE},
74 {"addlyrics", ADDLYRICS},
75 {"partcombine", PARTCOMBINE},
79 {"translator", TRANSLATOR},
80 {"transpose", TRANSPOSE},
87 My_lily_lexer::My_lily_lexer ()
89 keytable_ = new Keyword_table (the_key_tab);
92 add_scope(ly_make_anonymous_module());
95 main_input_b_ = false;
99 My_lily_lexer::add_scope (SCM module)
101 ly_reexport_module (scm_current_module());
102 scm_set_current_module (module);
103 for (SCM s = scopes_; gh_pair_p (s); s = gh_cdr (s))
106 UGH. how to do this more neatly?
108 SCM expr = scm_list_n (ly_symbol2scm ("module-use!"),
109 module, scm_list_n (ly_symbol2scm ("module-public-interface"),
110 gh_car (s), SCM_UNDEFINED),
113 scm_primitive_eval(expr);
116 scopes_ = scm_cons (module, scopes_);
120 My_lily_lexer::remove_scope ()
122 SCM sc = gh_car (scopes_);
123 scopes_ = gh_cdr (scopes_);
124 scm_set_current_module (gh_car (scopes_));
131 My_lily_lexer::lookup_keyword (String s)
133 return keytable_->lookup (s.to_str0 ());
137 My_lily_lexer::lookup_identifier (String s)
139 SCM sym = ly_symbol2scm (s.to_str0());
140 for (SCM s = scopes_; gh_pair_p (s); s = gh_cdr (s))
142 SCM var = ly_module_lookup (gh_car (s), sym);
143 if (var != SCM_BOOL_F)
144 return scm_variable_ref(var);
147 return SCM_UNSPECIFIED;
151 My_lily_lexer::start_main_input ()
153 new_input (main_input_string_, &global_input_file->sources_);
154 allow_includes_b_ = allow_includes_b_ && ! (safe_global_b);
158 My_lily_lexer::set_identifier (SCM name, SCM s)
160 assert (gh_string_p (name));
162 if (lookup_keyword (ly_scm2string (name)) >= 0)
165 char * str = gh_scm2newstr (name, &sz) ;
166 warning (_f ("Identifier name is a keyword: `%s'", str));
170 SCM sym = scm_string_to_symbol (name);
171 SCM mod = gh_car (scopes_);
173 scm_module_define (mod, sym, s);
176 My_lily_lexer::~My_lily_lexer ()
184 My_lily_lexer::LexerError (char const *s)
186 if (include_stack_.empty ())
188 progress_indication (_f ("error at EOF: %s", s)+ String ("\n"));
193 Input spot (get_source_file (), here_str0 ());
199 My_lily_lexer::escaped_char (char c) const
217 My_lily_lexer::here_input () const
219 Source_file * f= get_source_file ();
220 return Input (f, (char*)here_str0 ());
224 My_lily_lexer::prepare_for_next_token ()
226 last_input_ = here_input();
231 My_lily_lexer::scan_markup_word (String s)
234 TODO: better implementation:
236 - make a table of markup functions, for quicker lookup
241 SCM s = scm_c_eval_str ((s + "-markup").to_str0());