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