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