+struct lex_source;
+struct macro;
+
+/* Handling of errors. */
+enum lex_error_mode
+ {
+ LEX_ERROR_TERMINAL, /* Discard input line and continue reading. */
+ LEX_ERROR_CONTINUE, /* Continue to next command, except for
+ cascading failures. */
+ LEX_ERROR_STOP /* Stop processing. */
+ };
+
+/* Reads a single syntax file as a stream of bytes encoded in UTF-8.
+
+ Not opaque. */
+struct lex_reader
+ {
+ const struct lex_reader_class *class;
+ enum segmenter_mode syntax;
+ enum lex_error_mode error;
+ char *encoding;
+ char *file_name; /* NULL if not associated with a file. */
+ int line_number; /* 1-based initial line number, 0 if none. */
+ bool eof;
+ };
+
+/* An implementation of a lex_reader. */
+struct lex_reader_class
+ {
+ /* Reads up to N bytes of data from READER into N. Returns the positive
+ number of bytes read if successful, or zero at end of input or on
+ error.
+
+ STYLE provides a hint to interactive readers as to what kind of syntax
+ is being read right now. */
+ size_t (*read) (struct lex_reader *reader, char *buf, size_t n,
+ enum prompt_style style);
+
+ /* Closes and destroys READER, releasing any allocated storage.
+
+ The caller will free the 'file_name' member of READER, so the
+ implementation should not do so. */
+ void (*destroy) (struct lex_reader *reader);
+ };
+
+/* Helper functions for lex_reader. */
+void lex_reader_init (struct lex_reader *, const struct lex_reader_class *);
+void lex_reader_set_file_name (struct lex_reader *, const char *file_name);
+
+/* Creating various kinds of lex_readers. */
+struct lex_reader *lex_reader_for_file (const char *file_name,
+ const char *encoding,
+ enum segmenter_mode syntax,
+ enum lex_error_mode error);
+struct lex_reader *lex_reader_for_string (const char *, const char *encoding);
+struct lex_reader *lex_reader_for_format (const char *, const char *, ...)
+ PRINTF_FORMAT (1, 3);
+struct lex_reader *lex_reader_for_substring_nocopy (struct substring, const char *encoding);