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[]={
27 {"arpeggio", ARPEGGIO },
28 {"autochange", AUTOCHANGE},
29 {"spanrequest", SPANREQUEST},
30 {"commandspanrequest", COMMANDSPANREQUEST},
31 {"simultaneous", SIMULTANEOUS},
32 {"sequential", SEQUENTIAL},
34 {"alternative", ALTERNATIVE},
38 {"chordmodifiers", CHORDMODIFIERS},
42 {"consists", CONSISTS},
43 {"consistsend", CONSISTSEND},
46 {"duration", DURATION},
47 {"dynamicscript", DYNAMICSCRIPT},
48 {"elementdescriptions", ELEMENTDESCRIPTIONS},
56 {"musicalpitch", MUSICAL_PITCH},
62 {"pitchnames", PITCHNAMES},
64 {"outputproperty", OUTPUTPROPERTY},
65 {"override", OVERRIDE},
71 {"property", PROPERTY},
73 {"relative", RELATIVE},
76 {"addlyrics", ADDLYRICS},
77 {"partcombine", PARTCOMBINE},
80 {"stylesheet", STYLESHEET},
82 {"textscript", TEXTSCRIPT},
84 {"translator", TRANSLATOR},
85 {"transpose", TRANSPOSE},
90 My_lily_lexer::My_lily_lexer()
92 keytable_p_ = new Keyword_table (the_key_tab);
93 toplevel_scope_p_ = new Scope;
94 scope_l_arr_.push (toplevel_scope_p_);
96 main_input_b_ = false;
100 My_lily_lexer::lookup_keyword (String s)
102 return keytable_p_->lookup (s.ch_C ());
106 My_lily_lexer::lookup_identifier (String s)
108 SCM sym = ly_symbol2scm (s.ch_C());
110 for (int i = scope_l_arr_.size (); i--; )
112 SCM val = SCM_UNSPECIFIED;
113 if (scope_l_arr_[i]->try_retrieve (sym, &val))
116 return SCM_UNSPECIFIED;
120 My_lily_lexer::start_main_input ()
122 new_input (main_input_str_, source_global_l);
123 allow_includes_b_ = allow_includes_b_ && !(safe_global_b);
127 My_lily_lexer::set_identifier (String name_str, SCM s)
129 if (lookup_keyword (name_str) >= 0)
131 warning ( _f ("Identifier name is a keyword: `%s'", name_str));
134 scope_l_arr_.top ()->set (name_str, s);
137 My_lily_lexer::~My_lily_lexer()
140 delete toplevel_scope_p_ ;
146 My_lily_lexer::LexerError (char const *s)
148 if (include_stack_.empty())
150 progress_indication (_f ("error at EOF: %s", s)+ String ("\n"));
155 Input spot (source_file_l(),here_ch_C());
161 My_lily_lexer::escaped_char(char c) const
179 My_lily_lexer::here_input () const
181 Source_file * f_l= source_file_l ();
182 return Input (f_l, (char*)here_ch_C ());