]> git.donarmstrong.com Git - lilypond.git/blob - lily/my-lily-lexer.cc
patch::: 0.0.73pre.jcn1: epsilon performance
[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     {"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", DURATIONCOMMAND},
34     {"absdynamic", ABSDYNAMIC},
35     {"group", GROUP},
36     {"geometric", GEOMETRIC},
37     {"hshift", HSHIFT},
38     {"id", ID},
39     {"in", IN_T},
40     {"init_end", INIT_END},
41     {"requestengraver", REQUESTENGRAVER},
42     {"requestperformer", REQUESTPERFORMER},
43     {"lyric", LYRIC},
44     {"key", KEY},
45     {"melodic" , MELODIC},
46     {"melodic_request", MELODIC_REQUEST},
47     {"meter", METER},
48     {"midi", MIDI},
49     {"mm", MM_T},
50     {"multi", MULTI},
51     {"note", NOTE},
52     {"notenames", NOTENAMES},
53     {"octave", OCTAVECOMMAND},
54     {"output", OUTPUT},
55     {"partial", PARTIAL},
56     {"paper", PAPER},
57     {"plet", PLET},
58     {"pt", PT_T},
59     {"score", SCORE},
60     {"script", SCRIPT},
61     {"skip", SKIP},
62     {"staff", STAFF},
63     {"start", START_T},
64     {"stem", STEM},
65     {"table", TABLE},
66     {"spandynamic", SPANDYNAMIC}, 
67     {"symboltables", SYMBOLTABLES},
68     {"tempo", TEMPO},
69     {"texid", TEXID},
70     {"textstyle", TEXTSTYLE},
71     {"transpose", TRANSPOSE},
72     {"unitspace", UNITSPACE},
73     {"width", WIDTH},
74     {"version", VERSION},
75     {"grouping", GROUPING},
76     {0,0}
77 };
78
79 My_lily_lexer::My_lily_lexer()
80 {
81     keytable_p_ = new Keyword_table(the_key_tab);
82     identifier_assoc_p_ = new Assoc<String, Identifier*>;
83     errorlevel_i_ = 0;
84     post_quotes_b_ = false;
85     note_tab_p_ = new Notename_table;
86 }
87
88 int
89 My_lily_lexer::lookup_keyword(String s)
90 {
91     return keytable_p_->lookup(s);
92 }
93
94 Identifier*
95 My_lily_lexer::lookup_identifier(String s)
96 {
97     if (!identifier_assoc_p_->elt_b(s))
98         return 0;
99     
100     return (*identifier_assoc_p_)[s];
101 }
102
103
104 void
105 My_lily_lexer::add_identifier(Identifier*i)
106 {
107     delete lookup_identifier(i->name_str_);
108     (*identifier_assoc_p_)[i->name_str_] = i;
109 }
110
111 My_lily_lexer::~My_lily_lexer()
112 {
113     delete keytable_p_;
114
115     for (Assoc_iter<String,Identifier*>
116              ai(*identifier_assoc_p_); ai.ok(); ai++) {
117         mtor << "deleting: " << ai.key()<<'\n';
118         delete ai.val();
119     }
120     delete note_tab_p_;
121     delete identifier_assoc_p_;
122 }
123 void
124 My_lily_lexer::print_declarations(bool init_b)const
125 {
126     for (Assoc_iter<String,Identifier*> ai(*identifier_assoc_p_); ai.ok(); 
127          ai++) {
128         if (ai.val()->init_b_ == init_b)
129             ai.val()->print();
130     }
131 }
132
133 void
134 My_lily_lexer::LexerError(char const *s)
135 {
136     if (include_stack_.empty()) {
137         *mlog << "error at EOF" << s << '\n';
138     } else {
139         errorlevel_i_ |= 1;
140  
141         Input spot(source_file_l(),here_ch_C());
142
143         spot.error( s );
144     }
145 }
146
147 Melodic_req*
148 My_lily_lexer::lookup_melodic_req_l(String s)
149 {
150     return note_tab_p_->get_l(s);
151 }
152
153 void
154 My_lily_lexer::add_notename(String s, Melodic_req *p)
155 {
156     note_tab_p_->add(s,p);
157 }
158
159 void
160 My_lily_lexer::clear_notenames()
161 {
162     delete note_tab_p_;
163     note_tab_p_ = new Notename_table;
164 }