Mercurial > octave-dspies
comparison src/lex.l @ 3388:42cb61dd0248
[project @ 1999-12-16 04:51:43 by jwe]
author | jwe |
---|---|
date | Thu, 16 Dec 1999 04:51:46 +0000 |
parents | 8623649c967c |
children | 18366d37e7dd |
comparison
equal
deleted
inserted
replaced
3387:eb4223985ca8 | 3388:42cb61dd0248 |
---|---|
160 // [eye (2)] | 160 // [eye (2)] |
161 // | 161 // |
162 // will result in a call to `eye' with the argument `2'. | 162 // will result in a call to `eye' with the argument `2'. |
163 | 163 |
164 static int Vwhitespace_in_literal_matrix; | 164 static int Vwhitespace_in_literal_matrix; |
165 | |
166 static bool Vwarn_separator_insert = false; | |
165 | 167 |
166 // Forward declarations for functions defined at the bottom of this | 168 // Forward declarations for functions defined at the bottom of this |
167 // file. | 169 // file. |
168 | 170 |
169 static void fixup_column_count (char *s); | 171 static void fixup_column_count (char *s); |
184 static int handle_identifier (const string& tok, int spc_gobbled); | 186 static int handle_identifier (const string& tok, int spc_gobbled); |
185 static bool have_continuation (bool trailing_comments_ok = true); | 187 static bool have_continuation (bool trailing_comments_ok = true); |
186 static bool have_ellipsis_continuation (bool trailing_comments_ok = true); | 188 static bool have_ellipsis_continuation (bool trailing_comments_ok = true); |
187 static yum_yum eat_whitespace (void); | 189 static yum_yum eat_whitespace (void); |
188 static yum_yum eat_continuation (void); | 190 static yum_yum eat_continuation (void); |
191 static void maybe_warn_separator_insert (char sep); | |
189 | 192 |
190 %} | 193 %} |
191 | 194 |
192 D [0-9] | 195 D [0-9] |
193 S [ \t] | 196 S [ \t] |
275 // commas. | 278 // commas. |
276 %} | 279 %} |
277 | 280 |
278 <MATRIX>{S}*\,{S}* { | 281 <MATRIX>{S}*\,{S}* { |
279 current_input_column += yyleng; | 282 current_input_column += yyleng; |
283 | |
280 int tmp = eat_continuation (); | 284 int tmp = eat_continuation (); |
285 | |
281 lexer_flags.quote_is_transpose = false; | 286 lexer_flags.quote_is_transpose = false; |
282 lexer_flags.cant_be_identifier = false; | 287 lexer_flags.cant_be_identifier = false; |
283 lexer_flags.convert_spaces_to_comma = true; | 288 lexer_flags.convert_spaces_to_comma = true; |
284 if (Vwhitespace_in_literal_matrix != 2 | 289 |
285 && (tmp & ATE_NEWLINE) == ATE_NEWLINE) | 290 if ((tmp & ATE_NEWLINE) == ATE_NEWLINE) |
286 unput (';'); | 291 { |
292 maybe_warn_separator_insert (';'); | |
293 | |
294 if (Vwhitespace_in_literal_matrix != 2) | |
295 unput (';'); | |
296 } | |
297 | |
287 return (','); | 298 return (','); |
288 } | 299 } |
289 | 300 |
290 %{ | 301 %{ |
291 // In some cases, spaces in matrix constants can turn into commas. | 302 // In some cases, spaces in matrix constants can turn into commas. |
294 // here we can end up inserting too many commas. | 305 // here we can end up inserting too many commas. |
295 %} | 306 %} |
296 | 307 |
297 <MATRIX>{S}+ { | 308 <MATRIX>{S}+ { |
298 current_input_column += yyleng; | 309 current_input_column += yyleng; |
299 if (Vwhitespace_in_literal_matrix != 2) | 310 |
311 int tmp = eat_continuation (); | |
312 int bin_op = next_token_is_bin_op (true); | |
313 int postfix_un_op = next_token_is_postfix_unary_op (true); | |
314 | |
315 if (! (postfix_un_op || bin_op) | |
316 && nesting_level.is_bracket () | |
317 && lexer_flags.convert_spaces_to_comma) | |
300 { | 318 { |
301 int tmp = eat_continuation (); | 319 if ((tmp & ATE_NEWLINE) == ATE_NEWLINE) |
302 int bin_op = next_token_is_bin_op (true); | 320 { |
303 int postfix_un_op = next_token_is_postfix_unary_op (true); | 321 maybe_warn_separator_insert (';'); |
304 | 322 |
305 if (! (postfix_un_op || bin_op) | 323 if (Vwhitespace_in_literal_matrix != 2) |
306 && nesting_level.is_bracket () | 324 unput (';'); |
307 && lexer_flags.convert_spaces_to_comma) | 325 } |
326 | |
327 if (Vwhitespace_in_literal_matrix != 2) | |
308 { | 328 { |
309 lexer_flags.quote_is_transpose = false; | 329 lexer_flags.quote_is_transpose = false; |
310 lexer_flags.cant_be_identifier = false; | 330 lexer_flags.cant_be_identifier = false; |
311 lexer_flags.convert_spaces_to_comma = true; | 331 lexer_flags.convert_spaces_to_comma = true; |
312 if ((tmp & ATE_NEWLINE) == ATE_NEWLINE) | 332 |
313 unput (';'); | 333 maybe_warn_separator_insert (','); |
334 | |
314 return (','); | 335 return (','); |
315 } | 336 } |
316 } | 337 } |
317 } | 338 } |
318 | 339 |
339 | 360 |
340 <MATRIX>{S}*{COMMENT}{SNLCMT}* | | 361 <MATRIX>{S}*{COMMENT}{SNLCMT}* | |
341 <MATRIX>{S}*{NL}{SNLCMT}* { | 362 <MATRIX>{S}*{NL}{SNLCMT}* { |
342 fixup_column_count (yytext); | 363 fixup_column_count (yytext); |
343 eat_whitespace (); | 364 eat_whitespace (); |
365 | |
344 if (Vwhitespace_in_literal_matrix != 2) | 366 if (Vwhitespace_in_literal_matrix != 2) |
345 { | 367 { |
346 lexer_flags.quote_is_transpose = false; | 368 lexer_flags.quote_is_transpose = false; |
347 lexer_flags.cant_be_identifier = false; | 369 lexer_flags.cant_be_identifier = false; |
348 lexer_flags.convert_spaces_to_comma = true; | 370 lexer_flags.convert_spaces_to_comma = true; |
349 | 371 |
350 if (nesting_level.none ()) | 372 if (nesting_level.none ()) |
351 return LEXICAL_ERROR; | 373 return LEXICAL_ERROR; |
352 | 374 } |
353 if (nesting_level.is_bracket ()) | 375 |
376 if (nesting_level.is_bracket ()) | |
377 { | |
378 maybe_warn_separator_insert (';'); | |
379 | |
380 if (Vwhitespace_in_literal_matrix != 2) | |
354 return ';'; | 381 return ';'; |
355 } | 382 } |
356 } | 383 } |
357 | 384 |
358 %{ | 385 %{ |
1848 else | 1875 else |
1849 { | 1876 { |
1850 int c1 = yyinput (); | 1877 int c1 = yyinput (); |
1851 unput (c1); | 1878 unput (c1); |
1852 | 1879 |
1853 if (lexer_flags.bracketflag && Vwhitespace_in_literal_matrix != 2) | 1880 if (lexer_flags.bracketflag) |
1854 { | 1881 { |
1855 int bin_op = next_token_is_bin_op (spc_gobbled); | 1882 int bin_op = next_token_is_bin_op (spc_gobbled); |
1856 | 1883 |
1857 int postfix_un_op = next_token_is_postfix_unary_op (spc_gobbled); | 1884 int postfix_un_op = next_token_is_postfix_unary_op (spc_gobbled); |
1858 | 1885 |
1860 | 1887 |
1861 if (! (postfix_un_op || bin_op || sep_op) | 1888 if (! (postfix_un_op || bin_op || sep_op) |
1862 && nesting_level.is_bracket () | 1889 && nesting_level.is_bracket () |
1863 && lexer_flags.convert_spaces_to_comma) | 1890 && lexer_flags.convert_spaces_to_comma) |
1864 { | 1891 { |
1865 unput (','); | 1892 maybe_warn_separator_insert (','); |
1866 return ']'; | 1893 |
1894 if (Vwhitespace_in_literal_matrix != 2) | |
1895 { | |
1896 unput (','); | |
1897 return ']'; | |
1898 } | |
1867 } | 1899 } |
1868 } | 1900 } |
1869 } | 1901 } |
1870 | 1902 |
1871 lexer_flags.quote_is_transpose = true; | 1903 lexer_flags.quote_is_transpose = true; |
1876 } | 1908 } |
1877 | 1909 |
1878 static void | 1910 static void |
1879 maybe_unput_comma (int spc_gobbled) | 1911 maybe_unput_comma (int spc_gobbled) |
1880 { | 1912 { |
1881 if (Vwhitespace_in_literal_matrix != 2 && nesting_level.is_bracket ()) | 1913 if (nesting_level.is_bracket ()) |
1882 { | 1914 { |
1883 int bin_op = next_token_is_bin_op (spc_gobbled); | 1915 int bin_op = next_token_is_bin_op (spc_gobbled); |
1884 | 1916 |
1885 int postfix_un_op = next_token_is_postfix_unary_op (spc_gobbled); | 1917 int postfix_un_op = next_token_is_postfix_unary_op (spc_gobbled); |
1886 | 1918 |
1893 int sep_op = next_token_is_sep_op (); | 1925 int sep_op = next_token_is_sep_op (); |
1894 | 1926 |
1895 int dot_op = (c1 == '.' | 1927 int dot_op = (c1 == '.' |
1896 && (isalpha (c2) || isspace (c2) || c2 == '_')); | 1928 && (isalpha (c2) || isspace (c2) || c2 == '_')); |
1897 | 1929 |
1898 int index_op = (c1 == '(' | 1930 if (postfix_un_op || bin_op || sep_op || dot_op) |
1899 && (Vwhitespace_in_literal_matrix == 0 | 1931 return; |
1900 || ! spc_gobbled)); | 1932 |
1901 | 1933 int index_op = (c1 == '('); |
1902 if (! (postfix_un_op || bin_op || sep_op || dot_op || index_op)) | 1934 |
1903 unput (','); | 1935 if (index_op) |
1936 { | |
1937 // If there is no space before the '(', we don't insert a comma. | |
1938 if (! spc_gobbled) | |
1939 return; | |
1940 | |
1941 maybe_warn_separator_insert (','); | |
1942 | |
1943 // If there is a space, we only insert a comma if we are | |
1944 // trying to be Matlab-like. | |
1945 if (Vwhitespace_in_literal_matrix == 1) | |
1946 unput (','); | |
1947 } | |
1948 else | |
1949 { | |
1950 maybe_warn_separator_insert (','); | |
1951 | |
1952 if (Vwhitespace_in_literal_matrix != 2) | |
1953 unput (','); | |
1954 } | |
1904 } | 1955 } |
1905 } | 1956 } |
1906 | 1957 |
1907 // Figure out exactly what kind of token to return when we have seen | 1958 // Figure out exactly what kind of token to return when we have seen |
1908 // an identifier. Handles keywords. | 1959 // an identifier. Handles keywords. |
2148 | 2199 |
2149 // Quote marks strings intially. | 2200 // Quote marks strings intially. |
2150 quote_is_transpose = false; | 2201 quote_is_transpose = false; |
2151 } | 2202 } |
2152 | 2203 |
2204 static void | |
2205 maybe_warn_separator_insert (char sep) | |
2206 { | |
2207 string nm = curr_fcn_file_full_name; | |
2208 | |
2209 if (Vwarn_separator_insert) | |
2210 { | |
2211 if (nm.empty ()) | |
2212 warning ("potential auto-insertion of `%c' near line %d", | |
2213 sep, input_line_number); | |
2214 else | |
2215 warning ("potential auto-insertion of `%c' near line %d of file %s", | |
2216 sep, input_line_number, nm.c_str ()); | |
2217 } | |
2218 } | |
2219 | |
2220 static int | |
2221 warn_separator_insert (void) | |
2222 { | |
2223 Vwarn_separator_insert = check_preference ("warn_separator_insert"); | |
2224 | |
2225 return 0; | |
2226 } | |
2227 | |
2153 static int | 2228 static int |
2154 whitespace_in_literal_matrix (void) | 2229 whitespace_in_literal_matrix (void) |
2155 { | 2230 { |
2156 int pref = 0; | 2231 int pref = 0; |
2157 | 2232 |
2171 } | 2246 } |
2172 | 2247 |
2173 void | 2248 void |
2174 symbols_of_lex (void) | 2249 symbols_of_lex (void) |
2175 { | 2250 { |
2251 DEFVAR (warn_separator_insert, 0.0, warn_separator_insert, | |
2252 "print warning if commas or semicolons that might be inserted\n\ | |
2253 automatically in literal matrices"); | |
2254 | |
2176 DEFVAR (whitespace_in_literal_matrix, "", whitespace_in_literal_matrix, | 2255 DEFVAR (whitespace_in_literal_matrix, "", whitespace_in_literal_matrix, |
2177 "control auto-insertion of commas and semicolons in literal matrices"); | 2256 "control auto-insertion of commas and semicolons in literal matrices"); |
2178 } | 2257 } |
2179 | 2258 |
2180 /* | 2259 /* |