2 my-lily-lexer.cc -- implement My_lily_lexer
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "notename-table.hh"
12 #include "interval.hh"
13 #include "identifier.hh"
16 #include "my-lily-lexer.hh"
18 #include "source-file.hh"
19 #include "parseconstruct.hh"
23 static Keyword_ent the_key_tab[]={
24 {"spanrequest", SPANREQUEST},
26 {"alternative", ALTERNATIVE},
30 {"chordmodifiers", CHORDMODIFIERS},
34 {"consists", CONSISTS},
35 {"consistsend", CONSISTSEND},
37 {"duration", DURATION},
39 {"grouping", GROUPING},
44 {"keysignature", KEYSIGNATURE},
46 {"musicalpitch", MUSICAL_PITCH},
52 {"notenames", NOTENAMES},
57 {"property", PROPERTY},
59 {"relative", RELATIVE},
68 {"textscript", TEXTSCRIPT},
70 {"translator", TRANSLATOR},
71 {"transpose", TRANSPOSE},
77 My_lily_lexer::My_lily_lexer()
79 keytable_p_ = new Keyword_table (the_key_tab);
80 toplevel_scope_p_ = new Scope;
81 scope_l_arr_.push (toplevel_scope_p_);
83 note_tab_p_ = new Notename_table;
84 chordmodifier_tab_p_ = new Notename_table;
85 main_input_b_ = false;
89 My_lily_lexer::lookup_keyword (String s)
91 return keytable_p_->lookup (s.ch_C ());
95 My_lily_lexer::lookup_identifier (String s)
97 SCM sym = ly_symbol (s.ch_C());
99 for (int i = scope_l_arr_.size (); i--; )
100 if (scope_l_arr_[i]->elem_b (sym))
101 return scope_l_arr_[i]->elem(sym);
106 My_lily_lexer::start_main_input ()
108 if (!monitor->silent_b ("InitDeclarations") && check_debug)
109 print_declarations (true);
110 if (!monitor->silent_b ("InitLexer") && check_debug)
114 new_input (main_input_str_, source_global_l);
116 allow_includes_b_ = false;
118 print_declarations(true);
122 My_lily_lexer::set_identifier (String name_str, Identifier* i, bool )
125 if (scope_l_arr_.top ()->elem_b (name_str))
126 old = scope_l_arr_.top ()->elem(name_str);
133 old->warning(_f ("redeclaration of `\\%s\'", name_str));
137 if (lookup_keyword (name_str) >= 0)
139 warning ( _f ("Identifier name is a keyword (`%s')", name_str));
142 scope_l_arr_.top ()->elem (name_str) = i;
145 My_lily_lexer::~My_lily_lexer()
147 delete chordmodifier_tab_p_;
149 delete toplevel_scope_p_ ;
154 My_lily_lexer::print_declarations (bool ) const
156 for (int i=scope_l_arr_.size (); i--; )
158 DOUT << "Scope no. " << i << '\n';
159 scope_l_arr_[i]->print ();
164 My_lily_lexer::LexerError (char const *s)
166 if (include_stack_.empty())
168 *mlog << _f ("error at EOF: %s", s) << endl;
173 Input spot (source_file_l(),here_ch_C());
179 My_lily_lexer::lookup_notename (String s)
181 return (*note_tab_p_)[s];
185 My_lily_lexer::lookup_chordmodifier (String s)
187 return (*chordmodifier_tab_p_)[s];
191 My_lily_lexer::notename_b (String s) const
193 return note_tab_p_->elem_b (s);
197 My_lily_lexer::set_notename_table (Notename_table *p)
204 My_lily_lexer::chordmodifier_b (String s) const
206 return chordmodifier_tab_p_->elem_b (s);
210 My_lily_lexer::set_chordmodifier_table (Notename_table *p)
212 delete chordmodifier_tab_p_;
213 chordmodifier_tab_p_ = p;
217 My_lily_lexer::escaped_char(char c) const