Mercurial > octave-nkf
comparison libinterp/parse-tree/lex.ll @ 18394:fc0ce9eb9d82
don't allow get and set followed by "(" to be recognized as keywords.
* lex.ll (HANDLE_IDENTIFIER): New macro.
(set|get)/{S}*\(): New special-case pattern.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 23 Jan 2014 04:07:32 -0500 |
parents | 02b349ccf0ec |
children | e76d50d65278 |
comparison
equal
deleted
inserted
replaced
18393:6a2cc29f55fc | 18394:fc0ce9eb9d82 |
---|---|
252 \ | 252 \ |
253 return retval; \ | 253 return retval; \ |
254 } \ | 254 } \ |
255 while (0) | 255 while (0) |
256 | 256 |
257 #define HANDLE_IDENTIFIER(pattern, get_set) \ | |
258 do \ | |
259 { \ | |
260 curr_lexer->lexer_debug (pattern); \ | |
261 \ | |
262 int tok = curr_lexer->previous_token_value (); \ | |
263 \ | |
264 if (curr_lexer->whitespace_is_significant () \ | |
265 && curr_lexer->space_follows_previous_token () \ | |
266 && ! (tok == '[' || tok == '{' \ | |
267 || curr_lexer->previous_token_is_binop ())) \ | |
268 { \ | |
269 yyless (0); \ | |
270 unput (','); \ | |
271 } \ | |
272 else \ | |
273 { \ | |
274 if (! curr_lexer->looking_at_decl_list \ | |
275 && curr_lexer->previous_token_may_be_command ()) \ | |
276 { \ | |
277 yyless (0); \ | |
278 curr_lexer->push_start_state (COMMAND_START); \ | |
279 } \ | |
280 else \ | |
281 { \ | |
282 if (get_set) \ | |
283 curr_lexer->maybe_classdef_get_set_method = false; \ | |
284 \ | |
285 int id_tok = curr_lexer->handle_identifier (); \ | |
286 \ | |
287 if (id_tok >= 0) \ | |
288 return curr_lexer->count_token_internal (id_tok); \ | |
289 } \ | |
290 } \ | |
291 } \ | |
292 while (0) | |
293 | |
257 static bool Vdisplay_tokens = false; | 294 static bool Vdisplay_tokens = false; |
258 | 295 |
259 static unsigned int Vtoken_count = 0; | 296 static unsigned int Vtoken_count = 0; |
260 | 297 |
261 // Internal variable for lexer debugging state. | 298 // Internal variable for lexer debugging state. |
1114 return curr_lexer->handle_end_of_input (); | 1151 return curr_lexer->handle_end_of_input (); |
1115 } | 1152 } |
1116 | 1153 |
1117 %{ | 1154 %{ |
1118 // Identifiers. | 1155 // Identifiers. |
1119 %} | 1156 |
1157 // Don't allow get and set to be recognized as keywords if they are | |
1158 // followed by "(". | |
1159 %} | |
1160 | |
1161 (set|get)/{S}*\( { | |
1162 HANDLE_IDENTIFIER ("(set|get)/{S}*\\(", true); | |
1163 } | |
1120 | 1164 |
1121 {IDENT} { | 1165 {IDENT} { |
1122 curr_lexer->lexer_debug ("{IDENT}"); | 1166 HANDLE_IDENTIFIER ("{IDENT}", false); |
1123 | |
1124 int tok = curr_lexer->previous_token_value (); | |
1125 | |
1126 if (curr_lexer->whitespace_is_significant () | |
1127 && curr_lexer->space_follows_previous_token () | |
1128 && ! (tok == '[' || tok == '{' | |
1129 || curr_lexer->previous_token_is_binop ())) | |
1130 { | |
1131 yyless (0); | |
1132 unput (','); | |
1133 } | |
1134 else | |
1135 { | |
1136 if (! curr_lexer->looking_at_decl_list | |
1137 && curr_lexer->previous_token_may_be_command ()) | |
1138 { | |
1139 yyless (0); | |
1140 curr_lexer->push_start_state (COMMAND_START); | |
1141 } | |
1142 else | |
1143 { | |
1144 int id_tok = curr_lexer->handle_identifier (); | |
1145 | |
1146 if (id_tok >= 0) | |
1147 return curr_lexer->count_token_internal (id_tok); | |
1148 } | |
1149 } | |
1150 } | 1167 } |
1151 | 1168 |
1152 %{ | 1169 %{ |
1153 // Superclass method identifiers. | 1170 // Superclass method identifiers. |
1154 %} | 1171 %} |