static bool
parse_commands (struct lexer *lexer, struct hmap *dummies)
{
- enum lex_syntax_mode syntax_mode;
- enum segmenter_mode mode;
struct string *outputs;
struct string input;
size_t n_values;
for (i = 0; i < n_values; i++)
ds_init_empty (&outputs[i]);
- syntax_mode = lex_get_syntax_mode (lexer);
- if (syntax_mode == LEX_SYNTAX_AUTO)
- mode = SEG_MODE_AUTO;
- else if (syntax_mode == LEX_SYNTAX_INTERACTIVE)
- mode = SEG_MODE_INTERACTIVE;
- else if (syntax_mode == LEX_SYNTAX_BATCH)
- mode = SEG_MODE_BATCH;
- else
- NOT_REACHED ();
- do_parse_commands (ds_ss (&input), mode, dummies, outputs, n_values);
+ do_parse_commands (ds_ss (&input), lex_get_syntax_mode (lexer),
+ dummies, outputs, n_values);
ds_destroy (&input);
const struct lex_reader_class *class)
{
reader->class = class;
- reader->syntax = LEX_SYNTAX_AUTO;
+ reader->syntax = SEG_MODE_AUTO;
reader->error = LEX_ERROR_CONTINUE;
reader->file_name = NULL;
reader->encoding = NULL;
/* Returns the syntax mode for the syntax file from which the current drawn is
- drawn. Returns LEX_SYNTAX_AUTO for a T_STOP token or if the command's
- source does not have line numbers.
+ drawn. Returns SEG_MODE_AUTO for a T_STOP token or if the command's source
+ does not have line numbers.
There is no version of this function that takes an N argument because
lookahead only works to the end of a command and any given command is always
within a single syntax file. */
-enum lex_syntax_mode
+enum segmenter_mode
lex_get_syntax_mode (const struct lexer *lexer)
{
struct lex_source *src = lex_source__ (lexer);
- return src == NULL ? LEX_SYNTAX_AUTO : src->reader->syntax;
+ return src == NULL ? SEG_MODE_AUTO : src->reader->syntax;
}
/* Returns the error mode for the syntax file from which the current drawn is
lex_source_create (struct lex_reader *reader)
{
struct lex_source *src;
- enum segmenter_mode mode;
src = xzalloc (sizeof *src);
src->reader = reader;
-
- if (reader->syntax == LEX_SYNTAX_AUTO)
- mode = SEG_MODE_AUTO;
- else if (reader->syntax == LEX_SYNTAX_INTERACTIVE)
- mode = SEG_MODE_INTERACTIVE;
- else if (reader->syntax == LEX_SYNTAX_BATCH)
- mode = SEG_MODE_BATCH;
- else
- NOT_REACHED ();
- segmenter_init (&src->segmenter, mode);
-
+ segmenter_init (&src->segmenter, reader->syntax);
src->tokens = deque_init (&src->deque, 4, sizeof *src->tokens);
lex_source_push_endcmd__ (src);
Returns a null pointer if FILE_NAME cannot be opened. */
struct lex_reader *
lex_reader_for_file (const char *file_name, const char *encoding,
- enum lex_syntax_mode syntax,
+ enum segmenter_mode syntax,
enum lex_error_mode error)
{
struct lex_file_reader *r;
r = xmalloc (sizeof *r);
lex_reader_init (&r->reader, &lex_string_reader_class);
- r->reader.syntax = LEX_SYNTAX_AUTO;
+ r->reader.syntax = SEG_MODE_AUTO;
r->reader.encoding = xstrdup_if_nonnull (encoding);
r->s = s;
r->offset = 0;
#include "data/identifier.h"
#include "data/variable.h"
+#include "language/lexer/segment.h"
#include "libpspp/cast.h"
#include "libpspp/compiler.h"
#include "libpspp/prompt.h"
struct lexer;
-/* 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
{
struct lex_reader
{
const struct lex_reader_class *class;
- enum lex_syntax_mode syntax;
+ enum segmenter_mode syntax;
enum lex_error_mode error;
char *encoding;
char *file_name; /* NULL if not associated with a file. */
/* 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 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 (4, 0);
/* Error handling. */
-enum lex_syntax_mode lex_get_syntax_mode (const struct lexer *);
+enum segmenter_mode lex_get_syntax_mode (const struct lexer *);
enum lex_error_mode lex_get_error_mode (const struct lexer *);
void lex_discard_rest_of_command (struct lexer *);
void lex_interactive_reset (struct lexer *);
static int
do_insert (struct lexer *lexer, struct dataset *ds, enum variant variant)
{
- enum lex_syntax_mode syntax_mode;
+ enum segmenter_mode syntax_mode;
enum lex_error_mode error_mode;
char *relative_name;
char *filename;
}
lex_get (lexer);
- syntax_mode = LEX_SYNTAX_INTERACTIVE;
+ syntax_mode = SEG_MODE_INTERACTIVE;
error_mode = LEX_ERROR_CONTINUE;
cd = false;
status = CMD_FAILURE;
{
lex_match (lexer, T_EQUALS);
if (lex_match_id (lexer, "INTERACTIVE"))
- syntax_mode = LEX_SYNTAX_INTERACTIVE;
+ syntax_mode = SEG_MODE_INTERACTIVE;
else if (lex_match_id (lexer, "BATCH"))
- syntax_mode = LEX_SYNTAX_BATCH;
+ syntax_mode = SEG_MODE_BATCH;
else if (lex_match_id (lexer, "AUTO"))
- syntax_mode = LEX_SYNTAX_AUTO;
+ syntax_mode = SEG_MODE_AUTO;
else
{
lex_error_expecting (lexer, "BATCH", "INTERACTIVE", "AUTO");
struct lex_reader *
lex_reader_for_gtk_text_buffer (GtkTextBuffer *buffer,
GtkTextIter start, GtkTextIter stop,
- enum lex_syntax_mode syntax_mode)
+ enum segmenter_mode syntax_mode)
{
struct lex_gtk_text_buffer_reader *r = xmalloc (sizeof *r);
struct lex_reader *lex_reader_for_gtk_text_buffer (
GtkTextBuffer *buffer,
GtkTextIter start, GtkTextIter stop,
- enum lex_syntax_mode);
+ enum segmenter_mode);
#endif
const gchar *what = g_variant_get_string (new_state, NULL);
if (0 == g_strcmp0 (what, "auto"))
- sw->syntax_mode = LEX_SYNTAX_AUTO;
+ sw->syntax_mode = SEG_MODE_AUTO;
else if (0 == g_strcmp0 (what, "interactive"))
- sw->syntax_mode = LEX_SYNTAX_INTERACTIVE;
+ sw->syntax_mode = SEG_MODE_INTERACTIVE;
else if (0 == g_strcmp0 (what, "batch"))
- sw->syntax_mode = LEX_SYNTAX_BATCH;
+ sw->syntax_mode = SEG_MODE_BATCH;
else
g_warn_if_reached ();
}
NULL);
window->encoding = NULL;
- window->syntax_mode = LEX_SYNTAX_AUTO;
+ window->syntax_mode = SEG_MODE_AUTO;
window->cliptext = NULL;
window->dispose_has_run = FALSE;
gchar *encoding; /* File's encoding. */
GtkWidget *sb;
guint text_context;
- enum lex_syntax_mode syntax_mode;
+ enum segmenter_mode syntax_mode;
GtkPrintSettings *print_settings;
GtkSourcePrintCompositor *compositor;
static struct session *the_session;
static void add_syntax_reader (struct lexer *, const char *file_name,
- const char *encoding, enum lex_syntax_mode);
+ const char *encoding, enum segmenter_mode);
static void bug_handler(int sig);
static void fpu_init (void);
static void output_msg (const struct msg *, void *);
{
struct terminal_opts *terminal_opts;
struct argv_parser *parser;
- enum lex_syntax_mode syntax_mode;
+ enum segmenter_mode syntax_mode;
char *syntax_encoding;
bool process_statrc;
struct lexer *lexer;
char *rc = include_path_search ("rc");
if (rc != NULL)
{
- add_syntax_reader (lexer, rc, "Auto", LEX_SYNTAX_AUTO);
+ add_syntax_reader (lexer, rc, "Auto", SEG_MODE_AUTO);
free (rc);
}
}
static void
add_syntax_reader (struct lexer *lexer, const char *file_name,
- const char *encoding, enum lex_syntax_mode syntax_mode)
+ const char *encoding, enum segmenter_mode syntax_mode)
{
struct lex_reader *reader;
bool has_output_driver;
bool has_terminal_driver;
bool has_error_file;
- enum lex_syntax_mode *syntax_mode;
+ enum segmenter_mode *syntax_mode;
bool *process_statrc;
char **syntax_encoding;
char *table_look;
break;
case OPT_BATCH:
- *to->syntax_mode = LEX_SYNTAX_BATCH;
+ *to->syntax_mode = SEG_MODE_BATCH;
break;
case OPT_INTERACTIVE:
- *to->syntax_mode = LEX_SYNTAX_INTERACTIVE;
+ *to->syntax_mode = SEG_MODE_INTERACTIVE;
break;
case OPT_SYNTAX_ENCODING:
struct terminal_opts *
terminal_opts_init (struct argv_parser *ap,
- enum lex_syntax_mode *syntax_mode, bool *process_statrc,
+ enum segmenter_mode *syntax_mode, bool *process_statrc,
char **syntax_encoding)
{
struct terminal_opts *to;
- *syntax_mode = LEX_SYNTAX_AUTO;
+ *syntax_mode = SEG_MODE_AUTO;
*process_statrc = true;
*syntax_encoding = "Auto";
struct terminal_opts;
struct terminal_opts *terminal_opts_init (struct argv_parser *,
- enum lex_syntax_mode *,
+ enum segmenter_mode *,
bool *process_statrc,
char **syntax_encoding);
void terminal_opts_done (struct terminal_opts *, int argc, char *argv[]);
r = xzalloc (sizeof *r);
r->reader.class = &terminal_reader_class;
- r->reader.syntax = LEX_SYNTAX_INTERACTIVE;
+ r->reader.syntax = SEG_MODE_INTERACTIVE;
r->reader.error = LEX_ERROR_TERMINAL;
r->reader.file_name = NULL;
r->s = ss_empty ();
settings_init ();
struct lex_reader *reader = lex_reader_for_file (input_file_name, NULL,
- LEX_SYNTAX_AUTO,
+ SEG_MODE_AUTO,
LEX_ERROR_CONTINUE);
if (!reader)
exit (1);