ANY_CHAR (.|\n)
PUNCT [?!:'`]
ACCENT \\[`'"^]
+SPECIAL_CHAR [&@]
NATIONAL [\001-\006\021-\027\031\036]
-TEX {AA}|-|{PUNCT}|{ACCENT}|{NATIONAL}
-WORD {A}{AN}*
+TEX {AA}|-|{PUNCT}|{ACCENT}|{NATIONAL}|{SPECIAL_CHAR}
DASHED_WORD {A}({AN}|-)*
DASHED_KEY_WORD \\{DASHED_WORD}
ALPHAWORD {A}+
-DIGIT {N}
UNSIGNED {N}+
E_UNSIGNED \\{N}+
FRACTION {N}+\/{N}+
INT -?{UNSIGNED}
REAL ({INT}\.{N}*)|(-?\.{N}+)
-KEYWORD \\{WORD}
WHITE [ \n\t\f\r]
HORIZONTALWHITE [ \t]
BLACK [^ \n\t\f\r]
<*>\r {
- // windows-suck-suck-suck
+ // swallow and ignore carriage returns
}
<extratoken>{ANY_CHAR} {
yyless (0);
/* produce requested token */
- int type = extra_token_types_.back ();
- extra_token_types_.pop_back ();
- if (extra_token_types_.empty ())
+ int type = scm_to_int (scm_caar (extra_tokens_));
+ yylval.scm = scm_cdar (extra_tokens_);
+ extra_tokens_ = scm_cdr (extra_tokens_);
+ if (scm_is_null (extra_tokens_))
+ yy_pop_state ();
+
+ return type;
+}
+
+<extratoken><<EOF>> {
+ /* Generate a token without swallowing anything */
+
+ /* produce requested token */
+ int type = scm_to_int (scm_caar (extra_tokens_));
+ yylval.scm = scm_cdar (extra_tokens_);
+ extra_tokens_ = scm_cdr (extra_tokens_);
+ if (scm_is_null (extra_tokens_))
yy_pop_state ();
return type;
<INITIAL,chords,lyrics,figures,notes>{BOM_UTF8}/.* {
if (this->lexloc_->line_number () != 1 || this->lexloc_->column_number () != 0)
{
- LexerError (_ ("stray UTF-8 BOM encountered").c_str ());
- exit (1);
+ LexerWarning (_ ("stray UTF-8 BOM encountered").c_str ());
+ // exit (1);
}
- if (be_verbose_global)
- message (_ ("Skipping UTF-8 BOM"));
+ debug_output (_ ("Skipping UTF-8 BOM"));
}
<INITIAL,chords,figures,incl,lyrics,markup,notes>{
this->here_input ().get_source_file ()->set_line (here_input ().start (), i);
}
-<version>. {
+<version>{ANY_CHAR} {
LexerError (_ ("quoted string expected after \\version").c_str ());
yy_pop_state ();
}
-<sourcefilename>. {
+<sourcefilename>{ANY_CHAR} {
LexerError (_ ("quoted string expected after \\sourcefilename").c_str ());
yy_pop_state ();
}
-<sourcefileline>. {
+<sourcefileline>{ANY_CHAR} {
LexerError (_ ("integer expected after \\sourcefileline").c_str ());
yy_pop_state ();
}
"%"+"}" {
yy_pop_state ();
}
- <<EOF>> {
- LexerError (_ ("EOF found inside a comment").c_str ());
- is_main_input_ = false; // should be safe , can't have \include in --safe.
- if (! close_input ())
- yyterminate (); // can't move this, since it actually rets a YY_NULL
- }
}
new_input (s, sources_);
yy_pop_state ();
}
-<incl>\\{BLACK}*{WHITE} { /* got the include identifier */
+<incl>\\{BLACK}*{WHITE}? { /* got the include identifier */
string s = YYText () + 1;
strip_trailing_white (s);
if (s.length () && (s[s.length () - 1] == ';'))
scm_display (sid, err);
}
}
-<incl>\"[^"]* { // backup rule
+<incl,version,sourcefilename>\"[^"]* { // backup rule
error (_ ("end quote missing"));
exit (1);
}
yylval.scm = scan_fraction (YYText ());
return FRACTION;
}
-
- {DIGIT} {
- yylval.i = String_convert::dec2int (string (YYText ()));
- return DIGIT;
- }
+ {UNSIGNED}/\/ | // backup rule
{UNSIGNED} {
yylval.i = String_convert::dec2int (string (YYText ()));
return UNSIGNED;
yylval.scm = scan_fraction (YYText ());
return FRACTION;
}
+ {UNSIGNED}/\/[^0-9] { // backup rule
+ yylval.i = String_convert::dec2int (string (YYText ()));
+ return UNSIGNED;
+ }
+ {UNSIGNED}/\/ | // backup rule
{UNSIGNED} {
yylval.i = String_convert::dec2int (string (YYText ()));
return UNSIGNED;
yylval.scm = scan_fraction (YYText ());
return FRACTION;
}
+ {UNSIGNED}/\/[^0-9] { // backup rule
+ yylval.i = String_convert::dec2int (string (YYText ()));
+ return UNSIGNED;
+ }
+ {UNSIGNED}/\/ | // backup rule
{UNSIGNED} {
yylval.i = String_convert::dec2int (string (YYText ()));
return UNSIGNED;
else if (predicate == ly_lily_module_constant ("markup?"))
push_extra_token(EXPECT_MARKUP);
else
- push_extra_token(EXPECT_SCM);
+ push_extra_token(EXPECT_SCM, predicate);
}
return token_type;
}
[{}] {
return YYText ()[0];
}
- [^#{}"\\ \t\n\r\f]+ {
+ [^#{}\"\\ \t\n\r\f]+ {
string s (YYText ());
char c = s[s.length () - 1];
}
}
-<*><<EOF>> {
- if (is_main_input_)
+<longcomment><<EOF>> {
+ LexerError (_ ("EOF found inside a comment").c_str ());
+ is_main_input_ = false; // should be safe , can't have \include in --safe.
+ if (!close_input ())
+ yyterminate (); // can't move this, since it actually rets a YY_NULL
+ }
+
+<<EOF>> { if (is_main_input_)
{
/* 2 = init.ly + current file.
> because we're before closing, but is_main_input_ should
}
}
-{WORD} {
- return scan_bare_word (YYText ());
-}
-{KEYWORD} {
- return scan_escaped_word (YYText () + 1);
-}
+-{UNSIGNED} | // backup rule
{REAL} {
Real r;
int cnv = sscanf (YYText (), "%lf", &r);
yylval.scm = scm_from_double (r);
return REAL;
}
+-\. { // backup rule
+ yylval.scm = scm_from_double (0.0);
+ return REAL;
+}
{UNSIGNED} {
yylval.i = String_convert::dec2int (string (YYText ()));
/* Make the lexer generate a token of the given type as the next token.
TODO: make it possible to define a value for the token as well */
void
-Lily_lexer::push_extra_token (int token_type)
+Lily_lexer::push_extra_token (int token_type, SCM scm)
{
- if (extra_token_types_.empty ())
+ if (scm_is_null (extra_tokens_))
{
if (YY_START != extratoken)
hidden_state_ = YY_START;
yy_push_state (extratoken);
}
- extra_token_types_.push_back (token_type);
+ extra_tokens_ = scm_acons (scm_from_int (token_type), scm, extra_tokens_);
}
void
SCM sid = lookup_identifier (str);
if (is_music_function (sid))
{
+ int funtype = SCM_FUNCTION;
+
yylval.scm = get_music_function_transform (sid);
SCM s = scm_object_property (yylval.scm, ly_symbol2scm ("music-function-signature"));
+ SCM cs = scm_car (s);
+
+ if (scm_is_pair (cs))
+ {
+ cs = SCM_CAR (cs);
+ }
+
+ if (scm_is_eq (cs, ly_lily_module_constant ("ly:music?")))
+ funtype = MUSIC_FUNCTION;
+ else if (scm_is_eq (cs, ly_lily_module_constant ("ly:event?")))
+ funtype = EVENT_FUNCTION;
+ else if (ly_is_procedure (cs))
+ funtype = SCM_FUNCTION;
+ else programming_error ("Bad syntax function predicate");
+
push_extra_token (EXPECT_NO_MORE_ARGS);
- for (; scm_is_pair (s); s = scm_cdr (s))
+ for (s = scm_cdr (s); scm_is_pair (s); s = scm_cdr (s))
{
- SCM cs = scm_car (s);
+ SCM optional = SCM_UNDEFINED;
+ cs = scm_car (s);
+
+ if (scm_is_pair (cs))
+ {
+ optional = SCM_CDR (cs);
+ cs = SCM_CAR (cs);
+ }
if (cs == ly_music_p_proc)
push_extra_token (EXPECT_MUSIC);
else if (cs == ly_lily_module_constant ("markup?"))
push_extra_token (EXPECT_MARKUP);
else if (ly_is_procedure (cs))
- push_extra_token (EXPECT_SCM);
- else programming_error ("Function parameter without type-checking predicate");
+ push_extra_token (EXPECT_SCM, cs);
+ else
+ {
+ programming_error ("Function parameter without type-checking predicate");
+ continue;
+ }
+ if (!scm_is_eq (optional, SCM_UNDEFINED))
+ push_extra_token (EXPECT_OPTIONAL, optional);
}
- return MUSIC_FUNCTION;
+ return funtype;
}
if (sid != SCM_UNDEFINED)