comparison libinterp/parse-tree/lex.ll @ 16098:24b3800d30e7

move octave_read to lex.ll * lex.ll (octave_read): Move here from input.cc and make static. Return YY_NULL when no more characters are available. Error here if eof is not set when no more characters are available instead of in YY_INPUT macro. * input.h, input.cc (get_user_input): Now extern.
author John W. Eaton <jwe@octave.org>
date Mon, 25 Feb 2013 01:04:15 -0500
parents 6437fa7263dd
children 6b26e18d1dcb
comparison
equal deleted inserted replaced
16097:2f4fa62089b3 16098:24b3800d30e7
101 101
102 #ifdef YY_INPUT 102 #ifdef YY_INPUT
103 #undef YY_INPUT 103 #undef YY_INPUT
104 #endif 104 #endif
105 #define YY_INPUT(buf, result, max_size) \ 105 #define YY_INPUT(buf, result, max_size) \
106 if ((result = octave_read (buf, max_size)) < 0) \ 106 result = octave_read (buf, max_size)
107 YY_FATAL_ERROR ("octave_read () in flex scanner failed");
108 107
109 // Try to avoid crashing out completely on fatal scanner errors. 108 // Try to avoid crashing out completely on fatal scanner errors.
110 // The call to yy_fatal_error should never happen, but it avoids a 109 // The call to yy_fatal_error should never happen, but it avoids a
111 // 'static function defined but not used' warning from gcc. 110 // 'static function defined but not used' warning from gcc.
112 111
320 static bool have_continuation (bool trailing_comments_ok = true); 319 static bool have_continuation (bool trailing_comments_ok = true);
321 static bool have_ellipsis_continuation (bool trailing_comments_ok = true); 320 static bool have_ellipsis_continuation (bool trailing_comments_ok = true);
322 static void scan_for_comments (const char *); 321 static void scan_for_comments (const char *);
323 static yum_yum eat_whitespace (void); 322 static yum_yum eat_whitespace (void);
324 static yum_yum eat_continuation (void); 323 static yum_yum eat_continuation (void);
324 static int octave_read (char *buf, unsigned int max_size);
325 static void maybe_warn_separator_insert (char sep); 325 static void maybe_warn_separator_insert (char sep);
326 static void gripe_single_quote_string (void); 326 static void gripe_single_quote_string (void);
327 static void gripe_matlab_incompatible (const std::string& msg); 327 static void gripe_matlab_incompatible (const std::string& msg);
328 static void maybe_gripe_matlab_incompatible_comment (char c); 328 static void maybe_gripe_matlab_incompatible_comment (char c);
329 static void gripe_matlab_incompatible_continuation (void); 329 static void gripe_matlab_incompatible_continuation (void);
3546 3546
3547 void 3547 void
3548 prep_lexer_for_function_file (void) 3548 prep_lexer_for_function_file (void)
3549 { 3549 {
3550 BEGIN (FUNCTION_FILE_BEGIN); 3550 BEGIN (FUNCTION_FILE_BEGIN);
3551 }
3552
3553 static int
3554 octave_read (char *buf, unsigned max_size)
3555 {
3556 static const char * const eol = "\n";
3557 static std::string input_buf;
3558 static const char *pos = 0;
3559 static size_t chars_left = 0;
3560 static bool eof = false;
3561
3562 int status = 0;
3563
3564 if (chars_left == 0)
3565 {
3566 pos = 0;
3567
3568 input_buf = get_user_input (eof);
3569
3570 chars_left = input_buf.length ();
3571
3572 pos = input_buf.c_str ();
3573 }
3574
3575 if (chars_left > 0)
3576 {
3577 size_t len = max_size > chars_left ? chars_left : max_size;
3578 assert (len > 0);
3579
3580 memcpy (buf, pos, len);
3581
3582 chars_left -= len;
3583 pos += len;
3584
3585 // Make sure input ends with a new line character.
3586 if (chars_left == 0 && buf[len-1] != '\n')
3587 {
3588 if (len < max_size)
3589 {
3590 // There is enough room to plug the newline character in
3591 // the buffer.
3592 buf[len++] = '\n';
3593 }
3594 else
3595 {
3596 // There isn't enough room to plug the newline character
3597 // in the buffer so make sure it is returned on the next
3598 // octave_read call.
3599 pos = eol;
3600 chars_left = 1;
3601 }
3602 }
3603
3604 status = len;
3605 }
3606 else
3607 {
3608 status = YY_NULL;
3609
3610 if (! eof)
3611 YY_FATAL_ERROR ("octave_read () in flex scanner failed");
3612 }
3613
3614 return status;
3551 } 3615 }
3552 3616
3553 static void 3617 static void
3554 maybe_warn_separator_insert (char sep) 3618 maybe_warn_separator_insert (char sep)
3555 { 3619 {