lilypond-1.3.124
[lilypond.git] / lily / my-lily-lexer.cc
blob763c9e90db31db77dca1734640a5b18034bc61ea
1 /*
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>
7 */
9 #include <strstream.h>
10 #include <ctype.h>
12 #include "lily-proto.hh"
13 #include "scm-hash.hh"
14 #include "interval.hh"
16 #include "lily-guile.hh"
17 #include "parser.hh"
18 #include "keyword.hh"
19 #include "my-lily-lexer.hh"
20 #include "debug.hh"
21 #include "source-file.hh"
22 #include "main.hh"
23 #include "scope.hh"
24 #include "input.hh"
25 #include "moment.hh"
27 static Keyword_ent the_key_tab[]={
28 {"apply", APPLY},
29 {"arpeggio", ARPEGGIO },
30 {"autochange", AUTOCHANGE},
31 {"spanrequest", SPANREQUEST},
32 {"commandspanrequest", COMMANDSPANREQUEST},
33 {"simultaneous", SIMULTANEOUS},
34 {"sequential", SEQUENTIAL},
35 {"accepts", ACCEPTS},
36 {"alternative", ALTERNATIVE},
37 {"bar", BAR},
38 {"breathe", BREATHE},
39 {"char", CHAR_T},
40 {"chordmodifiers", CHORDMODIFIERS},
41 {"chords", CHORDS},
42 {"clef", CLEF},
43 {"cm", CM_T},
44 {"consists", CONSISTS},
45 {"consistsend", CONSISTSEND},
46 {"context", CONTEXT},
47 {"denies", DENIES},
48 {"duration", DURATION},
49 {"dynamicscript", DYNAMICSCRIPT},
50 {"elementdescriptions", ELEMENTDESCRIPTIONS},
51 {"font", FONT},
52 {"grace", GRACE},
53 {"glissando", GLISSANDO},
54 {"header", HEADER},
55 {"in", IN_T},
56 {"lyrics", LYRICS},
57 {"key", KEY},
58 {"mark", MARK},
59 {"pitch", PITCH},
60 {"time", TIME_T},
61 {"times", TIMES},
62 {"midi", MIDI},
63 {"mm", MM_T},
64 {"name", NAME},
65 {"pitchnames", PITCHNAMES},
66 {"notes", NOTES},
67 {"outputproperty", OUTPUTPROPERTY},
68 {"override", OVERRIDE},
69 {"set", SET},
70 {"revert", REVERT},
71 {"partial", PARTIAL},
72 {"paper", PAPER},
73 {"penalty", PENALTY},
74 {"property", PROPERTY},
75 {"pt", PT_T},
76 {"relative", RELATIVE},
77 {"remove", REMOVE},
78 {"repeat", REPEAT},
79 {"addlyrics", ADDLYRICS},
80 {"partcombine", PARTCOMBINE},
81 {"score", SCORE},
82 {"script", SCRIPT},
83 {"stylesheet", STYLESHEET},
84 {"skip", SKIP},
85 {"textscript", TEXTSCRIPT},
86 {"tempo", TEMPO},
87 {"translator", TRANSLATOR},
88 {"transpose", TRANSPOSE},
89 {"type", TYPE},
90 {0,0}
93 My_lily_lexer::My_lily_lexer()
95 keytable_p_ = new Keyword_table (the_key_tab);
96 toplevel_variable_tab_ = new Scheme_hash_table ;
97 scope_p_ = new Scope (toplevel_variable_tab_);
99 scope_l_arr_.push (scope_p_);
101 errorlevel_i_ = 0;
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))
120 return val;
122 return SCM_UNSPECIFIED;
125 void
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);
132 void
133 My_lily_lexer::set_identifier (String name_str, SCM s)
135 if (lookup_keyword (name_str) >= 0)
137 warning ( _f ("Identifier name is a keyword: `%s'", name_str));
140 scope_l_arr_.top ()->set (name_str, s);
143 My_lily_lexer::~My_lily_lexer()
145 delete keytable_p_;
146 scm_unprotect_object (toplevel_variable_tab_->self_scm ());
147 delete scope_p_ ;
152 void
153 My_lily_lexer::LexerError (char const *s)
155 if (include_stack_.empty())
157 progress_indication (_f ("error at EOF: %s", s)+ String ("\n"));
159 else
161 errorlevel_i_ |= 1;
162 Input spot (source_file_l(),here_ch_C());
163 spot.error (s);
167 char
168 My_lily_lexer::escaped_char(char c) const
170 switch(c)
172 case 'n':
173 return '\n';
174 case 't':
175 return '\t';
177 case '\'':
178 case '\"':
179 case '\\':
180 return c;
182 return 0;
185 Input
186 My_lily_lexer::here_input () const
188 Source_file * f_l= source_file_l ();
189 return Input (f_l, (char*)here_ch_C ());