2 my-lily-parser.cc -- implement My_lily_parser
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
10 #include "my-lily-parser.hh"
11 #include "my-lily-lexer.hh"
15 #include "input-file-results.hh"
16 #include "scm-hash.hh"
18 My_lily_parser::My_lily_parser (Input_file_results * source)
22 default_duration_ = Duration (2,0);
24 last_beam_start_ = SCM_EOL;
29 My_lily_parser::~My_lily_parser ()
33 scm_gc_unprotect_object (default_header_->self_scm ());
36 /* Process one .ly file, or book. */
38 My_lily_parser::parse_file (String init, String in_file, String out_file)
40 lexer_ = new My_lily_lexer;
41 output_basename_ = out_file;
43 lexer_->main_input_name_ = in_file;
45 progress_indication (_ ("Parsing..."));
46 progress_indication ("\n");
49 lexer_->new_input (init, &input_file_->sources_);
51 /* Read .ly IN_FILE, lex, parse, write \score blocks from IN_FILE to
52 OUT_FILE (unless IN_FILE redefines output file name). */
55 if (!define_spots_.is_empty ())
57 define_spots_.top ().warning (_ ("Braces don't match"));
61 input_file_->inclusion_names_ = lexer_->filename_strings_;
63 error_level_ = error_level_ | lexer_->errorlevel_; // ugh naming.
67 My_lily_parser::push_spot ()
69 define_spots_.push (here_input ());
73 My_lily_parser::here_str0 () const
75 return lexer_->here_str0 ();
79 My_lily_parser::parser_error (String s)
81 here_input ().error (s);
83 exit_status_global = 1;
89 My_lily_parser::pop_spot ()
91 return define_spots_.pop ();
95 My_lily_parser::here_input () const
98 Parsing looks ahead , so we really want the previous location of the
99 lexer, not lexer_->here_input ().
102 Actually, that gets very icky when there are white space, because
103 the line-numbers are all wrong. Let's try the character before
104 the current token. That gets the right result for
105 note/duration stuff, but doesn't mess up for errors in the 1st token of the line.
108 Input hi (lexer_->here_input ());
110 char const * bla = hi.defined_str0_;
111 if (hi.line_number () > 1
112 || hi.column_number () > 1)
115 return Input (hi.source_file_, bla);
118 #include "paper-def.hh"
119 #include "context-def.hh"
121 My_lily_parser * current_parser;
123 MAKE_SCHEME_CALLBACK (My_lily_parser,paper_description, 0);
126 My_lily_parser::paper_description ()
128 My_lily_parser * me = current_parser;
130 Music_output_def *id = unsmob_music_output_def (me->lexer_->lookup_identifier ("$defaultpaper"));
131 Paper_def *p = dynamic_cast<Paper_def*> (id->clone ());
133 SCM al = p->translator_tab_->to_alist ();
135 for (SCM s = al ; is_pair (s); s = ly_cdr (s))
137 Context_def * td = unsmob_context_def (ly_cdar (s));
138 l = scm_cons (scm_cons (ly_caar (s), td->to_alist ()), l);