@@ -55,14 +55,15 @@ inline function_call_token* print_encapsulate(token* token) {
5555 return new function_call_token (new identifier_token (" print" ), args);
5656}
5757
58- lexer::lexer (const char * source, unsigned long source_length, std::map<unsigned long , value*>* constants) {
58+ lexer::lexer (const char * source, unsigned long source_length, std::map<unsigned long , value*>* constants, std::set< unsigned long >* group_excluded_ids ) {
5959 this ->source = source;
6060 this ->source_length = source_length;
6161 this ->position = 0 ;
6262 this ->last_char = 0 ;
6363 this ->last_tok = nullptr ;
6464
6565 this ->constants = constants;
66+ this ->group_excluded_ids = group_excluded_ids;
6667
6768 read_char ();
6869 read_token ();
@@ -324,7 +325,6 @@ token* lexer::tokenize_statement(bool interactive_mode) {
324325 identifier_token* id = (identifier_token*)last_tok;
325326 id->no_delete ();
326327 group_stack.push_back ((char *)id->get_identifier ());
327- group_defined_ids.push_back (std::set<unsigned long >());
328328 delete id;
329329 read_token ();
330330 return nullptr ;
@@ -335,7 +335,11 @@ token* lexer::tokenize_statement(bool interactive_mode) {
335335 }
336336 delete[] group_stack.back ();
337337 group_stack.pop_back ();
338- group_defined_ids.pop_back ();
338+ for (auto i = to_exclude.begin (); i != to_exclude.end (); ++i)
339+ {
340+ group_excluded_ids->insert (*i);
341+ }
342+ to_exclude.clear ();
339343 read_token ();
340344 return nullptr ;
341345 case TOKEN_CONST_KW: {
@@ -535,11 +539,18 @@ variable_access_token* lexer::tokenize_var_access(identifier_token* identifier)
535539}
536540
537541identifier_token* lexer::apply_groups (identifier_token* id, bool creating) {
538- if (group_stack.empty () || (!creating && !group_defined_ids.back ().count (id->id_hash )))
542+ if (group_stack.empty ()) {
543+ if (creating) {
544+ group_excluded_ids->insert (id->id_hash );
545+ }
546+ return id;
547+ }
548+ else if (group_excluded_ids->count (id->id_hash )) {
539549 return id;
550+ }
551+
540552 char * base_id = (char *)id->get_identifier ();
541553 id->no_delete ();
542- group_defined_ids.back ().insert (id->id_hash );
543554 delete id;
544555
545556 std::list<char > chars;
@@ -559,7 +570,12 @@ identifier_token* lexer::apply_groups(identifier_token* id, bool creating) {
559570 id_buf[i++] = (*it);
560571 id_buf[i] = 0 ;
561572
562- return new identifier_token (id_buf, insecure_hash (id_buf));
573+ identifier_token* new_id = new identifier_token (id_buf, insecure_hash (id_buf));
574+
575+ if (creating)
576+ to_exclude.push_back (new_id->id_hash );
577+
578+ return new_id;
563579}
564580
565581token* lexer::tokenize_value () {
0 commit comments