* lily/lexer.ll: Grok \encoding.
2004-04-05 Jan Nieuwenhuizen <janneke@gnu.org>
+ * lily/my-lily-lexer.cc (set_encoding): New method.
+
+ * lily/lexer.ll: Grok \encoding.
+
* lily/font-metric.cc (get_encoded_index): New function.
* lily/include/font-metric.hh (coding_scheme): New method.
return;
}
- Source_file * sl = global_sources->get_file (s);
+ Source_file *sl = global_sources->get_file (s);
if (!sl)
{
String msg = _f ("can't find file: `%s'", s);
msg += "\n";
- msg += _f ("(search path: `%s')", global_sources->path_->to_string ().to_str0 ());
+ msg += _f ("(search path: `%s')",
+ global_sources->path_->to_string ().to_str0 ());
msg += "\n";
LexerError (msg.to_str0 ());
-
return;
}
filename_strings_.push (sl->name_string ());
Protected_scm scopes_;
public:
String main_input_name_;
- void * lexval;
+ String encoding_;
+ void *lexval;
bool main_input_b_;
/*
void push_lyric_state ();
void pop_state ();
void LexerError (char const *);
+ void set_encoding (String);
void set_identifier (SCM name_string, SCM);
bool is_note_state () const;
bool is_chord_state () const;
+/*
+ source-file.hh -- declare Source_file
+
+ source file of the GNU LilyPond music typesetter
+
+ (c) 1999--2004 Jan Nieuwenhuizen <janneke@gnu.org>
+*/
#ifndef SOURCE_FILE_HH
#define SOURCE_FILE_HH
Protected_scm str_port_;
};
-char * gulp_file (String fn, int *len);
+char *gulp_file (String fn, int *len);
-#endif // SOURCE_FILE_HH //
+#endif /* SOURCE_FILE_HH */
void strip_leading_white (String&);
String lyric_fudge (String s);
-SCM
-lookup_markup_command (String s);
-
-bool
-is_valid_version (String s);
-
+SCM lookup_markup_command (String s);
+bool is_valid_version (String s);
#define start_quote() \
%option never-interactive
%option warn
+%x encoding
%x renameinput
%x version
%x chords
}
}
+<INITIAL>\\encoding{WHITE}* {
+ yy_push_state (encoding);
+}
<INITIAL,chords,lyrics,notes,figures>\\version{WHITE}* {
yy_push_state (version);
}
<INITIAL,chords,lyrics,notes,figures>\\renameinput{WHITE}* {
yy_push_state (renameinput);
}
+<encoding>\"[^"]*\" {
+ String s (YYText () + 1);
+ s = s.left_string (s.index_last ('\"'));
+ set_encoding (s);
+ yy_pop_state ();
+}
<version>\"[^"]*\" { /* got the version number */
- String s (YYText ()+1);
+ String s (YYText () + 1);
s = s.left_string (s.index_last ('\"'));
- yy_pop_state();
- if (!is_valid_version (s))
+ yy_pop_state ();
+ if (!is_valid_version (s))
return INVALID;
}
-<renameinput>\"[^"]*\" { /* got the version number */
+<renameinput>\"[^"]*\" {
String s (YYText ()+1);
s = s.left_string (s.index_last ('\"'));
scm_makfrom0str (s.to_str0()));
}
-
+<encoding>. {
+ LexerError (_ ("No quoted string found after \\encoding").to_str0 ());
+ yy_pop_state ();
+}
<version>. {
- LexerError ("No quoted string found after \\version");
+ LexerError (_ ("No quoted string found after \\version").to_str0 ());
yy_pop_state ();
}
<renameinput>. {
- LexerError ("No quoted string found after \\renameinput");
+ LexerError (_ ("No quoted string found after \\renameinput").to_str0 ());
yy_pop_state ();
}
<longcomment>{
return '>';
}
{MARKUPCOMMAND} {
- String str (YYText() + 1);
+ String str (YYText () + 1);
SCM s = lookup_markup_command (str);
if (gh_pair_p (s) && gh_symbol_p (gh_cdr (s)) ) {
return MARKUP_HEAD_SCM0_MARKUP1;
else if (tag == ly_symbol2scm ("scheme0-scheme1-markup2"))
return MARKUP_HEAD_SCM0_SCM1_MARKUP2;
- else if (tag == ly_symbol2scm ("scheme0-scheme1-scheme2"))
+ else if (tag ==4 ly_symbol2scm ("scheme0-scheme1-scheme2"))
return MARKUP_HEAD_SCM0_SCM1_SCM2;
else {
programming_error ("No parser tag defined for this signature. Abort");
return scan_escaped_word (str);
}
[{}] {
- return YYText()[0];
+ return YYText ()[0];
}
[^#{}"\\ \t\n\r\f]+ {
String s (YYText ());
char c = s[s.length () - 1];
- if (c == '{' || c == '}') // brace open is for not confusing dumb tools.
+ /* brace open is for not confusing dumb tools. */
+ if (c == '{' || c == '}')
here_input ().warning (
_ ("Brace found at end of markup. Did you forget a space?"));
yylval.scm = scm_makfrom0str (s.to_str0 ());
lookup_markup_command (String s)
{
SCM proc = ly_scheme_function ("lookup-markup-command");
-
return scm_call_1 (proc, scm_makfrom0str (s.to_str0 ()));
}
#include "ly-module.hh"
-static Keyword_ent the_key_tab[]={
+static Keyword_ent the_key_tab[] = {
{"acciaccatura", ACCIACCATURA},
{"accepts", ACCEPTS},
{"addlyrics", ADDLYRICS},
{"type", TYPE},
{"unset", UNSET},
{"with", WITH},
- {0,0}
+ {0, 0}
};
scopes_ = SCM_EOL;
add_scope (ly_make_anonymous_module ());
- errorlevel_ =0;
+ errorlevel_ = 0;
main_input_b_ = false;
}
scm_set_current_module (module);
for (SCM s = scopes_; gh_pair_p (s); s = gh_cdr (s))
{
- /*
- UGH. how to do this more neatly?
- */
- SCM expr = scm_list_n (ly_symbol2scm ("module-use!"),
- module, scm_list_n (ly_symbol2scm ("module-public-interface"),
- gh_car (s), SCM_UNDEFINED),
- SCM_UNDEFINED);
-
+ /* UGH. how to do this more neatly? */
+ SCM expr
+ = scm_list_3 (ly_symbol2scm ("module-use!"),
+ module,
+ scm_list_2 (ly_symbol2scm ("module-public-interface"),
+ gh_car (s)));
scm_primitive_eval (expr);
}
-
scopes_ = scm_cons (module, scopes_);
}
My_lily_lexer::LexerError (char const *s)
{
if (include_stack_.is_empty ())
- {
- progress_indication (_f ("error at EOF: %s", s)+ String ("\n"));
- }
+ progress_indication (_f ("error at EOF: %s", s) + String ("\n"));
else
{
errorlevel_ |= 1;
{
last_input_ = here_input ();
}
+
+void
+My_lily_lexer::set_encoding (String s)
+{
+ encoding_ = s;
+}
make_simple_markup (SCM a)
{
SCM simple = ly_scheme_function ("simple-markup");
-
- return scm_list_2 (simple, a);
+ SCM markup = scm_list_2 (simple, a);
+#if 0
+ if (THIS->lexer_->encoding_ != "")
+ return scm_list_2
+ (scm_cons (ly_scheme_function ("encoding"),
+ scm_makfrom0str (THIS->lexer_->encoding_.to_str0 ())),
+ markup);
+#endif
+return markup;
}
set_music_properties (Music *p, SCM a)
{
for (SCM k = a; gh_pair_p (k); k = ly_cdr (k))
- {
- p->internal_set_property (ly_caar (k), ly_cdar (k));
- }
+ p->internal_set_property (ly_caar (k), ly_cdar (k));
}
SCM
int
yylex (YYSTYPE *s, void *v)
{
- My_lily_parser *pars = (My_lily_parser*) v;
+ My_lily_parser *pars = (My_lily_parser*) v;
My_lily_lexer *lex = pars->lexer_;
lex->lexval = (void*) s;