release commit
[lilypond.git] / lily / my-lily-parser.cc
blob86d7bc3fa95059aeb33707e0be5f99ce14b657c7
1 /*
2 my-lily-parser.cc -- implement My_lily_parser
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
8 */
10 #include "my-lily-parser.hh"
11 #include "my-lily-lexer.hh"
12 #include "warn.hh"
13 #include "main.hh"
14 #include "parser.hh"
15 #include "input-file-results.hh"
16 #include "scm-hash.hh"
18 My_lily_parser::My_lily_parser (Input_file_results * source)
20 input_file_ = source;
21 lexer_ = 0;
22 default_duration_ = Duration (2,0);
23 error_level_ = 0;
24 last_beam_start_ = SCM_EOL;
26 default_header_ =0;
29 My_lily_parser::~My_lily_parser ()
31 delete lexer_;
32 if (default_header_)
33 scm_gc_unprotect_object (default_header_->self_scm());
37 void
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..."));
47 set_yydebug (0);
48 lexer_->new_input (init, &input_file_->sources_);
49 do_yyparse ();
51 progress_indication ("\n");
53 if (!define_spots_.empty ())
55 define_spots_.top ().warning (_ ("Braces don't match"));
56 error_level_ = 1;
59 input_file_->inclusion_names_ = lexer_->filename_strings_;
61 error_level_ = error_level_ | lexer_->errorlevel_; // ugh naming.
64 void
65 My_lily_parser::push_spot ()
67 define_spots_.push (here_input ());
70 char const *
71 My_lily_parser::here_str0 () const
73 return lexer_->here_str0 ();
76 void
77 My_lily_parser::parser_error (String s)
79 here_input ().error (s);
80 error_level_ = 1;
81 exit_status_global = 1;
86 Input
87 My_lily_parser::pop_spot ()
89 return define_spots_.pop ();
92 Input
93 My_lily_parser::here_input () const
96 Parsing looks ahead , so we really want the previous location of the
97 lexer, not lexer_->here_input().
100 Actually, that gets very icky when there are white space, because
101 the line-numbers are all wrong. Let's try the character before
102 the current token. That gets the right result for
103 note/duration stuff, but doesn't mess up for errors in the 1st token of the line.
106 Input hi (lexer_->here_input ());
108 char const * bla = hi.defined_str0_;
109 if (hi.line_number () > 1
110 || hi.column_number () > 1)
111 bla --;
113 return Input (hi.source_file_, bla);
116 #include "paper-def.hh"
117 #include "translator-def.hh"
119 My_lily_parser * current_parser;
121 MAKE_SCHEME_CALLBACK (My_lily_parser,paper_description, 0);
124 My_lily_parser::paper_description ()
126 My_lily_parser * me = current_parser;
128 Music_output_def *id = unsmob_music_output_def (me->lexer_->lookup_identifier ("$defaultpaper"));
129 Paper_def *p = dynamic_cast<Paper_def*> (id->clone ());
131 SCM al = p->translator_tab_->to_alist ();
132 SCM l = SCM_EOL;
133 for (SCM s = al ; gh_pair_p (s); s = ly_cdr (s))
135 Translator_def * td = unsmob_translator_def (ly_cdar (s));
136 l = gh_cons (gh_cons (ly_caar (s), td->to_alist ()), l);
138 return l;