comparison libinterp/parse-tree/lex.ll @ 29915:28a39ddabbfc

allow unrecognized characters to begin command-style function call parsing * lex.ll (.): Instead of always producing a lexical error, allow an otherwise unrecognized character to trigger command-style function call parsing if the previous token may be a token and is followed by a space.
author John W. Eaton <jwe@octave.org>
date Fri, 23 Jul 2021 11:59:40 -0400
parents ef865fcd4611
children aeba7278cf80
comparison
equal deleted inserted replaced
29914:daf351544539 29915:28a39ddabbfc
1878 1878
1879 return curr_lexer->handle_token ('}'); 1879 return curr_lexer->handle_token ('}');
1880 } 1880 }
1881 1881
1882 %{ 1882 %{
1883 // Unrecognized input is a lexical error. 1883 // Unrecognized input. If the previous token may be a command and is
1884 // followed by a space, parse the remainder of this statement as a
1885 // command-style function call. Otherwise, unrecognized input is a
1886 // lexical error.
1884 %} 1887 %}
1885 1888
1886 . { 1889 . {
1887 curr_lexer->lexer_debug ("."); 1890 curr_lexer->lexer_debug (".");
1888 1891
1889 curr_lexer->xunput (yytext[0]); 1892 if (curr_lexer->previous_token_may_be_command ()
1890 1893 && curr_lexer->space_follows_previous_token ())
1891 int c = curr_lexer->text_yyinput (); 1894 {
1892 1895 yyless (0);
1893 if (c == 1) 1896 curr_lexer->push_start_state (COMMAND_START);
1894 return -1; 1897 }
1895 else if (c == EOF)
1896 return curr_lexer->handle_end_of_input ();
1897 else 1898 else
1898 { 1899 {
1899 std::ostringstream buf; 1900 curr_lexer->xunput (yytext[0]);
1900 1901
1901 buf << "invalid character '" 1902 int c = curr_lexer->text_yyinput ();
1902 << octave::undo_string_escape (static_cast<char> (c)) 1903
1903 << "' (ASCII " << c << ")"; 1904 if (c == 1)
1904 1905 return -1;
1905 // Use current file position for error token. 1906 else if (c == EOF)
1906 octave::token *tok 1907 return curr_lexer->handle_end_of_input ();
1907 = new octave::token (LEXICAL_ERROR, buf.str (), 1908 else
1908 curr_lexer->m_filepos, curr_lexer->m_filepos); 1909 {
1909 1910 std::ostringstream buf;
1910 curr_lexer->push_token (tok); 1911
1911 1912 buf << "invalid character '"
1912 curr_lexer->m_filepos.increment_column (); 1913 << octave::undo_string_escape (static_cast<char> (c))
1913 1914 << "' (ASCII " << c << ")";
1914 return curr_lexer->count_token_internal (LEXICAL_ERROR); 1915
1915 } 1916 // Use current file position for error token.
1916 } 1917 octave::token *tok
1918 = new octave::token (LEXICAL_ERROR, buf.str (),
1919 curr_lexer->m_filepos, curr_lexer->m_filepos);
1920
1921 curr_lexer->push_token (tok);
1922
1923 curr_lexer->m_filepos.increment_column ();
1924
1925 return curr_lexer->count_token_internal (LEXICAL_ERROR);
1926 }
1927 }
1928 }
1917 1929
1918 %{ 1930 %{
1919 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC) 1931 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
1920 // Disable these warnings for flex code. 1932 // Disable these warnings for flex code.
1921 # pragma GCC diagnostic ignored "-Wold-style-cast" 1933 # pragma GCC diagnostic ignored "-Wold-style-cast"