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},
62 {"pitchnames", PITCHNAMES},
64 {"outputproperty", OUTPUTPROPERTY},
65 {"override", OVERRIDE},
71 {"property", PROPERTY},
72 {"relative", RELATIVE},
75 {"addlyrics", ADDLYRICS},
76 {"partcombine", PARTCOMBINE},
80 {"translator", TRANSLATOR},
81 {"transpose", TRANSPOSE},
88 My_lily_lexer::My_lily_lexer ()
90 keytable_ = new Keyword_table (the_key_tab);
93 add_scope(ly_make_anonymous_module());
96 main_input_b_ = false;
100 My_lily_lexer::add_scope (SCM module)
102 ly_reexport_module (scm_current_module());
103 scm_set_current_module (module);
104 for (SCM s = scopes_; gh_pair_p (s); s = gh_cdr (s))
107 UGH. how to do this more neatly?
109 SCM expr = scm_list_n (ly_symbol2scm ("module-use!"),
110 module, scm_list_n (ly_symbol2scm ("module-public-interface"),
111 gh_car (s), SCM_UNDEFINED),
114 scm_primitive_eval(expr);
117 scopes_ = scm_cons (module, scopes_);
121 My_lily_lexer::remove_scope ()
123 SCM sc = gh_car (scopes_);
124 scopes_ = gh_cdr (scopes_);
125 scm_set_current_module (gh_car (scopes_));
132 My_lily_lexer::lookup_keyword (String s)
134 return keytable_->lookup (s.to_str0 ());
138 My_lily_lexer::lookup_identifier (String s)
140 SCM sym = ly_symbol2scm (s.to_str0());
141 for (SCM s = scopes_; gh_pair_p (s); s = gh_cdr (s))
143 SCM var = ly_module_lookup (gh_car (s), sym);
144 if (var != SCM_BOOL_F)
145 return scm_variable_ref(var);
148 return SCM_UNSPECIFIED;
152 My_lily_lexer::start_main_input ()
154 new_input (main_input_string_, &global_input_file->sources_);
155 allow_includes_b_ = allow_includes_b_ && ! (safe_global_b);
159 My_lily_lexer::set_identifier (SCM name, SCM s)
161 assert (gh_string_p (name));
163 if (lookup_keyword (ly_scm2string (name)) >= 0)
166 char * str = gh_scm2newstr (name, &sz) ;
167 warning (_f ("Identifier name is a keyword: `%s'", str));
171 SCM sym = scm_string_to_symbol (name);
172 SCM mod = gh_car (scopes_);
174 scm_module_define (mod, sym, s);
177 My_lily_lexer::~My_lily_lexer ()
185 My_lily_lexer::LexerError (char const *s)
187 if (include_stack_.empty ())
189 progress_indication (_f ("error at EOF: %s", s)+ String ("\n"));
194 Input spot (get_source_file (), here_str0 ());
200 My_lily_lexer::escaped_char (char c) const
218 My_lily_lexer::here_input () const
220 Source_file * f= get_source_file ();
221 return Input (f, (char*)here_str0 ());
225 My_lily_lexer::prepare_for_next_token ()
227 last_input_ = here_input();
232 My_lily_lexer::scan_markup_word (String s)
235 TODO: better implementation:
237 - make a table of markup functions, for quicker lookup
242 SCM s = scm_c_eval_str ((s + "-markup").to_str0());