1 %{ // -*-Fundamental-*-
6 #include "string-convert.hh"
7 #include "my-lily-lexer.hh"
11 #include "input-score.hh"
12 #include "parseconstruct.hh"
14 #include "identifier.hh"
16 #define start_quote() \
17 yy_push_state(quote);\
18 yylval.string = new String
20 #define yylval (*(YYSTYPE*)lexval_l)
22 #define YY_USER_ACTION add_lexed_char(YYLeng());
29 %option yyclass="My_lily_lexer"
31 %option never-interactive
48 TEX {AA}|-|{PUNCT}|{ACCENT}|{NATIONAL}
60 LYRICS {AA}[^0-9 \t\n\f]*
65 <lyrics,INITIAL,notes>{COMMENT} {
70 <notes,INITIAL,lyrics>
74 <incl>{WHITE}* { /* eat the whitespace */ }
75 <incl>\"[^"]*\" { /* got the include file name */
76 String s (YYText()+1);
77 s = s.left_str(s.length_i()-1);
78 mtor << "#include `" << s << "\'\n";
79 new_input(s,source_l_g);
84 const char *s = YYText();
85 yylval.string = new String (s);
86 mtor << "rest:"<< yylval.string;
89 <INITIAL,lyrics,notes>\\\${BLACK}*{WHITE} {
90 String s=YYText() + 2;
91 s=s.left_str(s.length_i() - 1);
92 return scan_escaped_word(s);
94 <INITIAL,lyrics,notes>\${BLACK}*{WHITE} {
95 String s=YYText() + 1;
96 s=s.left_str(s.length_i() - 1);
97 return scan_bare_word(s);
99 <notes>{ALPHAWORD}/\' {
100 post_quotes_b_ = true;
101 return scan_bare_word(YYText());
105 if (post_quotes_b_) {
106 post_quotes_b_ = false;
112 return scan_bare_word(YYText());
116 <notes>{NOTECOMMAND} {
117 return scan_escaped_word(YYText()+1);
121 yylval.i = strlen(YYText());
125 yylval.i = String_convert::dec2_i( String( YYText() ) );
141 *yylval.string += '\\';
144 *yylval.string +='\"';
147 *yylval.string += YYText();
150 mtor << "quoted string: `" << *yylval.string << "'\n";
159 yylval.i = strlen(YYText());
163 yylval.i = String_convert::dec2_i( String( YYText() ) );
166 <lyrics>{NOTECOMMAND} {
167 return scan_escaped_word(YYText()+1);
173 while ((i=s.index_i("_")) != -1) // change word binding "_" to " "
174 *(s.ch_l() + i) = ' ';
175 if ((i=s.index_i("\\,")) != -1) // change "\," to TeX's "\c "
177 *(s.ch_l() + i + 1) = 'c';
178 s = s.left_str(i+2) + " " + s.right_str(s.length_i()-i-2);
180 yylval.string = new String(s);
181 mtor << "lyric : `" << s << "'\n";
190 <lyrics>[()\[\]|/.^>;_-] {
191 return yylval.c = YYText()[0];
197 if (! close_input()) {
198 yyterminate(); // can't move this, since it actually rets a YY_NULL
202 return scan_bare_word(YYText());
205 return scan_escaped_word(YYText()+1);
209 int cnv=sscanf (YYText(), "%lf", &r);
211 mtor << "REAL" << r<<'\n';
222 char c = YYText()[0];
223 mtor << "misc char" <<c<<"\n";
230 return yylval.c = YYText()[0];
232 <INITIAL,lyrics,notes>\\. {
241 return E_EXCLAMATION;
248 LexerError( String( "illegal character: " ) +String( YYText()[0] ));
255 My_lily_lexer::push_note_state()
257 yy_push_state(notes);
261 My_lily_lexer::push_lyric_state()
263 yy_push_state(lyrics);
266 My_lily_lexer::pop_state()
272 My_lily_lexer::scan_escaped_word(String str)
274 mtor << "\\word: `" << str<<"'\n";
275 int l = lookup_keyword(str);
277 mtor << "(keyword)\n";
280 Identifier * id = lookup_identifier(str);
282 mtor << "(identifier)\n";
284 return id->token_code_i_;
287 String *sp = new String( str);
293 My_lily_lexer::scan_bare_word(String str)
295 mtor << "word: `" << str<< "'\n";
296 if (YYSTATE == notes){
297 Melodic_req * mel_l = lookup_melodic_req_l(str);
299 mtor << "(notename)\n";
300 yylval.melreq = mel_l;
304 if (YYSTATE != notes) {
305 // ugr. Should do this in note mode?
306 Identifier * id = lookup_identifier(str);
308 mtor << "(identifier)\n";
310 return id->token_code_i_;
313 yylval.string=new String( str );
318 My_lily_lexer::note_state_b() const
320 return YY_START == notes;
324 My_lily_lexer::lyric_state_b() const
326 return YY_START == lyrics;