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},
33 {"consists", CONSISTS},
34 {"contains", CONTAINS},
35 {"duration", DURATION},
37 {"grouping", GROUPING},
42 {"keysignature", KEYSIGNATURE},
44 {"musicalpitch", MUSICAL_PITCH},
48 {"notenames", NOTENAMES},
55 {"property", PROPERTY},
57 {"relative", RELATIVE},
63 {"spandynamic", SPANDYNAMIC},
64 {"symboltables", SYMBOLTABLES},
66 {"translator", TRANSLATOR},
68 {"transpose", TRANSPOSE},
73 My_lily_lexer::My_lily_lexer()
75 keytable_p_ = new Keyword_table (the_key_tab);
76 toplevel_scope_p_ = new Scope;
77 scope_l_arr_.push (toplevel_scope_p_);
79 note_tab_p_ = new Notename_table;
83 My_lily_lexer::lookup_keyword (String s)
85 return keytable_p_->lookup (s.ch_C ());
89 My_lily_lexer::lookup_identifier (String s)
91 for (int i = scope_l_arr_.size (); i--; )
92 if (scope_l_arr_[i]->elt_b (s))
93 return (*scope_l_arr_[i])[s];
98 My_lily_lexer::start_main_input ()
100 if (!monitor->silent_b ("InitDeclarations") && check_debug)
101 print_declarations (true);
102 if (!monitor->silent_b ("InitLexer") && check_debug)
105 new_input (main_input_str_, source_global_l);
107 print_declarations(true);
111 My_lily_lexer::set_identifier (String name_str, Identifier* i, bool unique_b)
113 Identifier *old = lookup_identifier (name_str);
118 old->warning(_f ("redeclaration of `\\%s\'", name_str));
122 if (lookup_keyword (name_str) >= 0)
124 warning ( _f ("Identifier name is a keyword (`%s')", name_str));
127 (*scope_l_arr_.top ())[name_str] = i;
130 My_lily_lexer::~My_lily_lexer()
133 delete toplevel_scope_p_ ;
138 My_lily_lexer::print_declarations (bool init_b) const
140 for (int i=scope_l_arr_.size (); i--; )
142 DOUT << "Scope no. " << i << '\n';
143 scope_l_arr_[i]->print ();
148 My_lily_lexer::LexerError (char const *s)
150 if (include_stack_.empty())
152 *mlog << _f ("error at EOF: %s", s) << endl;
157 Input spot (source_file_l(),here_ch_C());
163 My_lily_lexer::lookup_pitch (String s)
165 return (*note_tab_p_)[s];
169 My_lily_lexer::notename_b (String s) const
171 return note_tab_p_->elt_b (s);
175 My_lily_lexer::add_notename (String s, Musical_pitch p)
177 (*note_tab_p_)[s] = p;
181 My_lily_lexer::clear_notenames()
184 note_tab_p_ = new Notename_table;
188 My_lily_lexer::escaped_char(char c) const