2 my-lily-lexer.cc -- implement My_lily_lexer
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2003 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},
40 {"chordnames", CHORDNAMES},
43 {"consists", CONSISTS},
44 {"consistsend", CONSISTSEND},
48 {"duration", DURATION},
49 {"grobdescriptions", GROBDESCRIPTIONS},
63 {"pitchnames", PITCHNAMES},
65 {"outputproperty", OUTPUTPROPERTY},
66 {"override", OVERRIDE},
72 {"property", PROPERTY},
73 {"relative", RELATIVE},
76 {"addlyrics", ADDLYRICS},
77 {"partcombine", PARTCOMBINE},
81 {"translator", TRANSLATOR},
82 {"transpose", TRANSPOSE},
89 My_lily_lexer::My_lily_lexer ()
91 keytable_ = new Keyword_table (the_key_tab);
94 add_scope(ly_make_anonymous_module());
97 main_input_b_ = false;
101 My_lily_lexer::add_scope (SCM module)
103 ly_reexport_module (scm_current_module());
104 scm_set_current_module (module);
105 for (SCM s = scopes_; gh_pair_p (s); s = gh_cdr (s))
108 UGH. how to do this more neatly?
110 SCM expr = scm_list_n (ly_symbol2scm ("module-use!"),
111 module, scm_list_n (ly_symbol2scm ("module-public-interface"),
112 gh_car (s), SCM_UNDEFINED),
115 scm_primitive_eval(expr);
118 scopes_ = scm_cons (module, scopes_);
122 My_lily_lexer::remove_scope ()
124 SCM sc = gh_car (scopes_);
125 scopes_ = gh_cdr (scopes_);
126 scm_set_current_module (gh_car (scopes_));
133 My_lily_lexer::lookup_keyword (String s)
135 return keytable_->lookup (s.to_str0 ());
139 My_lily_lexer::lookup_identifier (String s)
141 SCM sym = ly_symbol2scm (s.to_str0());
142 for (SCM s = scopes_; gh_pair_p (s); s = gh_cdr (s))
144 SCM var = ly_module_lookup (gh_car (s), sym);
145 if (var != SCM_BOOL_F)
146 return scm_variable_ref(var);
149 return SCM_UNSPECIFIED;
153 My_lily_lexer::start_main_input ()
155 new_input (main_input_string_, &global_input_file->sources_);
156 allow_includes_b_ = allow_includes_b_ && ! (safe_global_b);
160 My_lily_lexer::set_identifier (SCM name, SCM s)
162 assert (gh_string_p (name));
164 if (lookup_keyword (ly_scm2string (name)) >= 0)
167 char * str = gh_scm2newstr (name, &sz) ;
168 warning (_f ("Identifier name is a keyword: `%s'", str));
172 SCM sym = scm_string_to_symbol (name);
173 SCM mod = gh_car (scopes_);
175 scm_module_define (mod, sym, s);
178 My_lily_lexer::~My_lily_lexer ()
186 My_lily_lexer::LexerError (char const *s)
188 if (include_stack_.empty ())
190 progress_indication (_f ("error at EOF: %s", s)+ String ("\n"));
195 Input spot (get_source_file (), here_str0 ());
201 My_lily_lexer::escaped_char (char c) const
219 My_lily_lexer::here_input () const
221 Source_file * f= get_source_file ();
222 return Input (f, (char*)here_str0 ());
226 My_lily_lexer::prepare_for_next_token ()
228 last_input_ = here_input();
233 My_lily_lexer::scan_markup_word (String s)
236 TODO: better implementation:
238 - make a table of markup functions, for quicker lookup
243 SCM s = scm_c_eval_str ((s + "-markup").to_str0());