X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=lily%2Flily-parser-scheme.cc;h=cd46e9774b403b6280749603645975582844a6d9;hb=59fd89c32399b67464b217ba31502051c91bb919;hp=0e844d2bc0ec51053f3f938cb4ac747fbf883af8;hpb=a260c500ba01a6ed3004cc7cf4ec4fc64fd453e7;p=lilypond.git diff --git a/lily/lily-parser-scheme.cc b/lily/lily-parser-scheme.cc index 0e844d2bc0..cd46e9774b 100644 --- a/lily/lily-parser-scheme.cc +++ b/lily/lily-parser-scheme.cc @@ -8,13 +8,13 @@ #include +#include "lily-parser.hh" + #include "file-name-map.hh" #include "file-name.hh" #include "file-path.hh" -#include "input-smob.hh" #include "international.hh" #include "lily-lexer.hh" -#include "lily-parser.hh" #include "ly-module.hh" #include "main.hh" #include "program-option.hh" @@ -86,7 +86,7 @@ LY_DEFINE (ly_parse_file, "ly:parse-file", if (dir != "" && dir != "." && dir != get_working_directory ()) { global_path.prepend (get_working_directory ()); - message (_f ("Changing working directory to `%s'", + message (_f ("Changing working directory to: `%s'", dir.c_str ())); chdir (dir.c_str ()); } @@ -104,17 +104,18 @@ LY_DEFINE (ly_parse_file, "ly:parse-file", if (init.length () && global_path.find (init).empty ()) { - warning (_f ("can't find init file: `%s'", init)); + warning (_f ("cannot find init file: `%s'", init)); warning (_f ("(search path: `%s')", global_path.to_string ().c_str ())); exit (2); } - if ((file_name != "-") && global_path.find (file_name).empty ()) + + bool error = false; + if ((file_name != "-") && file_name.empty ()) { - warning (_f ("can't find file: `%s'", file_name)); - scm_throw (ly_symbol2scm ("ly-file-failed"), - scm_list_1 (scm_makfrom0str (file_name.c_str ()))); + warning (_f ("cannot find file: `%s'", file)); + error = true; } else { @@ -129,37 +130,35 @@ LY_DEFINE (ly_parse_file, "ly:parse-file", parser->parse_file (init, file_name, out_file); - bool error = parser->error_level_; + error = parser->error_level_; + + parser->clear (); parser->unprotect (); - parser = 0; - if (error) - /* TODO: pass renamed input file too. */ - scm_throw (ly_symbol2scm ("ly-file-failed"), - scm_list_1 (scm_makfrom0str (file_name.c_str ()))); } + + /* + outside the if-else to ensure cleanup fo Sources object, + */ + if (error) + /* TODO: pass renamed input file too. */ + scm_throw (ly_symbol2scm ("ly-file-failed"), + scm_list_1 (ly_string2scm (file_name))); + return SCM_UNSPECIFIED; } -LY_DEFINE (ly_parse_string, "ly:parse-string", - 1, 0, 0, (SCM ly_code), - "Parse the string LY_CODE. " - "Upon failure, throw @code{ly-file-failed} key.") -{ - SCM_ASSERT_TYPE (scm_is_string (ly_code), ly_code, SCM_ARG1, __FUNCTION__, "string"); - - Sources sources; - sources.set_path (&global_path); - Lily_parser *parser = new Lily_parser (&sources); - parser->parse_string (ly_scm2string (ly_code)); - parser->unprotect (); - parser = 0; - return SCM_UNSPECIFIED; +LY_DEFINE (ly_parser_lexer, "ly:parser-lexer", + 1, 0, 0, (SCM parser_smob), + "Return the lexer for @var{parser-smob}.") +{ + Lily_parser *parser = unsmob_lily_parser (parser_smob); + return parser->lexer_->self_scm (); } -LY_DEFINE (ly_clone_parser, "ly:clone-parser", +LY_DEFINE (ly_parser_clone, "ly:parser-clone", 1, 0, 0, (SCM parser_smob), - "Return a clone of PARSER_SMOB.") + "Return a clone of @var{parser-smob}.") { Lily_parser *parser = unsmob_lily_parser (parser_smob); Lily_parser *clone = new Lily_parser (*parser); @@ -169,7 +168,7 @@ LY_DEFINE (ly_clone_parser, "ly:clone-parser", LY_DEFINE (ly_parser_define, "ly:parser-define!", 3, 0, 0, (SCM parser_smob, SCM symbol, SCM val), - "Bind SYMBOL to VAL in PARSER_SMOB's module.") + "Bind @var{symbol} to @var{val} in @var{parser-smob}'s module.") { Lily_parser *parser = unsmob_lily_parser (parser_smob); SCM_ASSERT_TYPE (scm_is_symbol (symbol), symbol, SCM_ARG2, __FUNCTION__, "symbol"); @@ -181,7 +180,7 @@ LY_DEFINE (ly_parser_define, "ly:parser-define!", LY_DEFINE (ly_parser_lookup, "ly:parser-lookup", 2, 0, 0, (SCM parser_smob, SCM symbol), - "Lookup @var{symbol} in @var{parser_smob}'s module. " + "Lookup @var{symbol} in @var{parser-smob}'s module. " "Undefined is '().") { Lily_parser *parser = unsmob_lily_parser (parser_smob); @@ -198,7 +197,7 @@ LY_DEFINE (ly_parser_lookup, "ly:parser-lookup", LY_DEFINE (ly_parser_parse_string, "ly:parser-parse-string", 2, 0, 0, (SCM parser_smob, SCM ly_code), - "Parse the string LY_CODE with PARSER_SMOB." + "Parse the string @code{ly-code} with @code{parser-smob}." "Upon failure, throw @code{ly-file-failed} key.") { Lily_parser *parser = unsmob_lily_parser (parser_smob); @@ -236,7 +235,7 @@ LY_DEFINE (ly_parser_output_name, "ly:parser-output-name", Lily_parser *p = unsmob_lily_parser (parser); SCM_ASSERT_TYPE (p, parser, SCM_ARG1, __FUNCTION__, "Lilypond parser"); - return scm_makfrom0str (p->output_basename_.c_str ()); + return ly_string2scm (p->output_basename_); } LY_DEFINE (ly_parser_error, "ly:parser-error", @@ -256,3 +255,16 @@ LY_DEFINE (ly_parser_error, "ly:parser-error", return parser; } + +LY_DEFINE (ly_parser_clear_error, "ly:parser-clear-error", + 1, 0, 0, (SCM parser), + "Clear the error flag for the parser.") +{ + Lily_parser *p = unsmob_lily_parser (parser); + SCM_ASSERT_TYPE (p, parser, SCM_ARG1, __FUNCTION__, "Lilypond parser"); + + p->error_level_ = 0; + p->lexer_->error_level_ = 0; + + return SCM_UNSPECIFIED; +}