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 `" + s+ "'");
29 char_count_stack_.push(0);
30 if (yy_current_buffer)
31 state_stack_.push(yy_current_buffer);
32 cout << "[" << s<<flush;
33 include_stack_.push(sl);
35 // ugh. We'd want to create a buffer from the bytes directly.
36 yy_switch_to_buffer(yy_create_buffer( sl->istream_l(), sl->length_off() ));
39 /** pop the inputstack. conceptually this is a destructor, but it
40 does not destruct the Source_file that Includable_lexer::new_input creates. */
42 Includable_lexer::close_input()
45 char_count_stack_.pop();
47 yy_delete_buffer(yy_current_buffer );
48 yy_current_buffer = 0;
49 if (state_stack_.empty()) {
52 yy_switch_to_buffer(state_stack_.pop());
58 Includable_lexer::here_ch_C()
60 if (include_stack_.empty())
62 return include_stack_.top()->ch_C() + char_count_stack_.top();
65 Includable_lexer::~Includable_lexer()
67 while (!include_stack_.empty()) {
72 Since we don't create the buffer state from the bytes directly, we
73 don't know about the location of the lexer. Add this as a
76 Includable_lexer::add_lexed_char(int count)
78 char_count_stack_.top() += count;
82 Includable_lexer::source_file_l()const
84 if (include_stack_.empty())
87 return include_stack_.top();