2 my-lily-lexer.cc -- implement My_lily_lexer
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 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-module.hh"
28 static Keyword_ent the_key_tab[] = {
29 {"acciaccatura", ACCIACCATURA},
31 {"addlyrics", ADDLYRICS},
32 {"addquote", ADDQUOTE},
34 {"alternative", ALTERNATIVE},
36 {"applycontext", APPLYCONTEXT},
37 {"applyoutput", APPLYOUTPUT},
38 {"appoggiatura", APPOGGIATURA},
39 {"autochange", AUTOCHANGE},
45 {"consists", CONSISTS},
46 {"consistsend", CONSISTSEND},
51 {"description", DESCRIPTION},
54 {"grobdescriptions", GROBDESCRIPTIONS},
58 {"lyricsto", NEWADDLYRICS},
67 {"override", OVERRIDE},
69 {"partcombine", PARTCOMBINE},
72 {"relative", RELATIVE},
78 {"sequential", SEQUENTIAL},
80 {"simultaneous", SIMULTANEOUS},
86 {"transpose", TRANSPOSE},
87 {"transposition", TRANSPOSITION},
95 My_lily_lexer::My_lily_lexer ()
97 keytable_ = new Keyword_table (the_key_tab);
99 chordmodifier_tab_ = scm_make_vector (gh_int2scm (1), SCM_EOL);
100 pitchname_tab_stack_ = SCM_EOL;
104 add_scope (ly_make_anonymous_module ());
107 main_input_b_ = false;
111 My_lily_lexer::add_scope (SCM module)
113 ly_reexport_module (scm_current_module ());
114 scm_set_current_module (module);
115 for (SCM s = scopes_; gh_pair_p (s); s = gh_cdr (s))
117 /* UGH. how to do this more neatly? */
119 = scm_list_3 (ly_symbol2scm ("module-use!"),
121 scm_list_2 (ly_symbol2scm ("module-public-interface"),
123 scm_primitive_eval (expr);
125 scopes_ = scm_cons (module, scopes_);
129 My_lily_lexer::remove_scope ()
131 SCM sc = gh_car (scopes_);
132 scopes_ = gh_cdr (scopes_);
133 scm_set_current_module (gh_car (scopes_));
140 My_lily_lexer::lookup_keyword (String s)
142 return keytable_->lookup (s.to_str0 ());
146 My_lily_lexer::lookup_identifier (String s)
148 SCM sym = ly_symbol2scm (s.to_str0());
149 for (SCM s = scopes_; gh_pair_p (s); s = gh_cdr (s))
151 SCM var = ly_module_lookup (gh_car (s), sym);
152 if (var != SCM_BOOL_F)
153 return scm_variable_ref (var);
156 return SCM_UNDEFINED;
160 My_lily_lexer::start_main_input ()
162 // yy_flex_debug = 1;
164 new_input (main_input_name_, &global_input_file->sources_);
165 /* Do not allow \include in --safe-mode */
166 allow_includes_b_ = allow_includes_b_ && ! safe_global_b;
168 scm_module_define (gh_car (scopes_),
169 ly_symbol2scm ("input-file-name"),
170 scm_makfrom0str (main_input_name_.to_str0 ()));
174 My_lily_lexer::set_identifier (SCM name, SCM s)
176 assert (gh_string_p (name));
178 if (lookup_keyword (ly_scm2string (name)) >= 0)
181 char * str = gh_scm2newstr (name, &sz) ;
182 warning (_f ("Identifier name is a keyword: `%s'", str));
186 SCM sym = scm_string_to_symbol (name);
187 SCM mod = gh_car (scopes_);
189 scm_module_define (mod, sym, s);
192 My_lily_lexer::~My_lily_lexer ()
200 My_lily_lexer::LexerError (char const *s)
202 if (include_stack_.is_empty ())
203 progress_indication (_f ("error at EOF: %s", s) + String ("\n"));
207 Input spot (get_source_file (), here_str0 ());
213 My_lily_lexer::escaped_char (char c) const
231 My_lily_lexer::here_input () const
233 Source_file * f= get_source_file ();
234 return Input (f, (char*)here_str0 ());
238 My_lily_lexer::prepare_for_next_token ()
240 last_input_ = here_input ();
244 My_lily_lexer::set_encoding (String s)