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 {"spanrequest", SPANREQUEST},
28 {"commandspanrequest", COMMANDSPANREQUEST},
29 {"simultaneous", SIMULTANEOUS},
30 {"sequential", SEQUENTIAL},
32 {"alternative", ALTERNATIVE},
36 {"chordmodifiers", CHORDMODIFIERS},
40 {"consists", CONSISTS},
41 {"consistsend", CONSISTSEND},
43 {"duration", DURATION},
51 {"musicalpitch", MUSICAL_PITCH},
57 {"notenames", NOTENAMES},
59 {"outputproperty", OUTPUTPROPERTY},
63 {"property", PROPERTY},
65 {"relative", RELATIVE},
68 {"addlyrics", ADDLYRICS},
72 {"textscript", TEXTSCRIPT},
74 {"translator", TRANSLATOR},
75 {"transpose", TRANSPOSE},
80 My_lily_lexer::My_lily_lexer()
82 keytable_p_ = new Keyword_table (the_key_tab);
83 toplevel_scope_p_ = new Scope;
84 scope_l_arr_.push (toplevel_scope_p_);
86 main_input_b_ = false;
90 My_lily_lexer::lookup_keyword (String s)
92 return keytable_p_->lookup (s.ch_C ());
96 My_lily_lexer::lookup_identifier (String s)
98 SCM sym = ly_symbol2scm (s.ch_C());
100 for (int i = scope_l_arr_.size (); i--; )
101 if (scope_l_arr_[i]->elem_b (sym))
102 return scope_l_arr_[i]->elem(sym);
107 My_lily_lexer::start_main_input ()
109 new_input (main_input_str_, source_global_l);
110 allow_includes_b_ = allow_includes_b_ && !(safe_global_b);
114 My_lily_lexer::set_identifier (String name_str, Identifier* i, bool )
117 if (scope_l_arr_.top ()->elem_b (name_str))
118 old = scope_l_arr_.top ()->elem(name_str);
125 if (lookup_keyword (name_str) >= 0)
127 warning ( _f ("Identifier name is a keyword: `%s'", name_str));
130 scope_l_arr_.top ()->set (name_str, i);
133 My_lily_lexer::~My_lily_lexer()
136 delete toplevel_scope_p_ ;
142 My_lily_lexer::LexerError (char const *s)
144 if (include_stack_.empty())
146 progress_indication (_f ("error at EOF: %s", s)+ String ("\n"));
151 Input spot (source_file_l(),here_ch_C());
157 My_lily_lexer::escaped_char(char c) const
175 My_lily_lexer::here_input () const
177 Source_file * f_l= source_file_l ();
178 return Input (f_l, (char*)here_ch_C ());