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 "lily-proto.hh"
13 #include "scm-hash.hh"
14 #include "interval.hh"
16 #include "lily-guile.hh"
19 #include "my-lily-lexer.hh"
21 #include "source-file.hh"
27 static Keyword_ent the_key_tab
[]={
29 {"arpeggio", ARPEGGIO
},
30 {"autochange", AUTOCHANGE
},
31 {"spanrequest", SPANREQUEST
},
32 {"commandspanrequest", COMMANDSPANREQUEST
},
33 {"simultaneous", SIMULTANEOUS
},
34 {"sequential", SEQUENTIAL
},
36 {"alternative", ALTERNATIVE
},
40 {"chordmodifiers", CHORDMODIFIERS
},
44 {"consists", CONSISTS
},
45 {"consistsend", CONSISTSEND
},
48 {"duration", DURATION
},
49 {"dynamicscript", DYNAMICSCRIPT
},
50 {"elementdescriptions", ELEMENTDESCRIPTIONS
},
53 {"glissando", GLISSANDO
},
65 {"pitchnames", PITCHNAMES
},
67 {"outputproperty", OUTPUTPROPERTY
},
68 {"override", OVERRIDE
},
74 {"property", PROPERTY
},
76 {"relative", RELATIVE
},
79 {"addlyrics", ADDLYRICS
},
80 {"partcombine", PARTCOMBINE
},
83 {"stylesheet", STYLESHEET
},
85 {"textscript", TEXTSCRIPT
},
87 {"translator", TRANSLATOR
},
88 {"transpose", TRANSPOSE
},
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_
);
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
))
122 return SCM_UNSPECIFIED
;
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
);
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()
146 scm_unprotect_object (toplevel_variable_tab_
->self_scm ());
153 My_lily_lexer::LexerError (char const *s
)
155 if (include_stack_
.empty())
157 progress_indication (_f ("error at EOF: %s", s
)+ String ("\n"));
162 Input
spot (source_file_l(),here_ch_C());
168 My_lily_lexer::escaped_char(char c
) const
186 My_lily_lexer::here_input () const
188 Source_file
* f_l
= source_file_l ();
189 return Input (f_l
, (char*)here_ch_C ());