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},
32 {"consists", CONSISTS},
33 {"duration", DURATION},
35 {"grouping", GROUPING},
40 {"keysignature", KEYSIGNATURE},
42 {"musicalpitch", MUSICAL_PITCH},
48 {"notenames", NOTENAMES},
54 {"property", PROPERTY},
56 {"relative", RELATIVE},
64 {"spandynamic", SPANDYNAMIC},
65 {"symboltables", SYMBOLTABLES},
67 {"translator", TRANSLATOR},
69 {"transpose", TRANSPOSE},
74 My_lily_lexer::My_lily_lexer()
76 keytable_p_ = new Keyword_table (the_key_tab);
77 toplevel_scope_p_ = new Scope;
78 scope_l_arr_.push (toplevel_scope_p_);
80 note_tab_p_ = new Notename_table;
84 My_lily_lexer::lookup_keyword (String s)
86 return keytable_p_->lookup (s.ch_C ());
90 My_lily_lexer::lookup_identifier (String s)
92 for (int i = scope_l_arr_.size (); i--; )
93 if (scope_l_arr_[i]->elem_b (s))
94 return (*scope_l_arr_[i])[s];
99 My_lily_lexer::start_main_input ()
101 if (!monitor->silent_b ("InitDeclarations") && check_debug)
102 print_declarations (true);
103 if (!monitor->silent_b ("InitLexer") && check_debug)
106 new_input (main_input_str_, source_global_l);
108 print_declarations(true);
112 My_lily_lexer::set_identifier (String name_str, Identifier* i, bool )
115 if (scope_l_arr_.top ()->elem_b (name_str))
116 old = scope_l_arr_.top ()->elem(name_str);
123 old->warning(_f ("redeclaration of `\\%s\'", name_str));
127 if (lookup_keyword (name_str) >= 0)
129 warning ( _f ("Identifier name is a keyword (`%s')", name_str));
132 (*scope_l_arr_.top ())[name_str] = i;
135 My_lily_lexer::~My_lily_lexer()
138 delete toplevel_scope_p_ ;
143 My_lily_lexer::print_declarations (bool ) const
145 for (int i=scope_l_arr_.size (); i--; )
147 DOUT << "Scope no. " << i << '\n';
148 scope_l_arr_[i]->print ();
153 My_lily_lexer::LexerError (char const *s)
155 if (include_stack_.empty())
157 *mlog << _f ("error at EOF: %s", s) << endl;
162 Input spot (source_file_l(),here_ch_C());
168 My_lily_lexer::lookup_pitch (String s)
170 return (*note_tab_p_)[s];
174 My_lily_lexer::notename_b (String s) const
176 return note_tab_p_->elem_b (s);
180 My_lily_lexer::add_notename (String s, Musical_pitch p)
182 (*note_tab_p_)[s] = p;
186 My_lily_lexer::set_notename_table(Notename_table *p)
193 My_lily_lexer::escaped_char(char c) const