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>
13 #include "lily-proto.hh"
14 #include "scm-hash.hh"
15 #include "interval.hh"
16 #include "input-file-results.hh"
17 #include "lily-guile.hh"
20 #include "my-lily-lexer.hh"
22 #include "source-file.hh"
26 #include "ly-modules.hh"
29 static Keyword_ent the_key_tab[]={
32 {"arpeggio", ARPEGGIO },
33 {"autochange", AUTOCHANGE},
34 {"spanrequest", SPANREQUEST},
35 {"commandspanrequest", COMMANDSPANREQUEST},
36 {"simultaneous", SIMULTANEOUS},
37 {"sequential", SEQUENTIAL},
39 {"alternative", ALTERNATIVE},
43 {"chordmodifiers", CHORDMODIFIERS},
47 {"consists", CONSISTS},
48 {"consistsend", CONSISTSEND},
52 {"duration", DURATION},
53 {"dynamicscript", DYNAMICSCRIPT},
54 {"grobdescriptions", GROBDESCRIPTIONS},
57 {"glissando", GLISSANDO},
70 {"pitchnames", PITCHNAMES},
72 {"outputproperty", OUTPUTPROPERTY},
73 {"override", OVERRIDE},
80 {"property", PROPERTY},
82 {"relative", RELATIVE},
85 {"addlyrics", ADDLYRICS},
86 {"partcombine", PARTCOMBINE},
89 {"stylesheet", STYLESHEET},
92 {"translator", TRANSLATOR},
93 {"transpose", TRANSPOSE},
100 My_lily_lexer::My_lily_lexer ()
102 keytable_ = new Keyword_table (the_key_tab);
105 add_scope(ly_make_anonymous_module());
108 main_input_b_ = false;
112 My_lily_lexer::add_scope (SCM module)
114 ly_reexport_module (scm_current_module());
115 scm_set_current_module (module);
116 for (SCM s = scopes_; gh_pair_p (s); s = gh_cdr (s))
119 UGH. how to do this more neatly?
121 SCM expr = scm_list_n (ly_symbol2scm ("module-use!"),
122 module, scm_list_n (ly_symbol2scm ("module-public-interface"),
123 gh_car (s), SCM_UNDEFINED),
126 scm_primitive_eval(expr);
129 scopes_ = scm_cons (module, scopes_);
133 My_lily_lexer::remove_scope ()
135 SCM sc = gh_car (scopes_);
136 scopes_ = gh_cdr (scopes_);
137 scm_set_current_module (gh_car (scopes_));
144 My_lily_lexer::lookup_keyword (String s)
146 return keytable_->lookup (s.to_str0 ());
150 My_lily_lexer::lookup_identifier (String s)
152 SCM sym = ly_symbol2scm (s.to_str0());
153 for (SCM s = scopes_; gh_pair_p (s); s = gh_cdr (s))
155 SCM var = ly_module_lookup (gh_car (s), sym);
156 if (var != SCM_BOOL_F)
157 return scm_variable_ref(var);
160 return SCM_UNSPECIFIED;
164 My_lily_lexer::start_main_input ()
166 new_input (main_input_string_, &global_input_file->sources_);
167 allow_includes_b_ = allow_includes_b_ && ! (safe_global_b);
171 My_lily_lexer::set_identifier (SCM name, SCM s)
173 assert (gh_string_p (name));
175 if (lookup_keyword (ly_scm2string (name)) >= 0)
178 char * str = gh_scm2newstr (name, &sz) ;
179 warning (_f ("Identifier name is a keyword: `%s'", str));
183 SCM sym = scm_string_to_symbol (name);
184 SCM mod = gh_car (scopes_);
186 scm_module_define (mod, sym, s);
189 My_lily_lexer::~My_lily_lexer ()
197 My_lily_lexer::LexerError (char const *s)
199 if (include_stack_.empty ())
201 progress_indication (_f ("error at EOF: %s", s)+ String ("\n"));
206 Input spot (get_source_file (),here_str0 ());
212 My_lily_lexer::escaped_char (char c) const
230 My_lily_lexer::here_input () const
232 Source_file * f= get_source_file ();
233 return Input (f, (char*)here_str0 ());