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"
24 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 {"melodic_request", MELODIC_REQUEST},
48 {"notenames", NOTENAMES},
53 {"property", PROPERTY},
61 {"spandynamic", SPANDYNAMIC},
62 {"symboltables", SYMBOLTABLES},
65 {"textstyle", TEXTSTYLE},
66 {"transpose", TRANSPOSE},
68 {"grouping", GROUPING},
72 My_lily_lexer::My_lily_lexer()
74 keytable_p_ = new Keyword_table (the_key_tab);
75 identifier_p_dict_p_ = new Dictionary<Identifier*>;
77 post_quotes_b_ = false;
78 note_tab_p_ = new Notename_table;
82 My_lily_lexer::lookup_keyword (String s)
84 return keytable_p_->lookup (s.ch_C ());
88 My_lily_lexer::lookup_identifier (String s)
90 if (!identifier_p_dict_p_->elt_b (s))
93 return (*identifier_p_dict_p_)[s];
97 My_lily_lexer::start_main_input ()
99 if (!monitor->silent_b ("InitDeclarations") && check_debug)
100 print_declarations (true);
101 if (!monitor->silent_b ("InitLexer") && check_debug)
104 new_input (main_input_str_, source_global_l);
106 print_declarations(true);
110 My_lily_lexer::set_identifier (String name_str, Identifier*i)
112 Identifier *old = lookup_identifier (name_str);
115 old->warning(_("redeclaration of \\") + name_str);
118 (*identifier_p_dict_p_)[name_str] = i;
121 My_lily_lexer::~My_lily_lexer()
125 for (Assoc_iter<String,Identifier*>
126 ai (*identifier_p_dict_p_); ai.ok(); ai++)
128 DOUT << "deleting: " << ai.key()<<'\n';
132 delete identifier_p_dict_p_;
135 My_lily_lexer::print_declarations (bool init_b) const
137 for (Assoc_iter<String,Identifier*> ai (*identifier_p_dict_p_);
140 if (ai.val()->init_b_ == init_b)
142 DOUT << ai.key() << '=';
149 My_lily_lexer::LexerError (char const *s)
151 if (include_stack_.empty())
153 *mlog << _("error at EOF") << s << '\n';
158 Input spot (source_file_l(),here_ch_C());
164 My_lily_lexer::lookup_melodic_req_l (String s)
166 return note_tab_p_->get_l (s);
170 My_lily_lexer::add_notename (String s, Melodic_req *p)
172 note_tab_p_->add (s,p);
176 My_lily_lexer::clear_notenames()
179 note_tab_p_ = new Notename_table;
183 My_lily_lexer::escaped_char(char c) const