]> git.donarmstrong.com Git - lilypond.git/blob - lily/my-lily-lexer.cc
release: 0.0.53
[lilypond.git] / lily / my-lily-lexer.cc
1 /*
2   my-lily-lexer.cc -- implement My_lily_lexer
3
4   source file of the 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     {"bar", BAR},
25     {"cadenza", CADENZA},
26     {"clear", CLEAR},
27     {"clef", CLEF},
28     {"cm", CM_T},
29     {"duration", DURATIONCOMMAND},
30     {"absdynamic", ABSDYNAMIC},
31     {"group", GROUP},
32     {"geometric", GEOMETRIC},
33     {"hshift", HSHIFT},
34     {"in", IN_T},
35     {"init_end", INIT_END},
36     {"inputregister", INPUT_REGS},
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     {"multivoice", MULTIVOICE},
45     {"note", NOTE},
46     {"notenames", NOTENAMES},
47     {"octave", OCTAVECOMMAND},
48     {"output", OUTPUT},
49     {"partial", PARTIAL},
50     {"paper", PAPER},
51     {"plet", PLET},
52     {"pt", PT_T},
53     {"score", SCORE},
54     {"script", SCRIPT},
55     {"skip", SKIP},
56     {"staff", STAFF},
57     {"start", START_T},
58     {"stem", STEM},
59     {"table", TABLE},
60     {"spandynamic", SPANDYNAMIC}, 
61     {"symboltables", SYMBOLTABLES},
62     {"tempo", TEMPO},
63     {"texid", TEXID},
64     {"textstyle", TEXTSTYLE},
65     {"transpose", TRANSPOSE},
66     {"unitspace", UNITSPACE},
67     {"width", WIDTH},
68     {"version", VERSION},
69     {"grouping", GROUPING},
70     {0,0}
71 };
72
73 My_lily_lexer::My_lily_lexer()
74 {
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;
80 }
81
82 int
83 My_lily_lexer::lookup_keyword(String s)
84 {
85     return keytable_p_->lookup(s);
86 }
87
88 Identifier*
89 My_lily_lexer::lookup_identifier(String s)
90 {
91     if (!identifier_assoc_p_->elt_b(s))
92         return 0;
93     
94     return (*identifier_assoc_p_)[s];
95 }
96
97
98 void
99 My_lily_lexer::add_identifier(Identifier*i)
100 {
101     delete lookup_identifier(i->name_str_);
102     (*identifier_assoc_p_)[i->name_str_] = i;
103 }
104
105 My_lily_lexer::~My_lily_lexer()
106 {
107     delete keytable_p_;
108
109     for (Assoc_iter<String,Identifier*>
110              ai(*identifier_assoc_p_); ai.ok(); ai++) {
111         mtor << "deleting: " << ai.key()<<'\n';
112         delete ai.val();
113     }
114     delete note_tab_p_;
115     delete identifier_assoc_p_;
116 }
117 void
118 My_lily_lexer::print_declarations(bool init_b)const
119 {
120     for (Assoc_iter<String,Identifier*> ai(*identifier_assoc_p_); ai.ok(); 
121          ai++) {
122         if (ai.val()->init_b_ == init_b)
123             ai.val()->print();
124     }
125 }
126
127 void
128 My_lily_lexer::LexerError(char const *s)
129 {
130     if (include_stack_.empty()) {
131         *mlog << "error at EOF" << s << '\n';
132     } else {
133         errorlevel_i_ |= 1;
134  
135         Input spot(source_file_l(),here_ch_C());
136
137         spot.error( s );
138     }
139 }
140
141 Melodic_req*
142 My_lily_lexer::lookup_melodic_req_l(String s)
143 {
144     return note_tab_p_->get_l(s);
145 }
146
147 void
148 My_lily_lexer::add_notename(String s, Melodic_req *p)
149 {
150     note_tab_p_->add(s,p);
151 }
152
153 void
154 My_lily_lexer::clear_notenames()
155 {
156     delete note_tab_p_;
157     note_tab_p_ = new Notename_table;
158 }