comparison libinterp/parse-tree/oct-parse.yy @ 16145:edddf8903f15

maint: reorder functions in oct-parse.yy
author John W. Eaton <jwe@octave.org>
date Wed, 27 Feb 2013 16:05:59 -0500
parents 26d65d677557
children ed8ce5da525f
comparison
equal deleted inserted replaced
16144:8f1f8a5cdc96 16145:edddf8903f15
1497 yyerror (const char *s) 1497 yyerror (const char *s)
1498 { 1498 {
1499 curr_parser->bison_error (s); 1499 curr_parser->bison_error (s);
1500 } 1500 }
1501 1501
1502 void
1503 octave_parser::bison_error (const char *s)
1504 {
1505 int err_col = curr_lexer->current_input_column - 1;
1506
1507 std::ostringstream output_buf;
1508
1509 if (reading_fcn_file || reading_script_file || reading_classdef_file)
1510 output_buf << "parse error near line " << curr_lexer->input_line_number
1511 << " of file " << curr_fcn_file_full_name;
1512 else
1513 output_buf << "parse error:";
1514
1515 if (s && strcmp (s, "parse error") != 0)
1516 output_buf << "\n\n " << s;
1517
1518 output_buf << "\n\n";
1519
1520 if (! current_input_line.empty ())
1521 {
1522 size_t len = current_input_line.length ();
1523
1524 if (current_input_line[len-1] == '\n')
1525 current_input_line.resize (len-1);
1526
1527 // Print the line, maybe with a pointer near the error token.
1528
1529 output_buf << ">>> " << current_input_line << "\n";
1530
1531 if (err_col == 0)
1532 err_col = len;
1533
1534 for (int i = 0; i < err_col + 3; i++)
1535 output_buf << " ";
1536
1537 output_buf << "^";
1538 }
1539
1540 output_buf << "\n";
1541
1542 std::string msg = output_buf.str ();
1543
1544 parse_error ("%s", msg.c_str ());
1545 }
1546
1547 int 1502 int
1548 octave_parser::run (void) 1503 octave_parser::run (void)
1549 { 1504 {
1550 return octave_parse (); 1505 return octave_parse ();
1551 } 1506 }
3101 set_stmt_print_flag (list, sep, warn_missing_semi); 3056 set_stmt_print_flag (list, sep, warn_missing_semi);
3102 3057
3103 list->append (stmt); 3058 list->append (stmt);
3104 3059
3105 return list; 3060 return list;
3061 }
3062
3063 void
3064 octave_parser::bison_error (const char *s)
3065 {
3066 int err_col = curr_lexer->current_input_column - 1;
3067
3068 std::ostringstream output_buf;
3069
3070 if (reading_fcn_file || reading_script_file || reading_classdef_file)
3071 output_buf << "parse error near line " << curr_lexer->input_line_number
3072 << " of file " << curr_fcn_file_full_name;
3073 else
3074 output_buf << "parse error:";
3075
3076 if (s && strcmp (s, "parse error") != 0)
3077 output_buf << "\n\n " << s;
3078
3079 output_buf << "\n\n";
3080
3081 if (! current_input_line.empty ())
3082 {
3083 size_t len = current_input_line.length ();
3084
3085 if (current_input_line[len-1] == '\n')
3086 current_input_line.resize (len-1);
3087
3088 // Print the line, maybe with a pointer near the error token.
3089
3090 output_buf << ">>> " << current_input_line << "\n";
3091
3092 if (err_col == 0)
3093 err_col = len;
3094
3095 for (int i = 0; i < err_col + 3; i++)
3096 output_buf << " ";
3097
3098 output_buf << "^";
3099 }
3100
3101 output_buf << "\n";
3102
3103 std::string msg = output_buf.str ();
3104
3105 parse_error ("%s", msg.c_str ());
3106 } 3106 }
3107 3107
3108 static void 3108 static void
3109 safe_fclose (FILE *f) 3109 safe_fclose (FILE *f)
3110 { 3110 {