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