]> git.donarmstrong.com Git - lilypond.git/blob - lily/my-lily-lexer.cc
release: 0.1.7
[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     {"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     {"notenames", NOTENAMES},
49     {"octave", OCTAVECOMMAND},
50     {"output", OUTPUT},
51     {"partial", PARTIAL},
52     {"paper", PAPER},
53     {"plet", PLET},
54     {"pt", PT_T},
55     {"score", SCORE},
56     {"script", SCRIPT},
57     {"skip", SKIP},
58     {"staff", STAFF},
59     {"stem", STEM},
60     {"table", TABLE},
61     {"spandynamic", SPANDYNAMIC}, 
62     {"symboltables", SYMBOLTABLES},
63     {"tempo", TEMPO},
64     {"texid", TEXID},
65     {"textstyle", TEXTSTYLE},
66     {"transpose", TRANSPOSE},
67     {"version", VERSION},
68     {"grouping", GROUPING},
69     {0,0}
70 };
71
72 My_lily_lexer::My_lily_lexer()
73 {
74     keytable_p_ = new Keyword_table(the_key_tab);
75     identifier_assoc_p_ = new Assoc<String, Identifier*>;
76     errorlevel_i_ = 0;
77     post_quotes_b_ = false;
78     note_tab_p_ = new Notename_table;
79 }
80
81 int
82 My_lily_lexer::lookup_keyword(String s)
83 {
84     return keytable_p_->lookup(s);
85 }
86
87 Identifier*
88 My_lily_lexer::lookup_identifier(String s)
89 {
90     if (!identifier_assoc_p_->elt_b(s))
91         return 0;
92     
93     return (*identifier_assoc_p_)[s];
94 }
95
96
97 void
98 My_lily_lexer::add_identifier(Identifier*i)
99 {
100     delete lookup_identifier(i->name_str_);
101     (*identifier_assoc_p_)[i->name_str_] = i;
102 }
103
104 My_lily_lexer::~My_lily_lexer()
105 {
106     delete keytable_p_;
107
108     for (Assoc_iter<String,Identifier*>
109              ai(*identifier_assoc_p_); ai.ok(); ai++) {
110         mtor << "deleting: " << ai.key()<<'\n';
111         delete ai.val();
112     }
113     delete note_tab_p_;
114     delete identifier_assoc_p_;
115 }
116 void
117 My_lily_lexer::print_declarations(bool init_b)const
118 {
119     for (Assoc_iter<String,Identifier*> ai(*identifier_assoc_p_); ai.ok(); 
120          ai++) {
121         if (ai.val()->init_b_ == init_b)
122             ai.val()->print();
123     }
124 }
125
126 void
127 My_lily_lexer::LexerError(char const *s)
128 {
129     if (include_stack_.empty()) {
130         *mlog << "error at EOF" << s << '\n';
131     } else {
132         errorlevel_i_ |= 1;
133  
134         Input spot(source_file_l(),here_ch_C());
135
136         spot.error( s );
137     }
138 }
139
140 Melodic_req*
141 My_lily_lexer::lookup_melodic_req_l(String s)
142 {
143     return note_tab_p_->get_l(s);
144 }
145
146 void
147 My_lily_lexer::add_notename(String s, Melodic_req *p)
148 {
149     note_tab_p_->add(s,p);
150 }
151
152 void
153 My_lily_lexer::clear_notenames()
154 {
155     delete note_tab_p_;
156     note_tab_p_ = new Notename_table;
157 }