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 {"applyoutput", APPLYOUTPUT},
33 {"autochange", AUTOCHANGE},
34 {"simultaneous", SIMULTANEOUS},
35 {"sequential", SEQUENTIAL},
37 {"alternative", ALTERNATIVE},
40 {"chordmodifiers", CHORDMODIFIERS},
43 {"consists", CONSISTS},
44 {"consistsend", CONSISTSEND},
48 {"description", DESCRIPTION},
49 {"duration", DURATION},
50 {"grobdescriptions", GROBDESCRIPTIONS},
64 {"pitchnames", PITCHNAMES},
66 {"outputproperty", OUTPUTPROPERTY},
67 {"override", OVERRIDE},
73 {"property", PROPERTY},
74 {"relative", RELATIVE},
77 {"addlyrics", ADDLYRICS},
78 {"partcombine", PARTCOMBINE},
82 {"translator", TRANSLATOR},
83 {"transpose", TRANSPOSE},
90 My_lily_lexer::My_lily_lexer ()
92 keytable_ = new Keyword_table (the_key_tab);
95 add_scope(ly_make_anonymous_module());
98 main_input_b_ = false;
102 My_lily_lexer::add_scope (SCM module)
104 ly_reexport_module (scm_current_module());
105 scm_set_current_module (module);
106 for (SCM s = scopes_; gh_pair_p (s); s = gh_cdr (s))
109 UGH. how to do this more neatly?
111 SCM expr = scm_list_n (ly_symbol2scm ("module-use!"),
112 module, scm_list_n (ly_symbol2scm ("module-public-interface"),
113 gh_car (s), SCM_UNDEFINED),
116 scm_primitive_eval(expr);
119 scopes_ = scm_cons (module, scopes_);
123 My_lily_lexer::remove_scope ()
125 SCM sc = gh_car (scopes_);
126 scopes_ = gh_cdr (scopes_);
127 scm_set_current_module (gh_car (scopes_));
134 My_lily_lexer::lookup_keyword (String s)
136 return keytable_->lookup (s.to_str0 ());
140 My_lily_lexer::lookup_identifier (String s)
142 SCM sym = ly_symbol2scm (s.to_str0());
143 for (SCM s = scopes_; gh_pair_p (s); s = gh_cdr (s))
145 SCM var = ly_module_lookup (gh_car (s), sym);
146 if (var != SCM_BOOL_F)
147 return scm_variable_ref(var);
150 return SCM_UNSPECIFIED;
154 My_lily_lexer::start_main_input ()
156 new_input (main_input_string_, &global_input_file->sources_);
157 allow_includes_b_ = allow_includes_b_ && ! (safe_global_b);
161 My_lily_lexer::set_identifier (SCM name, SCM s)
163 assert (gh_string_p (name));
165 if (lookup_keyword (ly_scm2string (name)) >= 0)
168 char * str = gh_scm2newstr (name, &sz) ;
169 warning (_f ("Identifier name is a keyword: `%s'", str));
173 SCM sym = scm_string_to_symbol (name);
174 SCM mod = gh_car (scopes_);
176 scm_module_define (mod, sym, s);
179 My_lily_lexer::~My_lily_lexer ()
187 My_lily_lexer::LexerError (char const *s)
189 if (include_stack_.empty ())
191 progress_indication (_f ("error at EOF: %s", s)+ String ("\n"));
196 Input spot (get_source_file (), here_str0 ());
202 My_lily_lexer::escaped_char (char c) const
220 My_lily_lexer::here_input () const
222 Source_file * f= get_source_file ();
223 return Input (f, (char*)here_str0 ());
227 My_lily_lexer::prepare_for_next_token ()
229 last_input_ = here_input();
234 My_lily_lexer::scan_markup_word (String s)
237 TODO: better implementation:
239 - make a table of markup functions, for quicker lookup
244 SCM s = scm_c_eval_str ((s + "-markup").to_str0());