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@stack.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[]={
32 {"consists", CONSISTS},
33 {"contains", CONTAINS},
34 {"duration", DURATION},
35 {"absdynamic", ABSDYNAMIC},
37 {"translator", TRANSLATOR},
41 {"melodic" , MELODIC},
42 {"musical_pitch", MUSICAL_PITCH},
48 {"notenames", NOTENAMES},
54 {"property", PROPERTY},
56 {"relative", RELATIVE},
63 {"spandynamic", SPANDYNAMIC},
64 {"symboltables", SYMBOLTABLES},
67 {"textstyle", TEXTSTYLE},
68 {"transpose", TRANSPOSE},
70 {"grouping", GROUPING},
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]->elt_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 unique_b)
114 Identifier *old = lookup_identifier (name_str);
118 old->warning(_("redeclaration of \\") + name_str);
121 (*scope_l_arr_.top ())[name_str] = i;
124 My_lily_lexer::~My_lily_lexer()
127 delete toplevel_scope_p_ ;
134 My_lily_lexer::print_declarations (bool init_b) const
136 for (int i=scope_l_arr_.size (); i--; )
138 DOUT << "Scope no. " << i << "\n";
139 scope_l_arr_[i]->print ();
144 My_lily_lexer::LexerError (char const *s)
146 if (include_stack_.empty())
148 *mlog << _("error at EOF") << s << '\n';
153 Input spot (source_file_l(),here_ch_C());
159 My_lily_lexer::lookup_pitch (String s)
161 return (*note_tab_p_)[s];
165 My_lily_lexer::notename_b (String s) const
167 return note_tab_p_->elt_b (s);
171 My_lily_lexer::add_notename (String s, Musical_pitch p)
173 (*note_tab_p_)[s] = p;
177 My_lily_lexer::clear_notenames()
180 note_tab_p_ = new Notename_table;
184 My_lily_lexer::escaped_char(char c) const