2 includable-lexer.cc -- implement Includable_lexer
4 source file of the LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
8 #include "includable-lexer.hh"
9 #include "source-file.hh"
12 Includable_lexer::Includable_lexer()
14 yy_current_buffer = 0;
17 /** set the new input to s, remember old file.
20 Includable_lexer::new_input(String s, Sources * global_sources)
22 Source_file * sl = global_sources->get_file_l(s);
24 LexerError("can't find file");
27 char_count_stack_.push(0);
28 if (yy_current_buffer)
29 state_stack_.push(yy_current_buffer);
30 cout << "[" << s<<flush;
31 include_stack_.push(sl);
33 // ugh. We'd want to create a buffer from the bytes directly.
34 yy_switch_to_buffer(yy_create_buffer( sl->istream_l(), sl->length_off() ));
37 /** pop the inputstack. conceptually this is a destructor, but it
38 does not destruct the Source_file it creates. */
40 Includable_lexer::close_input()
43 char_count_stack_.pop();
45 yy_delete_buffer(yy_current_buffer );
46 if (state_stack_.empty()) {
47 yy_current_buffer = 0;
50 yy_switch_to_buffer(state_stack_.pop());
56 Includable_lexer::here_ch_C()
58 if (include_stack_.empty())
60 return include_stack_.top()->ch_C() + char_count_stack_.top();
63 Includable_lexer::~Includable_lexer()
65 while (!include_stack_.empty()) {
70 Since we don't create the buffer state from the bytes directly, we
71 don't know about the location of the lexer. Add this as a
74 Includable_lexer::add_lexed_char(int count)
76 char_count_stack_.top() += count;