2 my-lily-lexer.cc -- implement My_lily_lexer
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
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 {"arpeggio", ARPEGGIO },
28 {"spanrequest", SPANREQUEST},
29 {"commandspanrequest", COMMANDSPANREQUEST},
30 {"simultaneous", SIMULTANEOUS},
31 {"sequential", SEQUENTIAL},
33 {"alternative", ALTERNATIVE},
37 {"chordmodifiers", CHORDMODIFIERS},
41 {"consists", CONSISTS},
42 {"consistsend", CONSISTSEND},
45 {"duration", DURATION},
53 {"musicalpitch", MUSICAL_PITCH},
59 {"notenames", NOTENAMES},
61 {"outputproperty", OUTPUTPROPERTY},
67 {"property", PROPERTY},
69 {"relative", RELATIVE},
72 {"addlyrics", ADDLYRICS},
73 {"partcombine", PARTCOMBINE},
77 {"textscript", TEXTSCRIPT},
79 {"translator", TRANSLATOR},
80 {"transpose", TRANSPOSE},
85 My_lily_lexer::My_lily_lexer()
87 keytable_p_ = new Keyword_table (the_key_tab);
88 toplevel_scope_p_ = new Scope;
89 scope_l_arr_.push (toplevel_scope_p_);
91 main_input_b_ = false;
95 My_lily_lexer::lookup_keyword (String s)
97 return keytable_p_->lookup (s.ch_C ());
101 My_lily_lexer::lookup_identifier (String s)
103 SCM sym = ly_symbol2scm (s.ch_C());
105 for (int i = scope_l_arr_.size (); i--; )
107 SCM val = SCM_UNSPECIFIED;
108 if (scope_l_arr_[i]->try_retrieve (sym, &val))
111 return SCM_UNSPECIFIED;
115 My_lily_lexer::start_main_input ()
117 new_input (main_input_str_, source_global_l);
118 allow_includes_b_ = allow_includes_b_ && !(safe_global_b);
122 My_lily_lexer::set_identifier (String name_str, SCM s)
124 if (lookup_keyword (name_str) >= 0)
126 warning ( _f ("Identifier name is a keyword: `%s'", name_str));
129 scope_l_arr_.top ()->set (name_str, s);
132 My_lily_lexer::~My_lily_lexer()
135 delete toplevel_scope_p_ ;
141 My_lily_lexer::LexerError (char const *s)
143 if (include_stack_.empty())
145 progress_indication (_f ("error at EOF: %s", s)+ String ("\n"));
150 Input spot (source_file_l(),here_ch_C());
156 My_lily_lexer::escaped_char(char c) const
174 My_lily_lexer::here_input () const
176 Source_file * f_l= source_file_l ();
177 return Input (f_l, (char*)here_ch_C ());