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"
23 static Keyword_ent the_key_tab[]={
24 {"autochange", AUTOCHANGE},
25 {"spanrequest", SPANREQUEST},
26 {"simultaneous", SIMULTANEOUS},
27 {"sequential", SEQUENTIAL},
29 {"alternative", ALTERNATIVE},
33 {"chordmodifiers", CHORDMODIFIERS},
37 {"consists", CONSISTS},
38 {"consistsend", CONSISTSEND},
40 {"duration", DURATION},
47 {"keysignature", KEYSIGNATURE},
49 {"musicalpitch", MUSICAL_PITCH},
55 {"notenames", NOTENAMES},
60 {"property", PROPERTY},
62 {"relative", RELATIVE},
65 {"repetitions", REPETITIONS},
66 {"addlyrics", ADDLYRICS},
73 {"textscript", TEXTSCRIPT},
75 {"translator", TRANSLATOR},
76 {"transpose", TRANSPOSE},
82 My_lily_lexer::My_lily_lexer()
84 keytable_p_ = new Keyword_table (the_key_tab);
85 toplevel_scope_p_ = new Scope;
86 scope_l_arr_.push (toplevel_scope_p_);
88 note_tab_p_ = new Notename_table;
89 chordmodifier_tab_p_ = new Notename_table;
90 main_input_b_ = false;
94 My_lily_lexer::lookup_keyword (String s)
96 return keytable_p_->lookup (s.ch_C ());
100 My_lily_lexer::lookup_identifier (String s)
102 SCM sym = ly_symbol (s.ch_C());
104 for (int i = scope_l_arr_.size (); i--; )
105 if (scope_l_arr_[i]->elem_b (sym))
106 return scope_l_arr_[i]->elem(sym);
111 My_lily_lexer::start_main_input ()
113 if (flower_dstream && !flower_dstream->silent_b ("InitDeclarations") && flower_dstream)
114 print_declarations (true);
115 if (flower_dstream && !flower_dstream->silent_b ("InitLexer") && flower_dstream)
119 new_input (main_input_str_, source_global_l);
121 allow_includes_b_ = false;
123 print_declarations(true);
127 My_lily_lexer::set_identifier (String name_str, Identifier* i, bool )
130 if (scope_l_arr_.top ()->elem_b (name_str))
131 old = scope_l_arr_.top ()->elem(name_str);
138 old->warning(_f ("redeclaration of `\\%s'", name_str));
142 if (lookup_keyword (name_str) >= 0)
144 warning ( _f ("Identifier name is a keyword: `%s'", name_str));
147 scope_l_arr_.top ()->elem (name_str) = i;
150 My_lily_lexer::~My_lily_lexer()
152 delete chordmodifier_tab_p_;
154 delete toplevel_scope_p_ ;
159 My_lily_lexer::print_declarations (bool ) const
161 for (int i=scope_l_arr_.size (); i--; )
163 DEBUG_OUT << "Scope no. " << i << '\n';
164 scope_l_arr_[i]->print ();
169 My_lily_lexer::LexerError (char const *s)
171 if (include_stack_.empty())
173 *mlog << _f ("error at EOF: %s", s) << endl;
178 Input spot (source_file_l(),here_ch_C());
184 My_lily_lexer::lookup_notename (String s)
186 return (*note_tab_p_)[s];
190 My_lily_lexer::lookup_chordmodifier (String s)
192 return (*chordmodifier_tab_p_)[s];
196 My_lily_lexer::notename_b (String s) const
198 return note_tab_p_->elem_b (s);
202 My_lily_lexer::set_notename_table (Notename_table *p)
209 My_lily_lexer::chordmodifier_b (String s) const
211 return chordmodifier_tab_p_->elem_b (s);
215 My_lily_lexer::set_chordmodifier_table (Notename_table *p)
217 delete chordmodifier_tab_p_;
218 chordmodifier_tab_p_ = p;
222 My_lily_lexer::escaped_char(char c) const
240 My_lily_lexer::here_input () const
242 Source_file * f_l= source_file_l ();
243 return Input (f_l, (char*)here_ch_C ());