-%{ // -*-Fundamental-*-
+%{ // -*- mode: c++; c-file-style: "linux" -*-
/*
This file is part of LilyPond, the GNU music typesetter.
along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
*/
+/* Mode and indentation are at best a rough approximation based on TAB
+ * formatting (reasonable for compatibility with unspecific editor
+ * modes as Flex modes are hard to find) and need manual correction
+ * frequently. Without a reasonably dependable way of formatting a
+ * Flex file sensibly, there is little point in trying to fix the
+ * inconsistent state of indentation.
+ */
+
/*
backup rules
yy_push_state (lyric_quote);\
yylval.string = new string
-#define yylval \
- (*(YYSTYPE*)lexval_)
+#define yylval (*lexval_)
-#define yylloc \
- (*(YYLTYPE*)lexloc_)
+#define yylloc (*lexloc_)
#define YY_USER_ACTION add_lexed_char (YYLeng ());
<INITIAL,chords,lyrics,figures,notes>\\include {
yy_push_state (incl);
}
-<incl>\"[^"]*\" { /* got the include file name */
+<incl>\"[^""]*\" { /* got the include file name */
string s (YYText ()+1);
s = s.substr (0, s.rfind ('"'));
if (scm_is_string (sid)) {
new_input (ly_scm2string (sid), sources_);
yy_pop_state ();
- } else {
+ } else {
string msg (_f ("wrong or undefined identifier: `%s'", s ));
LexerError (msg.c_str ());
scm_display (sid, err);
}
}
-<incl,version,sourcefilename>\"[^"]* { // backup rule
+<incl>(\$|#) { // scm for the filename
+ int n = 0;
+ Input hi = here_input();
+ hi.step_forward ();
+ SCM sval = ly_parse_scm (hi.start (), &n, hi,
+ be_safe_global && is_main_input_, parser_);
+ sval = eval_scm (sval);
+
+ for (int i = 0; i < n; i++)
+ {
+ yyinput ();
+ }
+ char_count_stack_.back () += n;
+
+ if (scm_is_string (sval)) {
+ new_input (ly_scm2string (sval), sources_);
+ yy_pop_state ();
+ } else {
+ LexerError (_ ("string expected after \\include").c_str ());
+ if (sval != SCM_UNDEFINED) {
+ SCM err = scm_current_error_port ();
+ scm_puts ("This value was found instead: ", err);
+ scm_display (sval, err);
+ }
+ }
+}
+
+<incl,version,sourcefilename>\"[^""]* { // backup rule
error (_ ("end quote missing"));
exit (1);
}
}
char_count_stack_.back () += n;
- for (size_t i = 0; i < pending_string_includes_.size (); i++)
- new_input ("<included string>", pending_string_includes_[i],
- parser_->sources_);
- pending_string_includes_.clear ();
-
yylval.scm = sval;
return SCM_TOKEN;
}
hi.step_forward ();
SCM sval = ly_parse_scm (hi.start (), &n, hi,
be_safe_global && is_main_input_, parser_);
- sval = eval_scm (sval);
for (int i = 0; i < n; i++)
{
}
char_count_stack_.back () += n;
- return scan_scm_id (sval);
+ sval = eval_scm (sval);
+
+ int token = scan_scm_id (sval);
+ if (!scm_is_eq (yylval.scm, SCM_UNSPECIFIED))
+ return token;
}
<INITIAL,notes,lyrics>{
/*
- substitute _ and \,
+ substitute _
*/
string
lyric_fudge (string s)
{
- char *chars = string_copy (s);
+ size_t i=0;
- for (char *p = chars; *p ; p++)
- {
- if (*p == '_' && (p == chars || *(p-1) != '\\'))
- *p = ' ';
- }
-
- s = string (chars);
- delete[] chars;
-
- ssize i = 0;
- if ((i = s.find ("\\,")) != NPOS) // change "\," to TeX's "\c "
- {
- * (((char*)s.c_str ()) + i + 1) = 'c';
- s = s.substr (0, i + 2) + " " + s.substr (i - 2);
- }
-
- return s;
+ while ((i = s.find ('_', i)) != string::npos)
+ {
+ s[i++] = ' ';
+ }
+ return s;
}
/*