LEFT | RIGHT |
1 /* | 1 /* |
2 This file is part of LilyPond, the GNU music typesetter. | 2 This file is part of LilyPond, the GNU music typesetter. |
3 | 3 |
4 Copyright (C) 1997--2020 Han-Wen Nienhuys <hanwen@xs4all.nl> | 4 Copyright (C) 1997--2020 Han-Wen Nienhuys <hanwen@xs4all.nl> |
5 | 5 |
6 LilyPond is free software: you can redistribute it and/or modify | 6 LilyPond is free software: you can redistribute it and/or modify |
7 it under the terms of the GNU General Public License as published by | 7 it under the terms of the GNU General Public License as published by |
8 the Free Software Foundation, either version 3 of the License, or | 8 the Free Software Foundation, either version 3 of the License, or |
9 (at your option) any later version. | 9 (at your option) any later version. |
10 | 10 |
11 LilyPond is distributed in the hope that it will be useful, | 11 LilyPond is distributed in the hope that it will be useful, |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 GNU General Public License for more details. | 14 GNU General Public License for more details. |
15 | 15 |
16 You should have received a copy of the GNU General Public License | 16 You should have received a copy of the GNU General Public License |
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>. | 17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>. |
18 */ | 18 */ |
19 | 19 |
20 #include "lily-lexer.hh" | 20 #include "lily-lexer.hh" |
21 | |
22 #include <cctype> | |
23 #include <sstream> | |
24 | 21 |
25 #include "context.hh" // for nested_property_alist | 22 #include "context.hh" // for nested_property_alist |
26 #include "international.hh" | 23 #include "international.hh" |
27 #include "interval.hh" | 24 #include "interval.hh" |
28 #include "main.hh" | 25 #include "main.hh" |
29 #include "moment.hh" | 26 #include "moment.hh" |
30 #include "parser.hh" | 27 #include "parser.hh" |
31 #include "scm-hash.hh" | 28 #include "scm-hash.hh" |
32 #include "source-file.hh" | 29 #include "source-file.hh" |
33 #include "warn.hh" | 30 #include "warn.hh" |
34 #include "program-option.hh" | 31 #include "program-option.hh" |
35 #include "lily-parser.hh" | 32 #include "lily-parser.hh" |
36 #include "ly-module.hh" | 33 #include "ly-module.hh" |
37 | 34 |
| 35 #include <cctype> |
| 36 #include <sstream> |
| 37 #include <unordered_map> |
| 38 |
38 using std::string; | 39 using std::string; |
39 | 40 |
40 class Keyword_ent | 41 static std::unordered_map<std::string, int> keytable{ |
41 { | |
42 public: | |
43 char const *name_; | |
44 int tokcode_; | |
45 }; | |
46 | |
47 static Keyword_ent the_key_tab[] | |
48 = | |
49 { | |
50 {"accepts", ACCEPTS}, | 42 {"accepts", ACCEPTS}, |
51 {"addlyrics", ADDLYRICS}, | 43 {"addlyrics", ADDLYRICS}, |
52 {"alias", ALIAS}, | 44 {"alias", ALIAS}, |
53 {"alternative", ALTERNATIVE}, | 45 {"alternative", ALTERNATIVE}, |
54 {"book", BOOK}, | 46 {"book", BOOK}, |
55 {"bookpart", BOOKPART}, | 47 {"bookpart", BOOKPART}, |
56 {"change", CHANGE}, | 48 {"change", CHANGE}, |
57 {"chordmode", CHORDMODE}, | 49 {"chordmode", CHORDMODE}, |
58 {"chords", CHORDS}, | 50 {"chords", CHORDS}, |
59 {"consists", CONSISTS}, | 51 {"consists", CONSISTS}, |
(...skipping 25 matching lines...) Expand all Loading... |
85 {"rest", REST}, | 77 {"rest", REST}, |
86 {"revert", REVERT}, | 78 {"revert", REVERT}, |
87 {"score", SCORE}, | 79 {"score", SCORE}, |
88 {"sequential", SEQUENTIAL}, | 80 {"sequential", SEQUENTIAL}, |
89 {"set", SET}, | 81 {"set", SET}, |
90 {"simultaneous", SIMULTANEOUS}, | 82 {"simultaneous", SIMULTANEOUS}, |
91 {"tempo", TEMPO}, | 83 {"tempo", TEMPO}, |
92 {"type", TYPE}, | 84 {"type", TYPE}, |
93 {"unset", UNSET}, | 85 {"unset", UNSET}, |
94 {"with", WITH}, | 86 {"with", WITH}, |
95 {0, 0} | |
96 }; | 87 }; |
97 | 88 |
98 Lily_lexer::Lily_lexer (Sources *sources, Lily_parser *parser) | 89 Lily_lexer::Lily_lexer (Sources *sources, Lily_parser *parser) |
99 { | 90 { |
100 parser_ = parser; | 91 parser_ = parser; |
101 | |
102 Keyword_ent *tab = the_key_tab; | |
103 while (tab->name_) | |
104 keytable_[tab->name_] = tab->tokcode_; | |
105 | 92 |
106 chordmodifier_tab_ = SCM_EOL; | 93 chordmodifier_tab_ = SCM_EOL; |
107 pitchname_tab_stack_ = SCM_EOL; | 94 pitchname_tab_stack_ = SCM_EOL; |
108 sources_ = sources; | 95 sources_ = sources; |
109 scopes_ = SCM_EOL; | 96 scopes_ = SCM_EOL; |
110 error_level_ = 0; | 97 error_level_ = 0; |
111 is_main_input_ = false; | 98 is_main_input_ = false; |
112 main_input_level_ = 0; | 99 main_input_level_ = 0; |
113 start_module_ = SCM_EOL; | 100 start_module_ = SCM_EOL; |
114 extra_tokens_ = SCM_EOL; | 101 extra_tokens_ = SCM_EOL; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 scm_set_current_module (scm_car (scopes_)); | 167 scm_set_current_module (scm_car (scopes_)); |
181 else | 168 else |
182 scm_set_current_module (start_module_); | 169 scm_set_current_module (start_module_); |
183 | 170 |
184 return old; | 171 return old; |
185 } | 172 } |
186 | 173 |
187 int | 174 int |
188 Lily_lexer::lookup_keyword (const string &s) | 175 Lily_lexer::lookup_keyword (const string &s) |
189 { | 176 { |
190 auto const &it = keytable_.find (s); | 177 auto const &it = keytable.find (s); |
191 if (it == keytable_.end ()) | 178 if (it == keytable.end ()) |
192 { | 179 { |
193 return -1; | 180 return -1; |
194 } | 181 } |
195 return it->second; | 182 return it->second; |
196 } | 183 } |
197 | 184 |
198 SCM | 185 SCM |
199 Lily_lexer::lookup_identifier_symbol (SCM sym) | 186 Lily_lexer::lookup_identifier_symbol (SCM sym) |
200 { | 187 { |
201 for (SCM s = scopes_; scm_is_pair (s); s = scm_cdr (s)) | 188 for (SCM s = scopes_; scm_is_pair (s); s = scm_cdr (s)) |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 scm_display (scopes_, port); | 362 scm_display (scopes_, port); |
376 scm_puts (" >", port); | 363 scm_puts (" >", port); |
377 return 1; | 364 return 1; |
378 } | 365 } |
379 | 366 |
380 bool | 367 bool |
381 Lily_lexer::is_clean () const | 368 Lily_lexer::is_clean () const |
382 { | 369 { |
383 return include_stack_.empty (); | 370 return include_stack_.empty (); |
384 } | 371 } |
LEFT | RIGHT |