staff-symbol-referencer.cc: Junk redundant functions.
[lilypond.git] / lily / includable-lexer.cc
blob617b1ace32ad706392b45bf797048eafd57ef7a8
1 /*
2 includable-lexer.cc -- implement Includable_lexer
4 source file of the LilyPond music typesetter
6 (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "includable-lexer.hh"
11 #include <sstream>
12 using namespace std;
14 #include "config.hh"
16 #include "file-path.hh"
17 #include "international.hh"
18 #include "main.hh"
19 #include "source-file.hh"
20 #include "sources.hh"
21 #include "warn.hh"
23 #ifndef YY_BUF_SIZE
24 #define YY_BUF_SIZE 16384
25 #endif
27 #ifndef YY_START
28 #define YY_START \
29 ((yy_start - 1) / 2)
30 #define YYSTATE YY_START
31 #endif
33 /* Flex >= 2.5.29 has include stack; but we don't use that yet. */
34 #if !HAVE_FLEXLEXER_YY_CURRENT_BUFFER
35 #define yy_current_buffer \
36 (yy_buffer_stack != 0 ? yy_buffer_stack[yy_buffer_stack_top] : 0)
37 #endif
39 Includable_lexer::Includable_lexer ()
41 #if HAVE_FLEXLEXER_YY_CURRENT_BUFFER
42 yy_current_buffer = 0;
43 #endif
46 /** Set the new input file to NAME, remember old file. */
47 void
48 Includable_lexer::new_input (string name, Sources *sources)
50 Source_file *file = sources->get_file (&name);
51 if (!file)
53 string msg = _f ("cannot find file: `%s'", name);
54 msg += "\n";
55 msg += _f ("(search path: `%s')",
56 sources->path_->to_string ().c_str ());
57 LexerError (msg.c_str ());
58 return;
60 file_name_strings_.push_back (file->name_string ());
62 char_count_stack_.push_back (0);
63 if (yy_current_buffer)
64 state_stack_.push_back (yy_current_buffer);
66 if (be_verbose_global)
67 progress_indication (string ("[") + name);
69 include_stack_.push_back (file);
71 /* Ugh. We'd want to create a buffer from the bytes directly.
73 Whoops. The size argument to yy_create_buffer is not the
74 filelength but a BUFFERSIZE. Maybe this is why reading stdin fucks up. */
75 yy_switch_to_buffer (yy_create_buffer (file->get_istream (), YY_BUF_SIZE));
78 void
79 Includable_lexer::new_input (string name, string data, Sources *sources)
81 Source_file *file = new Source_file (name, data);
82 sources->add (file);
83 file_name_strings_.push_back (name);
85 char_count_stack_.push_back (0);
86 if (yy_current_buffer)
87 state_stack_.push_back (yy_current_buffer);
89 if (be_verbose_global)
90 progress_indication (string ("[") + name);
91 include_stack_.push_back (file);
93 yy_switch_to_buffer (yy_create_buffer (file->get_istream (), YY_BUF_SIZE));
96 /** pop the inputstack. conceptually this is a destructor, but it
97 does not destruct the Source_file that Includable_lexer::new_input
98 creates. */
99 bool
100 Includable_lexer::close_input ()
102 include_stack_.pop_back ();
103 char_count_stack_.pop_back ();
104 if (be_verbose_global)
105 progress_indication ("]");
106 yy_delete_buffer (yy_current_buffer);
107 #if HAVE_FLEXLEXER_YY_CURRENT_BUFFER
108 yy_current_buffer = 0;
109 #endif
110 if (state_stack_.empty ())
112 #if HAVE_FLEXLEXER_YY_CURRENT_BUFFER
113 yy_current_buffer = 0;
114 #endif
115 return false;
117 yy_switch_to_buffer (state_stack_.back ());
118 state_stack_.pop_back ();
119 return true;
122 char const *
123 Includable_lexer::here_str0 () const
125 if (include_stack_.empty ())
126 return 0;
127 return include_stack_.back ()->c_str () + char_count_stack_.back ();
130 Includable_lexer::~Includable_lexer ()
132 while (!include_stack_.empty ())
133 close_input ();
136 Source_file *
137 Includable_lexer::get_source_file () const
139 if (include_stack_.empty ())
140 return 0;
141 return include_stack_.back ();