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"
14 #include "assoc-iter.hh"
18 #include "my-lily-lexer.hh"
20 #include "source-file.hh"
21 #include "parseconstruct.hh"
25 static Keyword_ent the_key_tab[]={
26 {"absdynamic", ABSDYNAMIC},
28 {"alternative", ALTERNATIVE},
33 {"consists", CONSISTS},
34 {"duration", DURATION},
36 {"grouping", GROUPING},
41 {"keysignature", KEYSIGNATURE},
43 {"musicalpitch", MUSICAL_PITCH},
49 {"notenames", NOTENAMES},
55 {"property", PROPERTY},
57 {"relative", RELATIVE},
67 {"spandynamic", SPANDYNAMIC},
68 {"symboltables", SYMBOLTABLES},
70 {"translator", TRANSLATOR},
72 {"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;
87 My_lily_lexer::lookup_keyword (String s)
89 return keytable_p_->lookup (s.ch_C ());
93 My_lily_lexer::lookup_identifier (String s)
95 for (int i = scope_l_arr_.size (); i--; )
96 if (scope_l_arr_[i]->elem_b (s))
97 return (*scope_l_arr_[i])[s];
102 My_lily_lexer::start_main_input ()
104 if (!monitor->silent_b ("InitDeclarations") && check_debug)
105 print_declarations (true);
106 if (!monitor->silent_b ("InitLexer") && check_debug)
109 new_input (main_input_str_, source_global_l);
111 print_declarations(true);
115 My_lily_lexer::set_identifier (String name_str, Identifier* i, bool )
118 if (scope_l_arr_.top ()->elem_b (name_str))
119 old = scope_l_arr_.top ()->elem(name_str);
126 old->warning(_f ("redeclaration of `\\%s\'", name_str));
130 if (lookup_keyword (name_str) >= 0)
132 warning ( _f ("Identifier name is a keyword (`%s')", name_str));
135 (*scope_l_arr_.top ())[name_str] = i;
138 My_lily_lexer::~My_lily_lexer()
141 delete toplevel_scope_p_ ;
146 My_lily_lexer::print_declarations (bool ) const
148 for (int i=scope_l_arr_.size (); i--; )
150 DOUT << "Scope no. " << i << '\n';
151 scope_l_arr_[i]->print ();
156 My_lily_lexer::LexerError (char const *s)
158 if (include_stack_.empty())
160 *mlog << _f ("error at EOF: %s", s) << endl;
165 Input spot (source_file_l(),here_ch_C());
171 My_lily_lexer::lookup_pitch (String s)
173 return (*note_tab_p_)[s];
177 My_lily_lexer::notename_b (String s) const
179 return note_tab_p_->elem_b (s);
183 My_lily_lexer::add_notename (String s, Musical_pitch p)
185 (*note_tab_p_)[s] = p;
189 My_lily_lexer::set_notename_table(Notename_table *p)
196 My_lily_lexer::escaped_char(char c) const