2 my-lily-lexer.cc -- implement My_lily_lexer
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "notename-table.hh"
12 #include "interval.hh"
13 #include "identifier.hh"
16 #include "my-lily-lexer.hh"
18 #include "source-file.hh"
19 #include "parseconstruct.hh"
23 static Keyword_ent the_key_tab[]={
24 {"spanrequest", SPANREQUEST},
26 {"alternative", ALTERNATIVE},
30 {"chordmodifiers", CHORDMODIFIERS},
34 {"consists", CONSISTS},
35 {"consistsend", CONSISTSEND},
37 {"duration", DURATION},
39 {"grouping", GROUPING},
45 {"keysignature", KEYSIGNATURE},
47 {"musicalpitch", MUSICAL_PITCH},
53 {"notenames", NOTENAMES},
58 {"property", PROPERTY},
60 {"relative", RELATIVE},
69 {"textscript", TEXTSCRIPT},
71 {"translator", TRANSLATOR},
72 {"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 SCM sym = ly_symbol (s.ch_C());
100 for (int i = scope_l_arr_.size (); i--; )
101 if (scope_l_arr_[i]->elem_b (sym))
102 return scope_l_arr_[i]->elem(sym);
107 My_lily_lexer::start_main_input ()
109 if (!monitor->silent_b ("InitDeclarations") && check_debug)
110 print_declarations (true);
111 if (!monitor->silent_b ("InitLexer") && check_debug)
115 new_input (main_input_str_, source_global_l);
117 allow_includes_b_ = false;
119 print_declarations(true);
123 My_lily_lexer::set_identifier (String name_str, Identifier* i, bool )
126 if (scope_l_arr_.top ()->elem_b (name_str))
127 old = scope_l_arr_.top ()->elem(name_str);
134 old->warning(_f ("redeclaration of `\\%s\'", name_str));
138 if (lookup_keyword (name_str) >= 0)
140 warning ( _f ("Identifier name is a keyword (`%s')", name_str));
143 scope_l_arr_.top ()->elem (name_str) = i;
146 My_lily_lexer::~My_lily_lexer()
148 delete chordmodifier_tab_p_;
150 delete toplevel_scope_p_ ;
155 My_lily_lexer::print_declarations (bool ) const
157 for (int i=scope_l_arr_.size (); i--; )
159 DOUT << "Scope no. " << i << '\n';
160 scope_l_arr_[i]->print ();
165 My_lily_lexer::LexerError (char const *s)
167 if (include_stack_.empty())
169 *mlog << _f ("error at EOF: %s", s) << endl;
174 Input spot (source_file_l(),here_ch_C());
180 My_lily_lexer::lookup_notename (String s)
182 return (*note_tab_p_)[s];
186 My_lily_lexer::lookup_chordmodifier (String s)
188 return (*chordmodifier_tab_p_)[s];
192 My_lily_lexer::notename_b (String s) const
194 return note_tab_p_->elem_b (s);
198 My_lily_lexer::set_notename_table (Notename_table *p)
205 My_lily_lexer::chordmodifier_b (String s) const
207 return chordmodifier_tab_p_->elem_b (s);
211 My_lily_lexer::set_chordmodifier_table (Notename_table *p)
213 delete chordmodifier_tab_p_;
214 chordmodifier_tab_p_ = p;
218 My_lily_lexer::escaped_char(char c) const