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"
13 #define YY_BUF_SIZE 16384
16 Includable_lexer::Includable_lexer()
18 yy_current_buffer = 0;
21 /** set the new input to s, remember old file.
24 Includable_lexer::new_input(String s, Sources * global_sources)
26 Source_file * sl = global_sources->get_file_l(s);
28 LexerError("Can't find file `" + s+ "'");
33 char_count_stack_.push(0);
34 if (yy_current_buffer)
35 state_stack_.push(yy_current_buffer);
36 cout << "[" << s<<flush;
37 include_stack_.push(sl);
40 ugh. We'd want to create a buffer from the bytes directly.
42 Whoops. The size argument to yy_create_buffer is not the
43 filelength but a BUFFERSIZE. Maybe this is why reading stdin fucks up.
45 Maybe this is also the reason why LilyPond sometimes crashed
46 mysteriously in yy_create_buffer() with a libc-malloc error
49 yy_switch_to_buffer(yy_create_buffer( sl->istream_l(), YY_BUF_SIZE ));
52 /** pop the inputstack. conceptually this is a destructor, but it
53 does not destruct the Source_file that Includable_lexer::new_input creates. */
55 Includable_lexer::close_input()
58 char_count_stack_.pop();
60 yy_delete_buffer(yy_current_buffer );
61 yy_current_buffer = 0;
62 if (state_stack_.empty()) {
65 yy_switch_to_buffer(state_stack_.pop());
71 Includable_lexer::here_ch_C()
73 if (include_stack_.empty())
75 return include_stack_.top()->ch_C() + char_count_stack_.top();
78 Includable_lexer::~Includable_lexer()
80 while (!include_stack_.empty()) {
85 Since we don't create the buffer state from the bytes directly, we
86 don't know about the location of the lexer. Add this as a
89 Includable_lexer::add_lexed_char(int count)
91 char_count_stack_.top() += count;
95 Includable_lexer::source_file_l()const
97 if (include_stack_.empty())
100 return include_stack_.top();