2 my-lily-lexer.cc -- implement My_lily_lexer
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 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 {"absdynamic", ABSDYNAMIC},
26 {"alternative", ALTERNATIVE},
29 {"chordmodifiers", CHORDMODIFIERS},
33 {"consists", CONSISTS},
34 {"duration", DURATION},
36 {"grouping", GROUPING},
41 {"keysignature", KEYSIGNATURE},
43 {"musicalpitch", MUSICAL_PITCH},
49 {"notenames", NOTENAMES},
54 {"property", PROPERTY},
56 {"relative", RELATIVE},
66 {"spandynamic", SPANDYNAMIC},
67 {"symboltables", SYMBOLTABLES},
69 {"translator", TRANSLATOR},
71 {"transpose", TRANSPOSE},
76 My_lily_lexer::My_lily_lexer()
78 keytable_p_ = new Keyword_table (the_key_tab);
79 toplevel_scope_p_ = new Scope;
80 scope_l_arr_.push (toplevel_scope_p_);
82 note_tab_p_ = new Notename_table;
83 chordmodifier_tab_p_ = new Notename_table;
84 main_input_b_ = false;
88 My_lily_lexer::lookup_keyword (String s)
90 return keytable_p_->lookup (s.ch_C ());
94 My_lily_lexer::lookup_identifier (String s)
96 for (int i = scope_l_arr_.size (); i--; )
97 if (scope_l_arr_[i]->elem_b (s))
98 return (*scope_l_arr_[i])[s];
103 My_lily_lexer::start_main_input ()
105 if (!monitor->silent_b ("InitDeclarations") && check_debug)
106 print_declarations (true);
107 if (!monitor->silent_b ("InitLexer") && check_debug)
111 new_input (main_input_str_, source_global_l);
113 allow_includes_b_ = false;
115 print_declarations(true);
119 My_lily_lexer::set_identifier (String name_str, Identifier* i, bool )
122 if (scope_l_arr_.top ()->elem_b (name_str))
123 old = scope_l_arr_.top ()->elem(name_str);
130 old->warning(_f ("redeclaration of `\\%s\'", name_str));
134 if (lookup_keyword (name_str) >= 0)
136 warning ( _f ("Identifier name is a keyword (`%s')", name_str));
139 (*scope_l_arr_.top ())[name_str] = i;
142 My_lily_lexer::~My_lily_lexer()
145 delete toplevel_scope_p_ ;
150 My_lily_lexer::print_declarations (bool ) const
152 for (int i=scope_l_arr_.size (); i--; )
154 DOUT << "Scope no. " << i << '\n';
155 scope_l_arr_[i]->print ();
160 My_lily_lexer::LexerError (char const *s)
162 if (include_stack_.empty())
164 *mlog << _f ("error at EOF: %s", s) << endl;
169 Input spot (source_file_l(),here_ch_C());
175 My_lily_lexer::lookup_notename (String s)
177 return (*note_tab_p_)[s];
181 My_lily_lexer::lookup_chordmodifier (String s)
183 return (*chordmodifier_tab_p_)[s];
187 My_lily_lexer::notename_b (String s) const
189 return note_tab_p_->elem_b (s);
193 My_lily_lexer::set_notename_table (Notename_table *p)
200 My_lily_lexer::chordmodifier_b (String s) const
202 return chordmodifier_tab_p_->elem_b (s);
206 My_lily_lexer::set_chordmodifier_table (Notename_table *p)
208 delete chordmodifier_tab_p_;
209 chordmodifier_tab_p_ = p;
213 My_lily_lexer::escaped_char(char c) const