]> git.donarmstrong.com Git - lilypond.git/blob - lily/my-lily-parser.cc
* lily/accidental-placement.cc (position_accidentals): bugfix in
[lilypond.git] / lily / my-lily-parser.cc
1 /*
2   my-lily-parser.cc -- implement My_lily_parser
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7        Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9
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"
17
18 My_lily_parser::My_lily_parser (Input_file_results * source)
19 {
20   input_file_ = source;
21   lexer_ = 0;
22   default_duration_ = Duration (2,0);
23   error_level_ = 0;
24   last_beam_start_ = SCM_EOL;
25
26   default_header_ =0;
27 }
28
29 My_lily_parser::~My_lily_parser ()
30 {
31   delete lexer_;
32   if (default_header_)
33     scm_gc_unprotect_object (default_header_->self_scm ());
34 }
35
36 /* Process one .ly file, or book.  */
37 void
38 My_lily_parser::parse_file (String init, String in_file, String out_file)
39 {
40   lexer_ = new My_lily_lexer;
41   output_basename_ = out_file;
42   
43   lexer_->main_input_name_ = in_file;
44
45   progress_indication (_ ("Parsing..."));
46
47   set_yydebug (0);
48   lexer_->new_input (init, &input_file_->sources_);
49
50   /* Read .ly IN_FILE, lex, parse, write \score blocks from IN_FILE to
51      OUT_FILE (unless IN_FILE redefines output file name).  */
52   do_yyparse ();
53
54   progress_indication ("\n");
55   
56   if (!define_spots_.is_empty ())
57     {
58       define_spots_.top ().warning (_ ("Braces don't match"));
59       error_level_ = 1;
60     }
61
62   input_file_->inclusion_names_ = lexer_->filename_strings_;
63
64   error_level_ = error_level_ | lexer_->errorlevel_; // ugh naming.
65 }
66
67 void
68 My_lily_parser::push_spot ()
69 {
70   define_spots_.push (here_input ());
71 }
72
73 char const *
74 My_lily_parser::here_str0 () const
75 {
76   return lexer_->here_str0 ();
77 }
78
79 void
80 My_lily_parser::parser_error (String s)
81 {
82   here_input ().error (s);
83   error_level_ = 1;
84   exit_status_global = 1;
85 }
86
87
88
89 Input
90 My_lily_parser::pop_spot ()
91 {
92   return define_spots_.pop ();
93 }
94
95 Input
96 My_lily_parser::here_input () const
97 {
98   /*
99     Parsing looks ahead , so we really want the previous location of the
100     lexer, not lexer_->here_input ().
101    */
102   /*
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. 
107     
108    */
109   Input hi (lexer_->here_input ());
110
111   char const * bla = hi.defined_str0_;
112   if (hi.line_number () > 1
113       || hi.column_number () > 1)
114     bla --;
115   
116   return Input (hi.source_file_, bla);
117 }
118
119 #include "paper-def.hh"
120 #include "context-def.hh"
121
122 My_lily_parser * current_parser;
123
124 MAKE_SCHEME_CALLBACK (My_lily_parser,paper_description, 0);
125
126 SCM
127 My_lily_parser::paper_description ()
128 {
129   My_lily_parser * me = current_parser;
130
131   Music_output_def *id = unsmob_music_output_def (me->lexer_->lookup_identifier ("$defaultpaper"));
132   Paper_def *p = dynamic_cast<Paper_def*> (id->clone ());
133
134   SCM al = p->translator_tab_->to_alist ();
135   SCM l = SCM_EOL;
136   for (SCM s = al ; gh_pair_p (s); s = ly_cdr (s))
137     {
138       Context_def * td = unsmob_context_def (ly_cdar (s));
139       l = gh_cons (gh_cons (ly_caar (s), td->to_alist ()),  l);
140     }
141   return l;  
142 }
143   
144