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 "ly-module.hh"
17 #include "scm-hash.hh"
19 My_lily_parser::My_lily_parser (Sources * sources)
25 default_duration_ = Duration (2,0);
27 last_beam_start_ = SCM_EOL;
29 header_ = ly_make_anonymous_module ();
32 My_lily_parser::~My_lily_parser ()
37 /* Process one .ly file, or book. */
39 My_lily_parser::parse_file (String init, String in_file, String out_file)
41 lexer_ = new My_lily_lexer (sources_);
42 output_basename_ = out_file;
44 lexer_->main_input_name_ = in_file;
46 progress_indication (_ ("Parsing..."));
47 progress_indication ("\n");
50 lexer_->new_input (init, sources_);
52 /* Read .ly IN_FILE, lex, parse, write \score blocks from IN_FILE to
53 OUT_FILE (unless IN_FILE redefines output file name). */
56 if (!define_spots_.is_empty ())
58 define_spots_.top ().warning (_ ("Braces don't match"));
62 // fixme: dependencies
63 //input_file_->inclusion_names_ = lexer_->filename_strings_;
65 error_level_ = error_level_ | lexer_->errorlevel_; // ugh naming.
69 My_lily_parser::push_spot ()
71 define_spots_.push (here_input ());
75 My_lily_parser::here_str0 () const
77 return lexer_->here_str0 ();
81 My_lily_parser::parser_error (String s)
83 here_input ().error (s);
90 My_lily_parser::pop_spot ()
92 return define_spots_.pop ();
96 My_lily_parser::here_input () const
99 Parsing looks ahead , so we really want the previous location of the
100 lexer, not lexer_->here_input ().
103 Actually, that gets very icky when there are white space, because
104 the line-numbers are all wrong. Let's try the character before
105 the current token. That gets the right result for
106 note/duration stuff, but doesn't mess up for errors in the 1st token of the line.
109 Input hi (lexer_->here_input ());
111 char const * bla = hi.defined_str0_;
112 if (hi.line_number () > 1
113 || hi.column_number () > 1)
116 return Input (hi.source_file_, bla);