# HG changeset patch # User John W. Eaton # Date 1363036236 14400 # Node ID 1bbc2fc552cfe1393b6178799c850389bdea5edb # Parent 8c17cd3704770beda3ff003e2e9d631a1727fbb7 adjust line and column info when inserting new text in lexer input stream * lex.ll: Adjust line and column position info when inserting text that was not part of the original input stream. (octave_lexer::text_yyinput, octave_lexer::xunput): Don't update line and column info. ({NL}): Increment line number and reset column number. diff --git a/libinterp/parse-tree/lex.ll b/libinterp/parse-tree/lex.ll --- a/libinterp/parse-tree/lex.ll +++ b/libinterp/parse-tree/lex.ll @@ -170,6 +170,8 @@ { \ yyless (0); \ curr_lexer->xunput (','); \ + /* Adjust for comma that was not really in the input stream. */ \ + curr_lexer->current_input_column--; \ } \ else \ { \ @@ -289,6 +291,9 @@ {NL} { curr_lexer->lexer_debug ("{NL}"); + curr_lexer->input_line_number++; + curr_lexer->current_input_column = 1; + if (curr_lexer->nesting_level.is_paren ()) curr_lexer->gripe_matlab_incompatible ("bare newline inside parentheses"); else @@ -296,7 +301,11 @@ int tok = curr_lexer->previous_token_value (); if (! (tok == ';' || tok == '[' || tok == '{')) - curr_lexer->xunput (';'); + { + curr_lexer->xunput (';'); + // Adjust for semicolon that was not really in the input stream. + curr_lexer->current_input_column--; + } } } @@ -363,6 +372,8 @@ { yyless (0); curr_lexer->xunput (','); + // Adjust for comma that was not really in the input stream. + curr_lexer->current_input_column--; } else { @@ -768,6 +779,8 @@ { yyless (0); curr_lexer->xunput (','); + // Adjust for comma that was not really in the input stream. + curr_lexer->current_input_column--; } } else @@ -834,6 +847,8 @@ { yyless (0); curr_lexer->xunput (','); + // Adjust for comma that was not really in the input stream. + curr_lexer->current_input_column--; } } else @@ -924,6 +939,8 @@ { yyless (0); curr_lexer->xunput (','); + // Adjust for comma that was not really in the input stream. + curr_lexer->current_input_column--; } else return tok; @@ -938,6 +955,8 @@ { yyless (0); curr_lexer->xunput (','); + // Adjust for comma that was not really in the input stream. + curr_lexer->current_input_column--; } else return tok; @@ -962,6 +981,8 @@ { yyless (0); curr_lexer->xunput (','); + // Adjust for comma that was not really in the input stream. + curr_lexer->current_input_column--; } else { @@ -1060,6 +1081,8 @@ { yyless (0); curr_lexer->xunput (','); + // Adjust for comma that was not really in the input stream. + curr_lexer->current_input_column--; } else { @@ -1759,9 +1782,6 @@ } } - if (c == '\n') - input_line_number++; - return c; } @@ -1777,9 +1797,6 @@ std::cerr << std::endl; } - if (c == '\n') - input_line_number--; - yyunput (c, buf, scanner); } } @@ -2181,7 +2198,11 @@ at_beginning_of_statement = true; if (! looking_at_continuation) - xunput ('\n'); + { + xunput ('\n'); + // Adjust for newline that was not really in the input stream. + input_line_number--; + } } // We have seen a backslash and need to find out if it should be