]> git.donarmstrong.com Git - lilypond.git/blob - lily/my-lily-lexer.cc
release: 1.3.72
[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--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include <strstream.h>
10 #include <ctype.h>
11
12 #include "interval.hh"
13 #include "identifier.hh"
14 #include "lily-guile.hh"
15 #include "parser.hh"
16 #include "keyword.hh"
17 #include "my-lily-lexer.hh"
18 #include "debug.hh"
19 #include "source-file.hh"
20 #include "main.hh"
21 #include "scope.hh"
22 #include "input.hh"
23 #include "moment.hh"
24
25 static Keyword_ent the_key_tab[]={
26   {"autochange", AUTOCHANGE},
27   {"spanrequest", SPANREQUEST},
28   {"commandspanrequest", COMMANDSPANREQUEST},  
29   {"simultaneous", SIMULTANEOUS},
30   {"sequential", SEQUENTIAL},
31   {"accepts", ACCEPTS},
32   {"alternative", ALTERNATIVE},
33   {"bar", BAR},
34   {"breathe", BREATHE},
35   {"char", CHAR_T},
36   {"chordmodifiers", CHORDMODIFIERS},
37   {"chords", CHORDS},
38   {"clef", CLEF},
39   {"cm", CM_T},
40   {"consists", CONSISTS},
41   {"consistsend", CONSISTSEND},
42   {"context", CONTEXT},
43   {"duration", DURATION},
44   {"font", FONT},
45   {"grace", GRACE},
46   {"header", HEADER},
47   {"in", IN_T},
48   {"lyrics", LYRICS},
49   {"key", KEY},
50   {"mark", MARK},
51   {"musicalpitch", MUSICAL_PITCH},
52   {"time", TIME_T},
53   {"times", TIMES},
54   {"midi", MIDI},
55   {"mm", MM_T},
56   {"name", NAME},
57   {"notenames", NOTENAMES},
58   {"notes", NOTES},
59   {"outputproperty", OUTPUTPROPERTY},
60   {"partial", PARTIAL},
61   {"paper", PAPER},
62   {"penalty", PENALTY},
63   {"property", PROPERTY},
64   {"pt", PT_T},
65   {"relative", RELATIVE},
66   {"remove", REMOVE},
67   {"repeat", REPEAT},
68   {"addlyrics", ADDLYRICS},
69   {"score", SCORE},
70   {"script", SCRIPT},
71   {"skip", SKIP},
72   {"textscript", TEXTSCRIPT},
73   {"tempo", TEMPO},
74   {"translator", TRANSLATOR},
75   {"transpose", TRANSPOSE},
76   {"type", TYPE},
77   {0,0}
78 };
79
80 My_lily_lexer::My_lily_lexer()
81 {
82   keytable_p_ = new Keyword_table (the_key_tab);
83   toplevel_scope_p_ = new Scope;
84   scope_l_arr_.push (toplevel_scope_p_);
85   errorlevel_i_ = 0;
86   main_input_b_ = false;
87 }
88
89 int
90 My_lily_lexer::lookup_keyword (String s)
91 {
92   return keytable_p_->lookup (s.ch_C ());
93 }
94
95 SCM
96 My_lily_lexer::lookup_identifier (String s)
97 {
98   SCM sym = ly_symbol2scm (s.ch_C());
99   
100   for (int i = scope_l_arr_.size (); i--; )
101     if (scope_l_arr_[i]->elem_b (sym))
102       return scope_l_arr_[i]->scm_elem(sym);
103   return SCM_UNSPECIFIED;
104 }
105
106 void
107 My_lily_lexer::start_main_input ()
108 {  
109   new_input (main_input_str_, source_global_l);
110   allow_includes_b_ = allow_includes_b_ &&  !(safe_global_b);
111 }
112
113 void
114 My_lily_lexer::set_identifier (String name_str, SCM s)
115 {
116   if (lookup_keyword (name_str) >= 0)
117     {
118       warning (  _f ("Identifier name is a keyword: `%s'", name_str));
119     }
120   
121   scope_l_arr_.top ()->set (name_str, s);
122 }
123
124 My_lily_lexer::~My_lily_lexer()
125 {
126   delete keytable_p_;
127   delete toplevel_scope_p_ ;
128 }
129
130
131
132 void
133 My_lily_lexer::LexerError (char const *s)
134 {
135   if (include_stack_.empty())
136     {
137       progress_indication (_f ("error at EOF: %s", s)+ String ("\n"));
138     }
139   else
140     {
141       errorlevel_i_ |= 1;
142       Input spot (source_file_l(),here_ch_C());
143       spot.error (s);
144     }
145 }
146
147 char
148 My_lily_lexer::escaped_char(char c) const
149 {
150   switch(c)
151     {
152     case 'n':
153       return '\n';
154     case 't':
155       return '\t';
156
157     case '\'':
158     case '\"':
159     case '\\':
160       return c;
161     }
162   return 0;
163 }
164
165 Input
166 My_lily_lexer::here_input () const
167 {
168   Source_file * f_l= source_file_l ();
169   return Input (f_l, (char*)here_ch_C ());
170 }