2 includable-lexer.cc -- implement Includable_lexer
4 source file of the LilyPond music typesetter
6 (c) 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "includable-lexer.hh"
12 #include "source-file.hh"
17 #define YY_BUF_SIZE 16384
21 #define YY_START ((yy_start - 1) / 2)
22 #define YYSTATE YY_START
25 Includable_lexer::Includable_lexer ()
27 yy_current_buffer
= 0;
28 allow_includes_b_
= true;
31 /** set the new input to s, remember old file.
34 Includable_lexer::new_input (String s
, Sources
* global_sources
)
36 if (!allow_includes_b_
)
38 LexerError ("include files are disallowed.");
42 Source_file
* sl
= global_sources
->get_file_l (s
);
45 String msg
= _f ("can't find file: `%s\'", s
);
46 LexerError (msg
.ch_C ());
49 filename_str_arr_
.push (sl
->name_str ());
51 char_count_stack_
.push (0);
52 if (yy_current_buffer
)
53 state_stack_
.push (yy_current_buffer
);
54 *mlog
<< "[" << s
<< flush
;
55 include_stack_
.push (sl
);
58 ugh. We'd want to create a buffer from the bytes directly.
60 Whoops. The size argument to yy_create_buffer is not the
61 filelength but a BUFFERSIZE. Maybe this is why reading stdin fucks up.
64 yy_switch_to_buffer (yy_create_buffer (sl
->istream_l (), YY_BUF_SIZE
));
68 Includable_lexer::new_input (String name
, String data
, Sources
* sources
)
70 Source_file
* file
= new Source_file (name
, data
);
72 filename_str_arr_
.push (name
);
74 char_count_stack_
.push (0);
75 if (yy_current_buffer
)
76 state_stack_
.push (yy_current_buffer
);
77 *mlog
<< "[" << name
<< flush
;
78 include_stack_
.push (file
);
80 yy_switch_to_buffer (yy_create_buffer (file
->istream_l (), YY_BUF_SIZE
));
83 /** pop the inputstack. conceptually this is a destructor, but it
84 does not destruct the Source_file that Includable_lexer::new_input creates. */
86 Includable_lexer::close_input ()
88 include_stack_
.pop ();
89 char_count_stack_
.pop ();
91 yy_delete_buffer (yy_current_buffer
);
92 yy_current_buffer
= 0;
93 if (state_stack_
.empty ())
95 yy_current_buffer
= 0;
100 yy_switch_to_buffer (state_stack_
.pop ());
106 Includable_lexer::here_ch_C ()
108 if (include_stack_
.empty ())
110 return include_stack_
.top ()->ch_C () + char_count_stack_
.top ();
113 Includable_lexer::~Includable_lexer ()
115 while (!include_stack_
.empty ())
121 Since we don't create the buffer state from the bytes directly, we
122 don't know about the location of the lexer. Add this as a
125 Includable_lexer::add_lexed_char (int count
)
127 char_count_stack_
.top () += count
;
131 Includable_lexer::source_file_l () const
133 if (include_stack_
.empty ())
136 return include_stack_
.top ();