]> git.donarmstrong.com Git - lilypond.git/blob - lily/my-lily-lexer.cc
release: 0.1.13
[lilypond.git] / lily / my-lily-lexer.cc
1 /*
2   my-lily-lexer.cc -- implement My_lily_lexer
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include <strstream.h>
10 #include <ctype.h>
11 #include "notename-table.hh"
12 #include "interval.hh"
13 #include "identifier.hh"
14 #include "assoc-iter.hh"
15 #include "parser.hh"
16 #include "keyword.hh"
17 #include "assoc.hh"
18 #include "my-lily-lexer.hh"
19 #include "debug.hh"
20 #include "source-file.hh"
21 #include "parseconstruct.hh"
22
23 static Keyword_ent the_key_tab[]={
24   {"accepts", ACCEPTS},
25   {"bar", BAR},
26   {"cadenza", CADENZA},
27   {"clear", CLEAR},
28   {"clef", CLEF},
29   {"cm", CM_T},
30   {"consists", CONSISTS},
31   {"contains", CONTAINS},
32   {"duration", DURATION},
33   {"absdynamic", ABSDYNAMIC},
34   {"in", IN_T},
35   {"translator", TRANSLATOR},
36   {"type", TYPE},
37   {"lyric", LYRIC},
38   {"key", KEY},
39   {"melodic" , MELODIC},
40   {"melodic_request", MELODIC_REQUEST},
41   {"meter", METER},
42   {"midi", MIDI},
43   {"mm", MM_T},
44   {"multi", MULTI},
45   {"header", HEADER},
46   {"notenames", NOTENAMES},
47   {"octave", OCTAVE},
48   {"output", OUTPUT},
49   {"partial", PARTIAL},
50   {"paper", PAPER},
51   {"plet", PLET},
52   {"property", PROPERTY},
53   {"pt", PT_T},
54   {"score", SCORE},
55   {"script", SCRIPT},
56   {"skip", SKIP},
57   {"staff", STAFF},
58   {"table", TABLE},
59   {"spandynamic", SPANDYNAMIC}, 
60   {"symboltables", SYMBOLTABLES},
61   {"tempo", TEMPO},
62   {"texid", TEXID},
63   {"textstyle", TEXTSTYLE},
64   {"transpose", TRANSPOSE},
65   {"version", VERSION},
66   {"grouping", GROUPING},
67   {0,0}
68 };
69
70 My_lily_lexer::My_lily_lexer()
71 {
72   keytable_p_ = new Keyword_table (the_key_tab);
73   identifier_p_dict_p_ = new Dictionary<Identifier*>;
74   errorlevel_i_ = 0;
75   post_quotes_b_ = false;
76   note_tab_p_ = new Notename_table;
77 }
78
79 int
80 My_lily_lexer::lookup_keyword (String s)
81 {
82   return keytable_p_->lookup (s);
83 }
84
85 Identifier*
86 My_lily_lexer::lookup_identifier (String s)
87 {
88   if (!identifier_p_dict_p_->elt_b (s))
89     return 0;
90   
91   return (*identifier_p_dict_p_)[s];
92 }
93
94
95 void
96 My_lily_lexer::set_identifier (String name_str, Identifier*i)
97 {
98   Identifier *old = lookup_identifier (name_str);
99   if  (old) 
100     {
101       old->warning("redeclaration of \\" + name_str);
102       delete old;
103     }
104   (*identifier_p_dict_p_)[name_str] = i;
105 }
106
107 My_lily_lexer::~My_lily_lexer()
108 {
109   delete keytable_p_;
110
111   for (Assoc_iter<String,Identifier*>
112          ai (*identifier_p_dict_p_); ai.ok(); ai++) 
113     {
114       DOUT << "deleting: " << ai.key()<<'\n';
115       delete ai.val();
116     }
117   delete note_tab_p_;
118   delete identifier_p_dict_p_;
119 }
120 void
121 My_lily_lexer::print_declarations (bool init_b) const
122 {
123   for (Assoc_iter<String,Identifier*> ai (*identifier_p_dict_p_);
124        ai.ok(); ai++) 
125     {
126       if (ai.val()->init_b_ == init_b) 
127         {
128           DOUT << ai.key() << '=';
129           ai.val()->print ();
130         }
131     }
132 }
133
134 void
135 My_lily_lexer::LexerError (char const *s)
136 {
137   if (include_stack_.empty()) 
138     {
139       *mlog << "error at EOF" << s << '\n';
140     }
141   else 
142     {
143       errorlevel_i_ |= 1;
144       Input spot (source_file_l(),here_ch_C());
145       spot.error (s);
146     }
147 }
148
149 Melodic_req*
150 My_lily_lexer::lookup_melodic_req_l (String s)
151 {
152   return note_tab_p_->get_l (s);
153 }
154
155 void
156 My_lily_lexer::add_notename (String s, Melodic_req *p)
157 {
158   note_tab_p_->add (s,p);
159 }
160
161 void
162 My_lily_lexer::clear_notenames()
163 {
164   delete note_tab_p_;
165   note_tab_p_ = new Notename_table;
166 }