2 my-lily-lexer.cc -- implement My_lily_lexer
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "notename-table.hh"
12 #include "interval.hh"
13 #include "identifier.hh"
14 #include "lily-guile.hh"
17 #include "my-lily-lexer.hh"
19 #include "source-file.hh"
25 static Keyword_ent the_key_tab[]={
26 {"autochange", AUTOCHANGE},
27 {"spanrequest", SPANREQUEST},
28 {"commandspanrequest", COMMANDSPANREQUEST},
29 {"simultaneous", SIMULTANEOUS},
30 {"sequential", SEQUENTIAL},
32 {"alternative", ALTERNATIVE},
35 {"chordmodifiers", CHORDMODIFIERS},
39 {"consists", CONSISTS},
40 {"consistsend", CONSISTSEND},
42 {"duration", DURATION},
49 {"keysignature", KEYSIGNATURE},
51 {"musicalpitch", MUSICAL_PITCH},
57 {"notenames", NOTENAMES},
62 {"property", PROPERTY},
64 {"relative", RELATIVE},
67 {"repetitions", REPETITIONS},
68 {"addlyrics", ADDLYRICS},
72 {"textscript", TEXTSCRIPT},
74 {"translator", TRANSLATOR},
75 {"transpose", TRANSPOSE},
80 My_lily_lexer::My_lily_lexer()
82 keytable_p_ = new Keyword_table (the_key_tab);
83 toplevel_scope_p_ = new Scope;
84 scope_l_arr_.push (toplevel_scope_p_);
86 note_tab_p_ = new Notename_table;
87 chordmodifier_tab_p_ = new Notename_table;
88 main_input_b_ = false;
92 My_lily_lexer::lookup_keyword (String s)
94 return keytable_p_->lookup (s.ch_C ());
98 My_lily_lexer::lookup_identifier (String s)
100 SCM sym = ly_symbol2scm (s.ch_C());
102 for (int i = scope_l_arr_.size (); i--; )
103 if (scope_l_arr_[i]->elem_b (sym))
104 return scope_l_arr_[i]->elem(sym);
109 My_lily_lexer::start_main_input ()
111 if (flower_dstream && !flower_dstream->silent_b ("InitDeclarations") && flower_dstream)
112 print_declarations (true);
113 if (flower_dstream && !flower_dstream->silent_b ("InitLexer") && flower_dstream)
117 new_input (main_input_str_, source_global_l);
118 allow_includes_b_ = allow_includes_b_ && !(safe_global_b);
121 print_declarations(true);
125 My_lily_lexer::set_identifier (String name_str, Identifier* i, bool )
128 if (scope_l_arr_.top ()->elem_b (name_str))
129 old = scope_l_arr_.top ()->elem(name_str);
136 old->warning(_f ("redeclaration of `\\%s'", name_str));
140 if (lookup_keyword (name_str) >= 0)
142 warning ( _f ("Identifier name is a keyword: `%s'", name_str));
145 scope_l_arr_.top ()->elem (name_str) = i;
148 My_lily_lexer::~My_lily_lexer()
150 delete chordmodifier_tab_p_;
152 delete toplevel_scope_p_ ;
157 My_lily_lexer::print_declarations (bool ) const
159 for (int i=scope_l_arr_.size (); i--; )
161 DEBUG_OUT << "Scope no. " << i << '\n';
162 scope_l_arr_[i]->print ();
167 My_lily_lexer::LexerError (char const *s)
169 if (include_stack_.empty())
171 progress_indication (_f ("error at EOF: %s", s)+ String ("\n"));
176 Input spot (source_file_l(),here_ch_C());
182 My_lily_lexer::lookup_notename (String s)
184 return note_tab_p_->get_pitch (s);
188 My_lily_lexer::lookup_chordmodifier (String s)
190 return chordmodifier_tab_p_->get_pitch (s);
195 My_lily_lexer::set_notename_table (Notename_table *p)
204 My_lily_lexer::set_chordmodifier_table (Notename_table *p)
206 delete chordmodifier_tab_p_;
207 chordmodifier_tab_p_ = p;
211 My_lily_lexer::escaped_char(char c) const
229 My_lily_lexer::here_input () const
231 Source_file * f_l= source_file_l ();
232 return Input (f_l, (char*)here_ch_C ());