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 {"accidentals", ACCIDENTALS},
34 {"consists", CONSISTS},
35 {"contains", CONTAINS},
36 {"duration", DURATION},
38 {"grouping", GROUPING},
43 {"melodic" , MELODIC},
44 {"musicalpitch", MUSICAL_PITCH},
50 {"notenames", NOTENAMES},
56 {"property", PROPERTY},
58 {"relative", RELATIVE},
65 {"spandynamic", SPANDYNAMIC},
66 {"symboltables", SYMBOLTABLES},
68 {"translator", TRANSLATOR},
70 {"transpose", TRANSPOSE},
75 My_lily_lexer::My_lily_lexer()
77 keytable_p_ = new Keyword_table (the_key_tab);
78 toplevel_scope_p_ = new Scope;
79 scope_l_arr_.push (toplevel_scope_p_);
81 note_tab_p_ = new Notename_table;
85 My_lily_lexer::lookup_keyword (String s)
87 return keytable_p_->lookup (s.ch_C ());
91 My_lily_lexer::lookup_identifier (String s)
93 for (int i = scope_l_arr_.size (); i--; )
94 if (scope_l_arr_[i]->elt_b (s))
95 return (*scope_l_arr_[i])[s];
100 My_lily_lexer::start_main_input ()
102 if (!monitor->silent_b ("InitDeclarations") && check_debug)
103 print_declarations (true);
104 if (!monitor->silent_b ("InitLexer") && check_debug)
107 new_input (main_input_str_, source_global_l);
109 print_declarations(true);
113 My_lily_lexer::set_identifier (String name_str, Identifier* i, bool unique_b)
115 Identifier *old = lookup_identifier (name_str);
120 old->warning(_f ("redeclaration of `\\%s\'", name_str));
124 (*scope_l_arr_.top ())[name_str] = i;
127 My_lily_lexer::~My_lily_lexer()
130 delete toplevel_scope_p_ ;
135 My_lily_lexer::print_declarations (bool init_b) const
137 for (int i=scope_l_arr_.size (); i--; )
139 DOUT << "Scope no. " << i << '\n';
140 scope_l_arr_[i]->print ();
145 My_lily_lexer::LexerError (char const *s)
147 if (include_stack_.empty())
149 *mlog << _f ("error at EOF: %s", s) << endl;
154 Input spot (source_file_l(),here_ch_C());
160 My_lily_lexer::lookup_pitch (String s)
162 return (*note_tab_p_)[s];
166 My_lily_lexer::notename_b (String s) const
168 return note_tab_p_->elt_b (s);
172 My_lily_lexer::add_notename (String s, Musical_pitch p)
174 (*note_tab_p_)[s] = p;
178 My_lily_lexer::clear_notenames()
181 note_tab_p_ = new Notename_table;
185 My_lily_lexer::escaped_char(char c) const