* stepmake/stepmake/metafont-rules.make: backport 1.7 fixes.
[lilypond.git] / lily / my-lily-lexer.cc
blob48005225d18c895bc4f3bf781d24df77ab1a55cb
1 /*
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>
7 */
9 #include <ctype.h>
11 #include <sstream>
13 #include "lily-proto.hh"
14 #include "scm-hash.hh"
15 #include "interval.hh"
16 #include "input-file-results.hh"
17 #include "lily-guile.hh"
18 #include "parser.hh"
19 #include "keyword.hh"
20 #include "my-lily-lexer.hh"
21 #include "warn.hh"
22 #include "source-file.hh"
23 #include "main.hh"
24 #include "input.hh"
25 #include "moment.hh"
27 static Keyword_ent the_key_tab[]={
28 {"alias", ALIAS},
29 {"apply", APPLY},
30 {"arpeggio", ARPEGGIO },
31 {"autochange", AUTOCHANGE},
32 {"spanrequest", SPANREQUEST},
33 {"commandspanrequest", COMMANDSPANREQUEST},
34 {"simultaneous", SIMULTANEOUS},
35 {"sequential", SEQUENTIAL},
36 {"accepts", ACCEPTS},
37 {"alternative", ALTERNATIVE},
38 {"bar", BAR},
39 {"breathe", BREATHE},
40 {"char", CHAR_T},
41 {"chordmodifiers", CHORDMODIFIERS},
42 {"chords", CHORDS},
43 {"clef", CLEF},
44 {"cm", CM_T},
45 {"consists", CONSISTS},
46 {"consistsend", CONSISTSEND},
47 {"context", CONTEXT},
48 {"default", DEFAULT},
49 {"denies", DENIES},
50 {"duration", DURATION},
51 {"dynamicscript", DYNAMICSCRIPT},
52 {"grobdescriptions", GROBDESCRIPTIONS},
53 {"figures",FIGURES},
54 {"grace", GRACE},
55 {"glissando", GLISSANDO},
56 {"header", HEADER},
57 {"in", IN_T},
58 {"lyrics", LYRICS},
59 {"key", KEY},
60 {"mark", MARK},
61 {"once", ONCE},
62 {"pitch", PITCH},
63 {"time", TIME_T},
64 {"times", TIMES},
65 {"midi", MIDI},
66 {"mm", MM_T},
67 {"name", NAME},
68 {"pitchnames", PITCHNAMES},
69 {"notes", NOTES},
70 {"outputproperty", OUTPUTPROPERTY},
71 {"override", OVERRIDE},
72 {"set", SET},
73 {"rest", REST},
74 {"revert", REVERT},
75 {"partial", PARTIAL},
76 {"paper", PAPER},
77 {"penalty", PENALTY},
78 {"property", PROPERTY},
79 {"pt", PT_T},
80 {"relative", RELATIVE},
81 {"remove", REMOVE},
82 {"repeat", REPEAT},
83 {"addlyrics", ADDLYRICS},
84 {"partcombine", PARTCOMBINE},
85 {"score", SCORE},
86 {"script", SCRIPT},
87 {"stylesheet", STYLESHEET},
88 {"skip", SKIP},
89 {"tempo", TEMPO},
90 {"translator", TRANSLATOR},
91 {"transpose", TRANSPOSE},
92 {"type", TYPE},
93 {"unset", UNSET},
94 {0,0}
97 My_lily_lexer::My_lily_lexer ()
99 keytable_ = new Keyword_table (the_key_tab);
100 toplevel_variable_tab_ = new Scheme_hash_table ;
101 scopes_.push (toplevel_variable_tab_);
103 errorlevel_ = 0;
104 main_input_b_ = false;
108 My_lily_lexer::lookup_keyword (String s)
110 return keytable_->lookup (s.to_str0 ());
114 My_lily_lexer::lookup_identifier (String s)
116 SCM sym = ly_symbol2scm (s.to_str0 ());
118 for (int i = scopes_.size (); i--;)
120 SCM val = SCM_UNSPECIFIED;
121 if (scopes_[i]->try_retrieve (sym, &val))
122 return val;
124 return SCM_UNSPECIFIED;
127 void
128 My_lily_lexer::start_main_input ()
130 new_input (main_input_string_, &global_input_file->sources_);
131 allow_includes_b_ = allow_includes_b_ && ! (safe_global_b);
134 void
135 My_lily_lexer::set_identifier (SCM name, SCM s)
137 assert (gh_string_p (name));
139 if (lookup_keyword (ly_scm2string (name)) >= 0)
141 size_t sz;
142 char * str = gh_scm2newstr (name, &sz) ;
143 warning (_f ("Identifier name is a keyword: `%s'", str));
144 free (str);
147 scopes_.top ()->set (scm_string_to_symbol (name), s);
150 My_lily_lexer::~My_lily_lexer ()
152 delete keytable_;
153 scm_gc_unprotect_object (toplevel_variable_tab_->self_scm ());
158 void
159 My_lily_lexer::LexerError (char const *s)
161 if (include_stack_.empty ())
163 progress_indication (_f ("error at EOF: %s", s)+ String ("\n"));
165 else
167 errorlevel_ |= 1;
168 Input spot (get_source_file (),here_str0 ());
169 spot.error (s);
173 char
174 My_lily_lexer::escaped_char (char c) const
176 switch (c)
178 case 'n':
179 return '\n';
180 case 't':
181 return '\t';
183 case '\'':
184 case '\"':
185 case '\\':
186 return c;
188 return 0;
191 Input
192 My_lily_lexer::here_input () const
194 Source_file * f= get_source_file ();
195 return Input (f, (char*)here_str0 ());