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},
36 {"chordmodifiers", CHORDMODIFIERS},
40 {"consists", CONSISTS},
41 {"consistsend", CONSISTSEND},
43 {"duration", DURATION},
50 {"keysignature", KEYSIGNATURE},
52 {"musicalpitch", MUSICAL_PITCH},
58 {"notenames", NOTENAMES},
63 {"property", PROPERTY},
65 {"relative", RELATIVE},
68 {"repetitions", REPETITIONS},
69 {"addlyrics", ADDLYRICS},
73 {"textscript", TEXTSCRIPT},
75 {"translator", TRANSLATOR},
76 {"transpose", TRANSPOSE},
81 My_lily_lexer::My_lily_lexer()
83 keytable_p_ = new Keyword_table (the_key_tab);
84 toplevel_scope_p_ = new Scope;
85 scope_l_arr_.push (toplevel_scope_p_);
87 note_tab_p_ = new Notename_table;
88 chordmodifier_tab_p_ = new Notename_table;
89 main_input_b_ = false;
93 My_lily_lexer::lookup_keyword (String s)
95 return keytable_p_->lookup (s.ch_C ());
99 My_lily_lexer::lookup_identifier (String s)
101 SCM sym = ly_symbol2scm (s.ch_C());
103 for (int i = scope_l_arr_.size (); i--; )
104 if (scope_l_arr_[i]->elem_b (sym))
105 return scope_l_arr_[i]->elem(sym);
110 My_lily_lexer::start_main_input ()
112 if (flower_dstream && !flower_dstream->silent_b ("InitDeclarations") && flower_dstream)
113 print_declarations (true);
114 if (flower_dstream && !flower_dstream->silent_b ("InitLexer") && flower_dstream)
118 new_input (main_input_str_, source_global_l);
119 allow_includes_b_ = allow_includes_b_ && !(safe_global_b);
122 print_declarations(true);
126 My_lily_lexer::set_identifier (String name_str, Identifier* i, bool )
129 if (scope_l_arr_.top ()->elem_b (name_str))
130 old = scope_l_arr_.top ()->elem(name_str);
137 old->warning(_f ("redeclaration of `\\%s'", name_str));
141 if (lookup_keyword (name_str) >= 0)
143 warning ( _f ("Identifier name is a keyword: `%s'", name_str));
146 scope_l_arr_.top ()->elem (name_str) = i;
149 My_lily_lexer::~My_lily_lexer()
151 delete chordmodifier_tab_p_;
153 delete toplevel_scope_p_ ;
158 My_lily_lexer::print_declarations (bool ) const
160 for (int i=scope_l_arr_.size (); i--; )
162 DEBUG_OUT << "Scope no. " << i << '\n';
163 scope_l_arr_[i]->print ();
168 My_lily_lexer::LexerError (char const *s)
170 if (include_stack_.empty())
172 progress_indication (_f ("error at EOF: %s", s)+ String ("\n"));
177 Input spot (source_file_l(),here_ch_C());
183 My_lily_lexer::lookup_notename (String s)
185 return note_tab_p_->get_pitch (s);
189 My_lily_lexer::lookup_chordmodifier (String s)
191 return chordmodifier_tab_p_->get_pitch (s);
196 My_lily_lexer::set_notename_table (Notename_table *p)
205 My_lily_lexer::set_chordmodifier_table (Notename_table *p)
207 delete chordmodifier_tab_p_;
208 chordmodifier_tab_p_ = p;
212 My_lily_lexer::escaped_char(char c) const
230 My_lily_lexer::here_input () const
232 Source_file * f_l= source_file_l ();
233 return Input (f_l, (char*)here_ch_C ());