+/* The syntax mode for which a syntax file is intended. */
+enum lex_syntax_mode
+ {
+ LEX_SYNTAX_AUTO, /* Try to guess intent. */
+ LEX_SYNTAX_INTERACTIVE, /* Interactive mode. */
+ LEX_SYNTAX_BATCH /* Batch mode. */
+ };
+
+/* Handling of errors. */
+enum lex_error_mode
+ {
+ LEX_ERROR_INTERACTIVE, /* Always continue to next command. */
+ 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 lex_syntax_mode syntax;
+ enum lex_error_mode error;
+ char *file_name; /* NULL if not associated with a file. */
+ int line_number; /* 1-based initial line number, 0 if none. */
+ };
+
+/* 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 (*close) (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 lex_syntax_mode syntax,
+ enum lex_error_mode error);
+struct lex_reader *lex_reader_for_string (const char *);
+struct lex_reader *lex_reader_for_format (const char *, ...)
+ PRINTF_FORMAT (1, 2);
+struct lex_reader *lex_reader_for_substring_nocopy (struct substring);
+