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},
46 {"notenames", NOTENAMES},
53 {"property", PROPERTY},
55 {"relative", RELATIVE},
61 {"spandynamic", SPANDYNAMIC},
62 {"symboltables", SYMBOLTABLES},
64 {"translator", TRANSLATOR},
66 {"transpose", TRANSPOSE},
71 My_lily_lexer::My_lily_lexer()
73 keytable_p_ = new Keyword_table (the_key_tab);
74 toplevel_scope_p_ = new Scope;
75 scope_l_arr_.push (toplevel_scope_p_);
77 note_tab_p_ = new Notename_table;
81 My_lily_lexer::lookup_keyword (String s)
83 return keytable_p_->lookup (s.ch_C ());
87 My_lily_lexer::lookup_identifier (String s)
89 for (int i = scope_l_arr_.size (); i--; )
90 if (scope_l_arr_[i]->elt_b (s))
91 return (*scope_l_arr_[i])[s];
96 My_lily_lexer::start_main_input ()
98 if (!monitor->silent_b ("InitDeclarations") && check_debug)
99 print_declarations (true);
100 if (!monitor->silent_b ("InitLexer") && check_debug)
103 new_input (main_input_str_, source_global_l);
105 print_declarations(true);
109 My_lily_lexer::set_identifier (String name_str, Identifier* i, bool unique_b)
111 Identifier *old = lookup_identifier (name_str);
116 old->warning(_f ("redeclaration of `\\%s\'", name_str));
120 if (lookup_keyword (name_str) >= 0)
122 warning ( _f ("Identifier name is a keyword (`%s')", name_str));
125 (*scope_l_arr_.top ())[name_str] = i;
128 My_lily_lexer::~My_lily_lexer()
131 delete toplevel_scope_p_ ;
136 My_lily_lexer::print_declarations (bool init_b) const
138 for (int i=scope_l_arr_.size (); i--; )
140 DOUT << "Scope no. " << i << '\n';
141 scope_l_arr_[i]->print ();
146 My_lily_lexer::LexerError (char const *s)
148 if (include_stack_.empty())
150 *mlog << _f ("error at EOF: %s", s) << endl;
155 Input spot (source_file_l(),here_ch_C());
161 My_lily_lexer::lookup_pitch (String s)
163 return (*note_tab_p_)[s];
167 My_lily_lexer::notename_b (String s) const
169 return note_tab_p_->elt_b (s);
173 My_lily_lexer::add_notename (String s, Musical_pitch p)
175 (*note_tab_p_)[s] = p;
179 My_lily_lexer::set_notename_table(Notename_table *p)
186 My_lily_lexer::escaped_char(char c) const