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
28 %option yyclass="My_lily_lexer"
45 TEX {AA}|-|{PUNCT}|{ACCENT}|{NATIONAL}
57 LYRICS {AA}[^0-9 \t\n\f]*
62 <lyrics,INITIAL,notes>{COMMENT} {
70 <incl>{WHITE}* { /* eat the whitespace */ }
71 <incl>\"[^"]*\" { /* got the include file name */
72 String s (YYText()+1);
73 s = s.left_str(s.length_i()-1);
74 defined_ch_c_l = here_ch_c_l() - String( YYText() ).length_i() - 1;
80 const char *s = YYText();
81 yylval.string = new String (s);
82 mtor << "rest:"<< yylval.string;
85 <INITIAL,lyrics,notes>\$\\{BLACK}*{WHITE} {
86 String s=YYText() + 2;
87 s=s.left_str(s.length_i() - 1);
88 return scan_escaped_word(s);
90 <INITIAL,lyrics,notes>\${BLACK}*{WHITE} {
91 String s=YYText() + 1;
92 s=s.left_str(s.length_i() - 1);
93 return scan_bare_word(s);
96 return scan_bare_word(YYText());
100 <notes>{NOTECOMMAND} {
101 return scan_escaped_word(YYText()+1);
105 yylval.i = strlen(YYText());
109 yylval.i = String_convert::dec2_i( String( YYText() ) );
122 return yylval.c = YYText()[0];
130 *yylval.string +='\"';
133 *yylval.string += YYText();
136 mtor << "quoted string: `" << *yylval.string << "'\n";
145 yylval.i = strlen(YYText());
149 yylval.i = String_convert::dec2_i( String( YYText() ) );
152 <lyrics>{NOTECOMMAND} {
153 return scan_escaped_word(YYText()+1);
159 while ((i=s.index_i("_")) != -1) // change word binding "_" to " "
160 *(s.ch_l() + i) = ' ';
161 if ((i=s.index_i("\\,")) != -1) // change "\," to TeX's "\c "
163 *(s.ch_l() + i + 1) = 'c';
164 s = s.left_str(i+2) + " " + s.right_str(s.length_i()-i-2);
166 yylval.string = new String(s);
167 mtor << "lyric : `" << s << "'\n";
176 <lyrics>[()\[\]|/.^>_-] {
177 return yylval.c = YYText()[0];
186 yyterminate(); // can't move this, since it actually rets a YY_NULL
189 return scan_bare_word(YYText());
192 return scan_escaped_word(YYText()+1);
196 int cnv=sscanf (YYText(), "%lf", &r);
198 mtor << "REAL" << r<<'\n';
209 char c = YYText()[0];
210 mtor << "misc char" <<c<<"\n";
221 error( String( "illegal character: " ) + String( YYText()[0] ), here_ch_c_l() );
228 My_lily_lexer::push_note_state()
230 yy_push_state(notes);
234 My_lily_lexer::push_lyric_state()
236 yy_push_state(lyrics);
239 My_lily_lexer::pop_state()
245 My_lily_lexer::scan_escaped_word(String str)
247 mtor << "\\word: `" << str<<"'\n";
248 int l = lookup_keyword(str);
250 mtor << "(keyword)\n";
253 String *sp = new String( str);
258 My_lily_lexer::scan_bare_word(String str)
260 mtor << "word: `" << str<< "'\n";
261 Identifier * id = lookup_identifier(str);
263 mtor << "(identifier)\n";
265 return id->token_code_i_;
268 yylval.string=new String( str );
273 My_lily_lexer::note_state_b() const
275 return YY_START == notes;
279 My_lily_lexer::lyric_state_b() const
281 return YY_START == lyrics;