1 %{ // -*-Fundamental-*-
3 lexer.l -- implement the Flex lexer
5 source file of the LilyPond music typesetter
7 (c) 1996,1997 Han-Wen Nienhuys <hanwen@stack.nl>
14 #include "string-convert.hh"
15 #include "my-lily-lexer.hh"
19 #include "input-score.hh"
20 #include "parseconstruct.hh"
22 #include "identifier.hh"
24 #define start_quote() \
25 yy_push_state(quote);\
26 yylval.string = new String
28 #define yylval (*(YYSTYPE*)lexval_l)
30 #define YY_USER_ACTION add_lexed_char(YYLeng());
37 %option yyclass="My_lily_lexer"
39 %option never-interactive
56 TEX {AA}|-|{PUNCT}|{ACCENT}|{NATIONAL}
68 LYRICS ({AA}|{NATIONAL})[^0-9 \t\n\f]*
73 <notes,incl,INITIAL,lyrics>{
75 yy_push_state(longcomment);
97 <notes,INITIAL,lyrics>
101 <incl>\"[^"]*\" { /* got the include file name */
102 String s (YYText()+1);
103 s = s.left_str(s.length_i()-1);
104 mtor << "#include `" << s << "\'\n";
105 new_input(s,source_l_g);
109 const char *s = YYText();
110 yylval.string = new String (s);
111 mtor << "rest:"<< yylval.string;
114 <INITIAL,lyrics,notes>\\\${BLACK}*{WHITE} {
115 String s=YYText() + 2;
116 s=s.left_str(s.length_i() - 1);
117 return scan_escaped_word(s);
119 <INITIAL,lyrics,notes>\${BLACK}*{WHITE} {
120 String s=YYText() + 1;
121 s=s.left_str(s.length_i() - 1);
122 return scan_bare_word(s);
126 post_quotes_b_ = true;
127 return scan_bare_word(YYText());
131 if (post_quotes_b_) {
132 post_quotes_b_ = false;
138 return scan_bare_word(YYText());
143 return scan_escaped_word(YYText()+1);
147 yylval.i = strlen(YYText());
151 yylval.i = String_convert::dec2_i( String( YYText() ) );
168 *yylval.string += '\\';
171 *yylval.string +='\"';
174 *yylval.string += YYText();
177 mtor << "quoted string: `" << *yylval.string << "'\n";
189 yylval.i = strlen(YYText());
193 yylval.i = String_convert::dec2_i( String( YYText() ) );
197 return scan_escaped_word(YYText()+1);
203 while ((i=s.index_i("_")) != -1) // change word binding "_" to " "
204 *(s.ch_l() + i) = ' ';
205 if ((i=s.index_i("\\,")) != -1) // change "\," to TeX's "\c "
207 *(s.ch_l() + i + 1) = 'c';
208 s = s.left_str(i+2) + " " + s.right_str(s.length_i()-i-2);
210 yylval.string = new String(s);
211 mtor << "lyric : `" << s << "'\n";
215 return yylval.c = YYText()[0];
222 if (! close_input()) {
223 yyterminate(); // can't move this, since it actually rets a YY_NULL
227 return scan_bare_word(YYText());
230 return scan_escaped_word(YYText()+1);
234 int cnv=sscanf (YYText(), "%lf", &r);
236 mtor << "REAL" << r<<'\n';
247 char c = YYText()[0];
248 mtor << "misc char" <<c<<"\n";
253 return yylval.c = YYText()[0];
256 <INITIAL,lyrics,notes>\\. {
265 return E_EXCLAMATION;
272 LexerError( String( "illegal character: " ) +String( YYText()[0] ));
279 My_lily_lexer::push_note_state()
281 yy_push_state(notes);
285 My_lily_lexer::push_lyric_state()
287 yy_push_state(lyrics);
290 My_lily_lexer::pop_state()
296 My_lily_lexer::scan_escaped_word(String str)
298 mtor << "\\word: `" << str<<"'\n";
299 int l = lookup_keyword(str);
301 mtor << "(keyword)\n";
304 Identifier * id = lookup_identifier(str);
306 mtor << "(identifier)\n";
308 return id->token_code_i_;
311 String *sp = new String( str);
317 My_lily_lexer::scan_bare_word(String str)
319 mtor << "word: `" << str<< "'\n";
320 if (YYSTATE == notes){
321 Melodic_req * mel_l = lookup_melodic_req_l(str);
323 mtor << "(notename)\n";
324 yylval.melreq = mel_l;
328 if (YYSTATE != notes) {
329 // ugr. Should do this in note mode?
330 Identifier * id = lookup_identifier(str);
332 mtor << "(identifier)\n";
334 return id->token_code_i_;
337 yylval.string=new String( str );
342 My_lily_lexer::note_state_b() const
344 return YY_START == notes;
348 My_lily_lexer::lyric_state_b() const
350 return YY_START == lyrics;