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[]={
30 {"addlyrics", ADDLYRICS},
32 {"alternative", ALTERNATIVE},
34 {"applycontext", APPLYCONTEXT},
35 {"applyoutput", APPLYOUTPUT},
36 {"autochange", AUTOCHANGE},
39 {"chordmodifiers", CHORDMODIFIERS},
42 {"consists", CONSISTS},
43 {"consistsend", CONSISTSEND},
47 {"description", DESCRIPTION},
48 {"duration", DURATION},
51 {"grobdescriptions", GROBDESCRIPTIONS},
62 {"outputproperty", OUTPUTPROPERTY},
63 {"override", OVERRIDE},
65 {"partcombine", PARTCOMBINE},
68 {"pitchnames", PITCHNAMES},
69 {"property", PROPERTY},
70 {"relative", RELATIVE},
76 {"sequential", SEQUENTIAL},
78 {"simultaneous", SIMULTANEOUS},
83 {"translator", TRANSLATOR},
84 {"transpose", TRANSPOSE},
91 My_lily_lexer::My_lily_lexer ()
93 keytable_ = new Keyword_table (the_key_tab);
96 add_scope(ly_make_anonymous_module());
99 main_input_b_ = false;
103 My_lily_lexer::add_scope (SCM module)
105 ly_reexport_module (scm_current_module());
106 scm_set_current_module (module);
107 for (SCM s = scopes_; gh_pair_p (s); s = gh_cdr (s))
110 UGH. how to do this more neatly?
112 SCM expr = scm_list_n (ly_symbol2scm ("module-use!"),
113 module, scm_list_n (ly_symbol2scm ("module-public-interface"),
114 gh_car (s), SCM_UNDEFINED),
117 scm_primitive_eval(expr);
120 scopes_ = scm_cons (module, scopes_);
124 My_lily_lexer::remove_scope ()
126 SCM sc = gh_car (scopes_);
127 scopes_ = gh_cdr (scopes_);
128 scm_set_current_module (gh_car (scopes_));
135 My_lily_lexer::lookup_keyword (String s)
137 return keytable_->lookup (s.to_str0 ());
141 My_lily_lexer::lookup_identifier (String s)
143 SCM sym = ly_symbol2scm (s.to_str0());
144 for (SCM s = scopes_; gh_pair_p (s); s = gh_cdr (s))
146 SCM var = ly_module_lookup (gh_car (s), sym);
147 if (var != SCM_BOOL_F)
148 return scm_variable_ref(var);
151 return SCM_UNDEFINED;
155 My_lily_lexer::start_main_input ()
157 new_input (main_input_string_, &global_input_file->sources_);
158 allow_includes_b_ = allow_includes_b_ && ! (safe_global_b);
162 My_lily_lexer::set_identifier (SCM name, SCM s)
164 assert (gh_string_p (name));
166 if (lookup_keyword (ly_scm2string (name)) >= 0)
169 char * str = gh_scm2newstr (name, &sz) ;
170 warning (_f ("Identifier name is a keyword: `%s'", str));
174 SCM sym = scm_string_to_symbol (name);
175 SCM mod = gh_car (scopes_);
177 scm_module_define (mod, sym, s);
180 My_lily_lexer::~My_lily_lexer ()
188 My_lily_lexer::LexerError (char const *s)
190 if (include_stack_.empty ())
192 progress_indication (_f ("error at EOF: %s", s)+ String ("\n"));
197 Input spot (get_source_file (), here_str0 ());
203 My_lily_lexer::escaped_char (char c) const
221 My_lily_lexer::here_input () const
223 Source_file * f= get_source_file ();
224 return Input (f, (char*)here_str0 ());
228 My_lily_lexer::prepare_for_next_token ()
230 last_input_ = here_input();
235 My_lily_lexer::scan_markup_word (String s)
238 TODO: better implementation:
240 - make a table of markup functions, for quicker lookup
245 SCM s = scm_c_eval_str ((s + "-markup").to_str0());