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},
31 {"chordmodifiers", CHORDMODIFIERS},
35 {"consists", CONSISTS},
36 {"duration", DURATION},
38 {"grouping", GROUPING},
43 {"keysignature", KEYSIGNATURE},
45 {"musicalpitch", MUSICAL_PITCH},
51 {"notenames", NOTENAMES},
56 {"property", PROPERTY},
58 {"relative", RELATIVE},
68 {"spandynamic", SPANDYNAMIC},
69 {"symboltables", SYMBOLTABLES},
71 {"translator", TRANSLATOR},
73 {"transpose", TRANSPOSE},
78 My_lily_lexer::My_lily_lexer()
80 keytable_p_ = new Keyword_table (the_key_tab);
81 toplevel_scope_p_ = new Scope;
82 scope_l_arr_.push (toplevel_scope_p_);
84 note_tab_p_ = new Notename_table;
85 chordmodifier_tab_p_ = new Notename_table;
86 main_input_b_ = false;
90 My_lily_lexer::lookup_keyword (String s)
92 return keytable_p_->lookup (s.ch_C ());
96 My_lily_lexer::lookup_identifier (String s)
98 for (int i = scope_l_arr_.size (); i--; )
99 if (scope_l_arr_[i]->elem_b (s))
100 return (*scope_l_arr_[i])[s];
105 My_lily_lexer::start_main_input ()
107 if (!monitor->silent_b ("InitDeclarations") && check_debug)
108 print_declarations (true);
109 if (!monitor->silent_b ("InitLexer") && check_debug)
113 new_input (main_input_str_, source_global_l);
115 allow_includes_b_ = false;
117 print_declarations(true);
121 My_lily_lexer::set_identifier (String name_str, Identifier* i, bool )
124 if (scope_l_arr_.top ()->elem_b (name_str))
125 old = scope_l_arr_.top ()->elem(name_str);
132 old->warning(_f ("redeclaration of `\\%s\'", name_str));
136 if (lookup_keyword (name_str) >= 0)
138 warning ( _f ("Identifier name is a keyword (`%s')", name_str));
141 (*scope_l_arr_.top ())[name_str] = i;
144 My_lily_lexer::~My_lily_lexer()
147 delete toplevel_scope_p_ ;
152 My_lily_lexer::print_declarations (bool ) const
154 for (int i=scope_l_arr_.size (); i--; )
156 DOUT << "Scope no. " << i << '\n';
157 scope_l_arr_[i]->print ();
162 My_lily_lexer::LexerError (char const *s)
164 if (include_stack_.empty())
166 *mlog << _f ("error at EOF: %s", s) << endl;
171 Input spot (source_file_l(),here_ch_C());
177 My_lily_lexer::lookup_notename (String s)
179 return (*note_tab_p_)[s];
183 My_lily_lexer::lookup_chordmodifier (String s)
185 return (*chordmodifier_tab_p_)[s];
189 My_lily_lexer::notename_b (String s) const
191 return note_tab_p_->elem_b (s);
195 My_lily_lexer::set_notename_table (Notename_table *p)
202 My_lily_lexer::chordmodifier_b (String s) const
204 return chordmodifier_tab_p_->elem_b (s);
208 My_lily_lexer::set_chordmodifier_table (Notename_table *p)
210 delete chordmodifier_tab_p_;
211 chordmodifier_tab_p_ = p;
215 My_lily_lexer::escaped_char(char c) const