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[]={
29 {"acciaccatura", ACCIACCATURA},
31 {"addlyrics", ADDLYRICS},
33 {"alternative", ALTERNATIVE},
35 {"applycontext", APPLYCONTEXT},
36 {"applyoutput", APPLYOUTPUT},
37 {"appoggiatura", APPOGGIATURA},
38 {"autochange", AUTOCHANGE},
42 {"chordmodifiers", CHORDMODIFIERS},
45 {"consists", CONSISTS},
46 {"consistsend", CONSISTSEND},
50 {"description", DESCRIPTION},
53 {"grobdescriptions", GROBDESCRIPTIONS},
57 {"lyricsto", NEWADDLYRICS},
66 {"override", OVERRIDE},
68 {"partcombine", PARTCOMBINE},
70 {"pitchnames", PITCHNAMES},
71 {"property", PROPERTY},
72 {"relative", RELATIVE},
78 {"sequential", SEQUENTIAL},
80 {"simultaneous", SIMULTANEOUS},
86 {"translator", TRANSLATOR},
87 {"transpose", TRANSPOSE},
95 My_lily_lexer::My_lily_lexer ()
99 keytable_ = new Keyword_table (the_key_tab);
101 chordmodifier_tab_ = scm_make_vector (gh_int2scm (1), SCM_EOL);
102 pitchname_tab_ = scm_make_vector (gh_int2scm (1), SCM_EOL);
106 add_scope(ly_make_anonymous_module());
109 main_input_b_ = false;
113 My_lily_lexer::add_scope (SCM module)
115 ly_reexport_module (scm_current_module());
116 scm_set_current_module (module);
117 for (SCM s = scopes_; gh_pair_p (s); s = gh_cdr (s))
120 UGH. how to do this more neatly?
122 SCM expr = scm_list_n (ly_symbol2scm ("module-use!"),
123 module, scm_list_n (ly_symbol2scm ("module-public-interface"),
124 gh_car (s), SCM_UNDEFINED),
127 scm_primitive_eval(expr);
130 scopes_ = scm_cons (module, scopes_);
134 My_lily_lexer::remove_scope ()
136 SCM sc = gh_car (scopes_);
137 scopes_ = gh_cdr (scopes_);
138 scm_set_current_module (gh_car (scopes_));
145 My_lily_lexer::lookup_keyword (String s)
147 return keytable_->lookup (s.to_str0 ());
151 My_lily_lexer::lookup_identifier (String s)
153 SCM sym = ly_symbol2scm (s.to_str0());
154 for (SCM s = scopes_; gh_pair_p (s); s = gh_cdr (s))
156 SCM var = ly_module_lookup (gh_car (s), sym);
157 if (var != SCM_BOOL_F)
158 return scm_variable_ref(var);
161 return SCM_UNDEFINED;
165 My_lily_lexer::start_main_input ()
167 new_input (main_input_name_, &global_input_file->sources_);
168 allow_includes_b_ = allow_includes_b_ && ! (safe_global_b);
170 scm_module_define (gh_car (scopes_),
171 ly_symbol2scm ("input-file-name"),
172 scm_makfrom0str (main_input_name_.to_str0()));
176 My_lily_lexer::set_identifier (SCM name, SCM s)
178 assert (gh_string_p (name));
180 if (lookup_keyword (ly_scm2string (name)) >= 0)
183 char * str = gh_scm2newstr (name, &sz) ;
184 warning (_f ("Identifier name is a keyword: `%s'", str));
188 SCM sym = scm_string_to_symbol (name);
189 SCM mod = gh_car (scopes_);
191 scm_module_define (mod, sym, s);
194 My_lily_lexer::~My_lily_lexer ()
202 My_lily_lexer::LexerError (char const *s)
204 if (include_stack_.empty ())
206 progress_indication (_f ("error at EOF: %s", s)+ String ("\n"));
211 Input spot (get_source_file (), here_str0 ());
217 My_lily_lexer::escaped_char (char c) const
235 My_lily_lexer::here_input () const
237 Source_file * f= get_source_file ();
238 return Input (f, (char*)here_str0 ());
242 My_lily_lexer::prepare_for_next_token ()
244 last_input_ = here_input();