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"
14 #include "lily-guile.hh"
17 #include "my-lily-lexer.hh"
19 #include "source-file.hh"
25 static Keyword_ent the_key_tab
[]={
26 {"autochange", AUTOCHANGE
},
27 {"spanrequest", SPANREQUEST
},
28 {"simultaneous", SIMULTANEOUS
},
29 {"sequential", SEQUENTIAL
},
31 {"alternative", ALTERNATIVE
},
34 {"chordmodifiers", CHORDMODIFIERS
},
38 {"consists", CONSISTS
},
39 {"consistsend", CONSISTSEND
},
41 {"duration", DURATION
},
48 {"keysignature", KEYSIGNATURE
},
50 {"musicalpitch", MUSICAL_PITCH
},
56 {"notenames", NOTENAMES
},
61 {"property", PROPERTY
},
63 {"relative", RELATIVE
},
66 {"repetitions", REPETITIONS
},
67 {"addlyrics", ADDLYRICS
},
71 {"textscript", TEXTSCRIPT
},
73 {"translator", TRANSLATOR
},
74 {"transpose", TRANSPOSE
},
79 My_lily_lexer::My_lily_lexer()
81 keytable_p_
= new Keyword_table (the_key_tab
);
82 toplevel_scope_p_
= new Scope
;
83 scope_l_arr_
.push (toplevel_scope_p_
);
85 note_tab_p_
= new Notename_table
;
86 chordmodifier_tab_p_
= new Notename_table
;
87 main_input_b_
= false;
91 My_lily_lexer::lookup_keyword (String s
)
93 return keytable_p_
->lookup (s
.ch_C ());
97 My_lily_lexer::lookup_identifier (String s
)
99 SCM sym
= ly_symbol2scm (s
.ch_C());
101 for (int i
= scope_l_arr_
.size (); i
--; )
102 if (scope_l_arr_
[i
]->elem_b (sym
))
103 return scope_l_arr_
[i
]->elem(sym
);
108 My_lily_lexer::start_main_input ()
110 if (flower_dstream
&& !flower_dstream
->silent_b ("InitDeclarations") && flower_dstream
)
111 print_declarations (true);
112 if (flower_dstream
&& !flower_dstream
->silent_b ("InitLexer") && flower_dstream
)
116 new_input (main_input_str_
, source_global_l
);
118 allow_includes_b_
= false;
120 print_declarations(true);
124 My_lily_lexer::set_identifier (String name_str
, Identifier
* i
, bool )
127 if (scope_l_arr_
.top ()->elem_b (name_str
))
128 old
= scope_l_arr_
.top ()->elem(name_str
);
135 old
->warning(_f ("redeclaration of `\\%s'", name_str
));
139 if (lookup_keyword (name_str
) >= 0)
141 warning ( _f ("Identifier name is a keyword: `%s'", name_str
));
144 scope_l_arr_
.top ()->elem (name_str
) = i
;
147 My_lily_lexer::~My_lily_lexer()
149 delete chordmodifier_tab_p_
;
151 delete toplevel_scope_p_
;
156 My_lily_lexer::print_declarations (bool ) const
158 for (int i
=scope_l_arr_
.size (); i
--; )
160 DEBUG_OUT
<< "Scope no. " << i
<< '\n';
161 scope_l_arr_
[i
]->print ();
166 My_lily_lexer::LexerError (char const *s
)
168 if (include_stack_
.empty())
170 progress_indication (_f ("error at EOF: %s", s
)+ String ("\n"));
175 Input
spot (source_file_l(),here_ch_C());
181 My_lily_lexer::lookup_notename (String s
)
183 return note_tab_p_
->get_pitch (s
);
187 My_lily_lexer::lookup_chordmodifier (String s
)
189 return chordmodifier_tab_p_
->get_pitch (s
);
193 My_lily_lexer::notename_b (String s
) const
195 return note_tab_p_
->elem_b (s
);
199 My_lily_lexer::set_notename_table (Notename_table
*p
)
206 My_lily_lexer::chordmodifier_b (String s
) const
208 return chordmodifier_tab_p_
->elem_b (s
);
212 My_lily_lexer::set_chordmodifier_table (Notename_table
*p
)
214 delete chordmodifier_tab_p_
;
215 chordmodifier_tab_p_
= p
;
219 My_lily_lexer::escaped_char(char c
) const
237 My_lily_lexer::here_input () const
239 Source_file
* f_l
= source_file_l ();
240 return Input (f_l
, (char*)here_ch_C ());