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>
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"
20 #include "my-lily-lexer.hh"
22 #include "source-file.hh"
27 static Keyword_ent the_key_tab
[]={
30 {"arpeggio", ARPEGGIO
},
31 {"autochange", AUTOCHANGE
},
32 {"spanrequest", SPANREQUEST
},
33 {"commandspanrequest", COMMANDSPANREQUEST
},
34 {"simultaneous", SIMULTANEOUS
},
35 {"sequential", SEQUENTIAL
},
37 {"alternative", ALTERNATIVE
},
41 {"chordmodifiers", CHORDMODIFIERS
},
45 {"consists", CONSISTS
},
46 {"consistsend", CONSISTSEND
},
50 {"duration", DURATION
},
51 {"dynamicscript", DYNAMICSCRIPT
},
52 {"grobdescriptions", GROBDESCRIPTIONS
},
55 {"glissando", GLISSANDO
},
68 {"pitchnames", PITCHNAMES
},
70 {"outputproperty", OUTPUTPROPERTY
},
71 {"override", OVERRIDE
},
78 {"property", PROPERTY
},
80 {"relative", RELATIVE
},
83 {"addlyrics", ADDLYRICS
},
84 {"partcombine", PARTCOMBINE
},
87 {"stylesheet", STYLESHEET
},
90 {"translator", TRANSLATOR
},
91 {"transpose", TRANSPOSE
},
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_
);
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
))
124 return SCM_UNSPECIFIED
;
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
);
135 My_lily_lexer::set_identifier (SCM name
, SCM s
)
137 assert (gh_string_p (name
));
139 if (lookup_keyword (ly_scm2string (name
)) >= 0)
142 char * str
= gh_scm2newstr (name
, &sz
) ;
143 warning (_f ("Identifier name is a keyword: `%s'", str
));
147 scopes_
.top ()->set (scm_string_to_symbol (name
), s
);
150 My_lily_lexer::~My_lily_lexer ()
153 scm_gc_unprotect_object (toplevel_variable_tab_
->self_scm ());
159 My_lily_lexer::LexerError (char const *s
)
161 if (include_stack_
.empty ())
163 progress_indication (_f ("error at EOF: %s", s
)+ String ("\n"));
168 Input
spot (get_source_file (),here_str0 ());
174 My_lily_lexer::escaped_char (char c
) const
192 My_lily_lexer::here_input () const
194 Source_file
* f
= get_source_file ();
195 return Input (f
, (char*)here_str0 ());