2 my-lily-lexer.cc -- implement My_lily_lexer
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
13 #include "lily-proto.hh"
14 #include "scm-hash.hh"
15 #include "interval.hh"
17 #include "lily-guile.hh"
20 #include "my-lily-lexer.hh"
22 #include "source-file.hh"
27 static Keyword_ent the_key_tab[]={
30 {"arpeggio", ARPEGGIO },
31 {"autochange", AUTOCHANGE},
32 {"spanrequest", SPANREQUEST},
33 {"commandspanrequest", COMMANDSPANREQUEST},
34 {"simultaneous", SIMULTANEOUS},
35 {"sequential", SEQUENTIAL},
37 {"alternative", ALTERNATIVE},
41 {"chordmodifiers", CHORDMODIFIERS},
45 {"consists", CONSISTS},
46 {"consistsend", CONSISTSEND},
50 {"duration", DURATION},
51 {"dynamicscript", DYNAMICSCRIPT},
52 {"grobdescriptions", GROBDESCRIPTIONS},
55 {"glissando", GLISSANDO},
67 {"pitchnames", PITCHNAMES},
69 {"outputproperty", OUTPUTPROPERTY},
70 {"override", OVERRIDE},
77 {"property", PROPERTY},
79 {"relative", RELATIVE},
82 {"addlyrics", ADDLYRICS},
83 {"partcombine", PARTCOMBINE},
86 {"stylesheet", STYLESHEET},
89 {"translator", TRANSLATOR},
90 {"transpose", TRANSPOSE},
96 My_lily_lexer::My_lily_lexer ()
98 keytable_ = new Keyword_table (the_key_tab);
99 toplevel_variable_tab_ = new Scheme_hash_table ;
100 scopes_.push (toplevel_variable_tab_);
103 main_input_b_ = false;
107 My_lily_lexer::lookup_keyword (String s)
109 return keytable_->lookup (s.to_str0 ());
113 My_lily_lexer::lookup_identifier (String s)
115 SCM sym = ly_symbol2scm (s.to_str0 ());
117 for (int i = scopes_.size (); i--;)
119 SCM val = SCM_UNSPECIFIED;
120 if (scopes_[i]->try_retrieve (sym, &val))
123 return SCM_UNSPECIFIED;
127 My_lily_lexer::start_main_input ()
129 new_input (main_input_string_, source_global);
130 allow_includes_b_ = allow_includes_b_ && ! (safe_global_b);
134 My_lily_lexer::set_identifier (SCM name, SCM s)
136 assert (gh_string_p (name));
138 if (lookup_keyword (ly_scm2string (name)) >= 0)
141 char * str = gh_scm2newstr (name, &sz) ;
142 warning (_f ("Identifier name is a keyword: `%s'", str));
146 scopes_.top ()->set (scm_string_to_symbol (name), s);
149 My_lily_lexer::~My_lily_lexer ()
152 scm_gc_unprotect_object (toplevel_variable_tab_->self_scm ());
158 My_lily_lexer::LexerError (char const *s)
160 if (include_stack_.empty ())
162 progress_indication (_f ("error at EOF: %s", s)+ String ("\n"));
167 Input spot (get_source_file (),here_str0 ());
173 My_lily_lexer::escaped_char (char c) const
191 My_lily_lexer::here_input () const
193 Source_file * f= get_source_file ();
194 return Input (f, (char*)here_str0 ());