lilypond-0.1.12
[lilypond.git] / lily / my-lily-lexer.cc
blobf09f0dd6c81d0274220af01bedee72382e4ccd1f
1 /*
2 my-lily-lexer.cc -- implement My_lily_lexer
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
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"
23 static Keyword_ent the_key_tab[]={
24 {"accepts", ACCEPTS},
25 {"alias", ALIAS},
26 {"bar", BAR},
27 {"cadenza", CADENZA},
28 {"clear", CLEAR},
29 {"clef", CLEF},
30 {"cm", CM_T},
31 {"consists", CONSISTS},
32 {"contains", CONTAINS},
33 {"duration", DURATION},
34 {"absdynamic", ABSDYNAMIC},
35 {"group", GROUP},
36 {"hshift", HSHIFT},
37 {"id", ID},
38 {"in", IN_T},
39 {"requesttranslator", REQUESTTRANSLATOR},
40 {"lyric", LYRIC},
41 {"key", KEY},
42 {"melodic" , MELODIC},
43 {"melodic_request", MELODIC_REQUEST},
44 {"meter", METER},
45 {"midi", MIDI},
46 {"mm", MM_T},
47 {"multi", MULTI},
48 {"header", HEADER},
49 {"notenames", NOTENAMES},
50 {"octave", OCTAVE},
51 {"output", OUTPUT},
52 {"partial", PARTIAL},
53 {"paper", PAPER},
54 {"plet", PLET},
55 {"pt", PT_T},
56 {"score", SCORE},
57 {"script", SCRIPT},
58 {"skip", SKIP},
59 {"staff", STAFF},
60 {"stem", STEM},
61 {"table", TABLE},
62 {"spandynamic", SPANDYNAMIC},
63 {"symboltables", SYMBOLTABLES},
64 {"tempo", TEMPO},
65 {"texid", TEXID},
66 {"textstyle", TEXTSTYLE},
67 {"transpose", TRANSPOSE},
68 {"version", VERSION},
69 {"grouping", GROUPING},
70 {0,0}
73 My_lily_lexer::My_lily_lexer()
75 keytable_p_ = new Keyword_table (the_key_tab);
76 identifier_assoc_p_ = new Assoc<String, Identifier*>;
77 errorlevel_i_ = 0;
78 post_quotes_b_ = false;
79 note_tab_p_ = new Notename_table;
82 int
83 My_lily_lexer::lookup_keyword (String s)
85 return keytable_p_->lookup (s);
88 Identifier*
89 My_lily_lexer::lookup_identifier (String s)
91 if (!identifier_assoc_p_->elt_b (s))
92 return 0;
94 return (*identifier_assoc_p_)[s];
98 void
99 My_lily_lexer::set_identifier (String name_str, Identifier*i)
101 Identifier *old = lookup_identifier (name_str);
102 if (old)
104 old->warning("redeclaration of \\" + name_str);
105 delete old;
107 (*identifier_assoc_p_)[name_str] = i;
110 My_lily_lexer::~My_lily_lexer()
112 delete keytable_p_;
114 for (Assoc_iter<String,Identifier*>
115 ai (*identifier_assoc_p_); ai.ok(); ai++)
117 DOUT << "deleting: " << ai.key()<<'\n';
118 delete ai.val();
120 delete note_tab_p_;
121 delete identifier_assoc_p_;
123 void
124 My_lily_lexer::print_declarations (bool init_b) const
126 for (Assoc_iter<String,Identifier*> ai (*identifier_assoc_p_); ai.ok();
127 ai++)
129 if (ai.val()->init_b_ == init_b)
131 DOUT << ai.key() << '=';
132 ai.val()->print ();
137 void
138 My_lily_lexer::LexerError (char const *s)
140 if (include_stack_.empty())
142 *mlog << "error at EOF" << s << '\n';
144 else
146 errorlevel_i_ |= 1;
148 Input spot (source_file_l(),here_ch_C());
150 spot.error (s);
154 Melodic_req*
155 My_lily_lexer::lookup_melodic_req_l (String s)
157 return note_tab_p_->get_l (s);
160 void
161 My_lily_lexer::add_notename (String s, Melodic_req *p)
163 note_tab_p_->add (s,p);
166 void
167 My_lily_lexer::clear_notenames()
169 delete note_tab_p_;
170 note_tab_p_ = new Notename_table;