]> git.donarmstrong.com Git - lilypond.git/blob - lily/my-lily-lexer.cc
release: 0.0.44
[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
12 #include "interval.hh"
13 #include "identifier.hh"
14 #include "assoc-iter.hh"
15 #include "out/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     "clef", CLEF,
27     "cm", CM_T,
28     "duration", DURATIONCOMMAND,
29     "dynamic", DYNAMIC,
30     "geometric", GEOMETRIC,
31     "in", IN_T,
32     "lyrics", LYRICS,
33     "key", KEY,
34     "melodic" , MELODIC,
35     "meter", METER,
36     "midi", MIDI,
37     "mm", MM_T,
38     "multivoice", MULTIVOICE,
39     "octave", OCTAVECOMMAND,
40     "output", OUTPUT,
41     "partial", PARTIAL,
42     "paper", PAPER,
43     "plet", PLET,
44     "pt", PT_T,
45     "score", SCORE,
46     "script", SCRIPT,
47     "skip", SKIP,
48     "staff", STAFF,
49     "start", START_T,
50     "stem", STEM,
51     "table", TABLE,
52     "symboltables", SYMBOLTABLES,
53     "tempo", TEMPO,
54     "texid", TEXID,
55     "textstyle", TEXTSTYLE,
56     "transpose", TRANSPOSE,
57     "unitspace", UNITSPACE,
58     "width", WIDTH,
59     "music", MUSIC,
60     "grouping", GROUPING,
61     0,0
62 };
63
64 My_lily_lexer::My_lily_lexer()
65 {
66     keytable_p_ = new Keyword_table(the_key_tab);
67     identifier_assoc_p_ = new Assoc<String, Identifier*>;
68     errorlevel_i_ = 0;
69     post_quotes_b_ = false;
70     
71 }
72
73 int
74 My_lily_lexer::lookup_keyword(String s)
75 {
76     return keytable_p_->lookup(s);
77 }
78
79 Identifier*
80 My_lily_lexer::lookup_identifier(String s)
81 {
82     if (!identifier_assoc_p_->elt_query(s))
83         return 0;
84     
85     return (*identifier_assoc_p_)[s];
86 }
87
88
89 void
90 My_lily_lexer::add_identifier(Identifier*i)
91 {
92     delete lookup_identifier(i->name);
93     (*identifier_assoc_p_)[i->name] = i;
94 }
95
96 My_lily_lexer::~My_lily_lexer()
97 {
98     delete keytable_p_;
99
100     for (Assoc_iter<String,Identifier*>
101              ai(*identifier_assoc_p_); ai.ok(); ai++) {
102         mtor << "deleting: " << ai.key()<<'\n';
103         Identifier *i_p = ai.val();
104         if (!i_p->accessed_b_ && !i_p->init_b_)
105             warning("Variable not used", i_p->defined_ch_C_);
106         
107         delete ai.val();
108     }
109     delete identifier_assoc_p_;
110 }
111 void
112 My_lily_lexer::print_declarations(bool init_b)const
113 {
114     for (Assoc_iter<String,Identifier*> ai(*identifier_assoc_p_); ai.ok(); 
115          ai++) {
116         if (ai.val()->init_b_ == init_b)
117             ai.val()->print();
118     }
119 }
120
121 void
122 My_lily_lexer::LexerError(char const *s)
123 {
124     if (include_stack_.empty()) {
125         *mlog << "error at EOF" << s << '\n';
126     } else {
127         char const* ch_C = here_ch_C();
128         if ( ch_C ) {
129             ch_C--;
130             while (isspace(*ch_C == ' ' ))
131                     ch_C--;
132             ch_C++;
133         }
134         errorlevel_i_ |= 1;
135         error( s, ch_C );
136     }
137 }
138