* mf/feta-toevallig.mf: tweak for bottom of flat sign.
[lilypond.git] / lily / my-lily-lexer.cc
blob8513720acb50223073064d5c022fb9d244c2f0d0
1 /*
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>
7 */
9 #include <ctype.h>
10 #include <sstream>
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"
17 #include "parser.hh"
18 #include "keyword.hh"
19 #include "my-lily-lexer.hh"
20 #include "warn.hh"
21 #include "source-file.hh"
22 #include "main.hh"
23 #include "input.hh"
24 #include "moment.hh"
25 #include "ly-modules.hh"
28 static Keyword_ent the_key_tab[]={
29 {"alias", ALIAS},
30 {"apply", APPLY},
31 {"applycontext", APPLYCONTEXT},
32 {"applyoutput", APPLYOUTPUT},
33 {"autochange", AUTOCHANGE},
34 {"simultaneous", SIMULTANEOUS},
35 {"sequential", SEQUENTIAL},
36 {"accepts", ACCEPTS},
37 {"alternative", ALTERNATIVE},
38 {"bar", BAR},
39 {"breathe", BREATHE},
40 {"chordmodifiers", CHORDMODIFIERS},
41 {"chords", CHORDS},
42 {"clef", CLEF},
43 {"consists", CONSISTS},
44 {"consistsend", CONSISTSEND},
45 {"context", CONTEXT},
46 {"default", DEFAULT},
47 {"denies", DENIES},
48 {"description", DESCRIPTION},
49 {"duration", DURATION},
50 {"grobdescriptions", GROBDESCRIPTIONS},
51 {"figures",FIGURES},
52 {"grace", GRACE},
53 {"header", HEADER},
54 {"lyrics", LYRICS},
55 {"key", KEY},
56 {"mark", MARK},
57 {"markup", MARKUP},
58 {"once", ONCE},
59 {"pitch", PITCH},
60 {"time", TIME_T},
61 {"times", TIMES},
62 {"midi", MIDI},
63 {"name", NAME},
64 {"pitchnames", PITCHNAMES},
65 {"notes", NOTES},
66 {"outputproperty", OUTPUTPROPERTY},
67 {"override", OVERRIDE},
68 {"set", SET},
69 {"rest", REST},
70 {"revert", REVERT},
71 {"partial", PARTIAL},
72 {"paper", PAPER},
73 {"property", PROPERTY},
74 {"relative", RELATIVE},
75 {"remove", REMOVE},
76 {"repeat", REPEAT},
77 {"addlyrics", ADDLYRICS},
78 {"partcombine", PARTCOMBINE},
79 {"score", SCORE},
80 {"skip", SKIP},
81 {"tempo", TEMPO},
82 {"translator", TRANSLATOR},
83 {"transpose", TRANSPOSE},
84 {"type", TYPE},
85 {"unset", UNSET},
86 {0,0}
90 My_lily_lexer::My_lily_lexer ()
92 keytable_ = new Keyword_table (the_key_tab);
93 scopes_ = SCM_EOL;
95 add_scope(ly_make_anonymous_module());
96 errorlevel_ =0;
98 main_input_b_ = false;
101 void
102 My_lily_lexer::add_scope (SCM module)
104 ly_reexport_module (scm_current_module());
105 scm_set_current_module (module);
106 for (SCM s = scopes_; gh_pair_p (s); s = gh_cdr (s))
109 UGH. how to do this more neatly?
111 SCM expr = scm_list_n (ly_symbol2scm ("module-use!"),
112 module, scm_list_n (ly_symbol2scm ("module-public-interface"),
113 gh_car (s), SCM_UNDEFINED),
114 SCM_UNDEFINED);
116 scm_primitive_eval(expr);
119 scopes_ = scm_cons (module, scopes_);
123 My_lily_lexer::remove_scope ()
125 SCM sc = gh_car (scopes_);
126 scopes_ = gh_cdr (scopes_);
127 scm_set_current_module (gh_car (scopes_));
129 return sc;
134 My_lily_lexer::lookup_keyword (String s)
136 return keytable_->lookup (s.to_str0 ());
140 My_lily_lexer::lookup_identifier (String s)
142 SCM sym = ly_symbol2scm (s.to_str0());
143 for (SCM s = scopes_; gh_pair_p (s); s = gh_cdr (s))
145 SCM var = ly_module_lookup (gh_car (s), sym);
146 if (var != SCM_BOOL_F)
147 return scm_variable_ref(var);
150 return SCM_UNDEFINED;
153 void
154 My_lily_lexer::start_main_input ()
156 new_input (main_input_string_, &global_input_file->sources_);
157 allow_includes_b_ = allow_includes_b_ && ! (safe_global_b);
160 void
161 My_lily_lexer::set_identifier (SCM name, SCM s)
163 assert (gh_string_p (name));
165 if (lookup_keyword (ly_scm2string (name)) >= 0)
167 size_t sz;
168 char * str = gh_scm2newstr (name, &sz) ;
169 warning (_f ("Identifier name is a keyword: `%s'", str));
170 free (str);
173 SCM sym = scm_string_to_symbol (name);
174 SCM mod = gh_car (scopes_);
176 scm_module_define (mod, sym, s);
179 My_lily_lexer::~My_lily_lexer ()
181 delete keytable_;
186 void
187 My_lily_lexer::LexerError (char const *s)
189 if (include_stack_.empty ())
191 progress_indication (_f ("error at EOF: %s", s)+ String ("\n"));
193 else
195 errorlevel_ |= 1;
196 Input spot (get_source_file (), here_str0 ());
197 spot.error (s);
201 char
202 My_lily_lexer::escaped_char (char c) const
204 switch (c)
206 case 'n':
207 return '\n';
208 case 't':
209 return '\t';
211 case '\'':
212 case '\"':
213 case '\\':
214 return c;
216 return 0;
219 Input
220 My_lily_lexer::here_input () const
222 Source_file * f= get_source_file ();
223 return Input (f, (char*)here_str0 ());
226 void
227 My_lily_lexer::prepare_for_next_token ()
229 last_input_ = here_input();
232 #if 0
234 My_lily_lexer::scan_markup_word (String s)
237 TODO: better implementation:
239 - make a table of markup functions, for quicker lookup
241 - error handling.
244 SCM s = scm_c_eval_str ((s + "-markup").to_str0());
245 yylval.scm = s;
246 return MARKUP_HEAD;
248 #endif