From 7bfc458c6aba8fe348b9fd5afafb64b8004441f7 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Fri, 1 Sep 2006 11:57:55 +0000 Subject: [PATCH] * lily/lexer.ll: accept EOF in all states. * lily/tempo-performer.cc (Tempo_performer): initialize last_tempo_. * lily/source-file.cc (Source_file): always 0-terminate character array, to prevent Flex from barfing. * lily/global-context.cc (get_output): robustness: don't crash if no Score context found. --- ChangeLog | 10 ++++++++++ lily/global-context-scheme.cc | 5 ++++- lily/global-context.cc | 6 +++++- lily/lexer.ll | 3 ++- lily/lily-parser-scheme.cc | 2 +- lily/lily-parser.cc | 1 - lily/parser.yy | 7 +++---- lily/source-file.cc | 12 +++++++----- lily/tempo-performer.cc | 1 + scm/parser-ly-from-scheme.scm | 5 +++-- 10 files changed, 36 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9f753356b5..076b9ea9a1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2006-09-01 Han-Wen Nienhuys + * lily/lexer.ll: accept EOF in all states. + + * lily/tempo-performer.cc (Tempo_performer): initialize last_tempo_. + + * lily/source-file.cc (Source_file): always 0-terminate character + array, to prevent Flex from barfing. + + * lily/global-context.cc (get_output): robustness: don't crash if + no Score context found. + * lily/include/book.hh (class Book): idem. * lily/include/context-def.hh (struct Context_def): idem. diff --git a/lily/global-context-scheme.cc b/lily/global-context-scheme.cc index 273ae10b1d..219dc267c1 100644 --- a/lily/global-context-scheme.cc +++ b/lily/global-context-scheme.cc @@ -27,7 +27,10 @@ LY_DEFINE (ly_format_output, "ly:format-output", SCM output = g->get_output (); progress_indication ("\n"); - unsmob_music_output (output)->process (); + + if (Music_output *od = unsmob_music_output (output)) + od->process (); + return output; } diff --git a/lily/global-context.cc b/lily/global-context.cc index 40fe3a61cd..ddcec501ba 100644 --- a/lily/global-context.cc +++ b/lily/global-context.cc @@ -114,7 +114,11 @@ Global_context::get_score_context () const SCM Global_context::get_output () { - return get_score_context ()->get_property ("output"); + Context * c = get_score_context (); + if (c) + return c->get_property ("output"); + else + return SCM_EOL; } void diff --git a/lily/lexer.ll b/lily/lexer.ll index 98332a1eb3..178ea88e97 100644 --- a/lily/lexer.ll +++ b/lily/lexer.ll @@ -227,6 +227,7 @@ BOM_UTF8 \357\273\277 int i; sscanf (YYText (), "%d", &i); +// this->set_debug (1); yy_pop_state (); this->here_input ().get_source_file ()->set_line (here_input ().start (), i); } @@ -550,7 +551,7 @@ BOM_UTF8 \357\273\277 } } -<> { +<*><> { if (is_main_input_) { is_main_input_ = false; diff --git a/lily/lily-parser-scheme.cc b/lily/lily-parser-scheme.cc index 7c66507997..30062e14ff 100644 --- a/lily/lily-parser-scheme.cc +++ b/lily/lily-parser-scheme.cc @@ -130,8 +130,8 @@ LY_DEFINE (ly_parse_file, "ly:parse-file", parser->parse_file (init, file_name, out_file); bool error = parser->error_level_; + parser->unprotect (); - parser = 0; if (error) /* TODO: pass renamed input file too. */ scm_throw (ly_symbol2scm ("ly-file-failed"), diff --git a/lily/lily-parser.cc b/lily/lily-parser.cc index 65160851e1..1f073fb07a 100644 --- a/lily/lily-parser.cc +++ b/lily/lily-parser.cc @@ -141,7 +141,6 @@ Lily_parser::parse_string (string ly_code) lexer_->main_input_name_ = ""; lexer_->is_main_input_ = true; - set_yydebug (0); lexer_->new_input (lexer_->main_input_name_, ly_code, sources_); SCM mod = lexer_->set_current_scope (); diff --git a/lily/parser.yy b/lily/parser.yy index dff3ee921d..ef215c327a 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -9,6 +9,7 @@ %{ +#define YYDEBUG 1 #define YYERROR_VERBOSE 1 #define YYPARSE_PARAM my_lily_parser #define YYLEX_PARAM my_lily_parser @@ -2324,11 +2325,9 @@ markup: %% void -Lily_parser::set_yydebug (bool ) +Lily_parser::set_yydebug (bool x) { -#if 0 - yydebug = 1; -#endif + yydebug = x; } void diff --git a/lily/source-file.cc b/lily/source-file.cc index cead386ae9..f1dd4a3694 100644 --- a/lily/source-file.cc +++ b/lily/source-file.cc @@ -38,10 +38,11 @@ Source_file::load_stdin () int c; while ((c = fgetc (stdin)) != EOF) characters_.push_back (c); - - characters_.push_back (0); } +/* + return contents of FILENAME. *Not 0-terminated!* + */ vector gulp_file (string filename, int desired_size) { @@ -101,9 +102,10 @@ Source_file::Source_file (string filename, string data) name_ = filename; characters_.resize (data.length ()); - copy (data.begin (), data.end (), characters_.begin ()); + characters_.push_back (0); + init_port (); for (vsize i = 0; i < characters_.size (); i++) @@ -122,9 +124,10 @@ Source_file::Source_file (string filename_string) else { characters_ = gulp_file (filename_string, -1); - characters_.push_back (0); } + characters_.push_back (0); + init_port (); for (vsize i = 0; i < characters_.size (); i++) @@ -198,7 +201,6 @@ Source_file::name_string () const Source_file::~Source_file () { delete istream_; - istream_ = 0; } Slice diff --git a/lily/tempo-performer.cc b/lily/tempo-performer.cc index 19a453f01b..23ea8fa74f 100644 --- a/lily/tempo-performer.cc +++ b/lily/tempo-performer.cc @@ -38,6 +38,7 @@ Tempo_performer::derived_mark () const Tempo_performer::Tempo_performer () { + last_tempo_ = SCM_EOL; audio_ = 0; } diff --git a/scm/parser-ly-from-scheme.scm b/scm/parser-ly-from-scheme.scm index d7a83a1f4d..9d2b3b5d47 100644 --- a/scm/parser-ly-from-scheme.scm +++ b/scm/parser-ly-from-scheme.scm @@ -17,8 +17,9 @@ (char->integer #\0))))) (string->list (number->string var-idx))))))))) -(define-public (ly:parse-string-result str parser) +(define-public (parse-string-result str parser) "Parse `str', which is supposed to contain a music expression." + (ly:parser-parse-string parser (format #f "parseStringResult = \\notemode { ~a }" str)) @@ -81,6 +82,6 @@ character." ,@(map (lambda (binding) `(ly:parser-define! parser-clone ',(car binding) ,(cdr binding))) (reverse bindings)) - (ly:parse-string-result ,lily-string parser-clone))))) + (parse-string-result ,lily-string parser-clone))))) (read-hash-extend #\{ read-lily-expression) -- 2.39.2