X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Flily-parser.cc;h=12646bb3b450e3c6a65313b52a520fc36b4dfe41;hb=16e626a8524421eda692cb19be6d0ec5bff723b7;hp=2ee77b1e6dec7a0f270761362c642c37d792aaa0;hpb=1c846b2c2348b4e0ca4a3c2e8fb267047ba2d203;p=lilypond.git diff --git a/lily/lily-parser.cc b/lily/lily-parser.cc index 2ee77b1e6d..12646bb3b4 100644 --- a/lily/lily-parser.cc +++ b/lily/lily-parser.cc @@ -72,7 +72,6 @@ Lily_parser::~Lily_parser () { } - SCM Lily_parser::mark_smob (SCM s) { @@ -81,7 +80,7 @@ Lily_parser::mark_smob (SCM s) } int -Lily_parser::print_smob (SCM s, SCM port, scm_print_state*) +Lily_parser::print_smob (SCM s, SCM port, scm_print_state *) { scm_puts ("#set_identifier (ly_symbol2scm ("parser"), - SCM_EOL); + SCM_EOL); ly_reexport_module (scm_current_module ()); scm_set_current_module (mod); @@ -144,7 +143,7 @@ Lily_parser::parse_string (string ly_code) { // TODO: use $parser lexer_->set_identifier (ly_symbol2scm ("parser"), - self_scm ()); + self_scm ()); lexer_->main_input_name_ = ""; lexer_->is_main_input_ = true; @@ -157,13 +156,43 @@ Lily_parser::parse_string (string ly_code) if (!define_spots_.empty ()) { if (define_spots_.empty () - && !error_level_) - programming_error ("define_spots_ don't match, but error_level_ not set."); + && !error_level_) + programming_error ("define_spots_ don't match, but error_level_ not set."); } error_level_ = error_level_ | lexer_->error_level_; } +SCM +Lily_parser::parse_string_expression (string ly_code) +{ + // TODO: use $parser + lexer_->set_identifier (ly_symbol2scm ("parser"), + self_scm ()); + + lexer_->main_input_name_ = ""; + lexer_->is_main_input_ = true; + lexer_->new_input (lexer_->main_input_name_, ly_code, sources_); + + SCM mod = lexer_->set_current_scope (); + lexer_->push_extra_token (EMBEDDED_LILY); + do_yyparse (); + SCM result = lexer_->lookup_identifier_symbol (ly_symbol2scm ("parseStringResult")); + // parseStringResult is set in the grammar rule for embedded_lilypond + + scm_set_current_module (mod); + + if (!define_spots_.empty ()) + { + if (define_spots_.empty () + && !error_level_) + programming_error ("define_spots_ don't match, but error_level_ not set."); + } + + error_level_ = error_level_ | lexer_->error_level_; + return result; +} + void Lily_parser::include_string (string ly_code) { @@ -176,7 +205,7 @@ Lily_parser::clear () if (lexer_) { while (lexer_->has_scope ()) - lexer_->remove_scope (); + lexer_->remove_scope (); } lexer_ = 0; @@ -202,13 +231,10 @@ Lily_parser::parser_error (Input const &i, string s) error_level_ = 1; } - - IMPLEMENT_SMOBS (Lily_parser); IMPLEMENT_TYPE_P (Lily_parser, "ly:lily-parser?"); IMPLEMENT_DEFAULT_EQUAL_P (Lily_parser); - /**************************************************************** OUTPUT-DEF ****************************************************************/ @@ -240,8 +266,8 @@ Output_def * get_paper (Lily_parser *parser) { SCM papers = parser->lexer_->lookup_identifier ("$papers"); - Output_def *layout = ((papers == SCM_UNDEFINED) || scm_is_null (papers)) ? - 0 : unsmob_output_def (scm_car (papers)); + Output_def *layout = ((papers == SCM_UNDEFINED) || scm_is_null (papers)) + ? 0 : unsmob_output_def (scm_car (papers)); SCM default_paper = parser->lexer_->lookup_identifier ("$defaultpaper"); layout = layout ? layout : unsmob_output_def (default_paper);