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>
12 #include "lily-proto.hh"
13 #include "scm-hash.hh"
14 #include "interval.hh"
16 #include "lily-guile.hh"
19 #include "my-lily-lexer.hh"
21 #include "source-file.hh"
26 static Keyword_ent the_key_tab[]={
29 {"arpeggio", ARPEGGIO },
30 {"autochange", AUTOCHANGE},
31 {"spanrequest", SPANREQUEST},
32 {"commandspanrequest", COMMANDSPANREQUEST},
33 {"simultaneous", SIMULTANEOUS},
34 {"sequential", SEQUENTIAL},
36 {"alternative", ALTERNATIVE},
40 {"chordmodifiers", CHORDMODIFIERS},
44 {"consists", CONSISTS},
45 {"consistsend", CONSISTSEND},
49 {"duration", DURATION},
50 {"dynamicscript", DYNAMICSCRIPT},
51 {"grobdescriptions", GROBDESCRIPTIONS},
54 {"glissando", GLISSANDO},
66 {"pitchnames", PITCHNAMES},
68 {"outputproperty", OUTPUTPROPERTY},
69 {"override", OVERRIDE},
76 {"property", PROPERTY},
78 {"relative", RELATIVE},
81 {"addlyrics", ADDLYRICS},
82 {"partcombine", PARTCOMBINE},
85 {"stylesheet", STYLESHEET},
88 {"translator", TRANSLATOR},
89 {"transpose", TRANSPOSE},
95 My_lily_lexer::My_lily_lexer ()
97 keytable_p_ = new Keyword_table (the_key_tab);
98 toplevel_variable_tab_ = new Scheme_hash_table ;
99 scope_l_arr_.push (toplevel_variable_tab_);
102 main_input_b_ = false;
106 My_lily_lexer::lookup_keyword (String s)
108 return keytable_p_->lookup (s.ch_C ());
112 My_lily_lexer::lookup_identifier (String s)
114 SCM sym = ly_symbol2scm (s.ch_C ());
116 for (int i = scope_l_arr_.size (); i--;)
118 SCM val = SCM_UNSPECIFIED;
119 if (scope_l_arr_[i]->try_retrieve (sym, &val))
122 return SCM_UNSPECIFIED;
126 My_lily_lexer::start_main_input ()
128 new_input (main_input_str_, source_global_l);
129 allow_includes_b_ = allow_includes_b_ && ! (safe_global_b);
133 My_lily_lexer::set_identifier (SCM name, SCM s)
135 assert (gh_string_p (name));
137 if (lookup_keyword (ly_scm2string (name)) >= 0)
140 char * str = gh_scm2newstr (name, &sz) ;
141 warning (_f ("Identifier name is a keyword: `%s'", str));
145 scope_l_arr_.top ()->set (scm_string_to_symbol (name), s);
148 My_lily_lexer::~My_lily_lexer ()
151 scm_gc_unprotect_object (toplevel_variable_tab_->self_scm ());
157 My_lily_lexer::LexerError (char const *s)
159 if (include_stack_.empty ())
161 progress_indication (_f ("error at EOF: %s", s)+ String ("\n"));
166 Input spot (source_file_l (),here_ch_C ());
172 My_lily_lexer::escaped_char (char c) const
190 My_lily_lexer::here_input () const
192 Source_file * f_l= source_file_l ();
193 return Input (f_l, (char*)here_ch_C ());