@@ -55,15 +55,14 @@ 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, std::set< unsigned long >* group_excluded_ids ) {
58+ lexer::lexer (const char * source, unsigned long source_length, struct lexer_state * lexer_state ) {
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
65- this ->constants = constants;
66- this ->group_excluded_ids = group_excluded_ids;
65+ this ->lexer_state = lexer_state;
6766
6867 read_char ();
6968 read_token ();
@@ -144,9 +143,9 @@ token* lexer::read_token() {
144143 case 303295209 :
145144 return last_tok = new token (TOKEN_END_GROUP);
146145 default : {
147- if (constants-> count (hash)) {
146+ if (lexer_state-> constants . count (hash)) {
148147 delete[] id_buf;
149- return last_tok = new value_token ((*constants-> find (hash)).second ->clone ());
148+ return last_tok = new value_token ((*lexer_state-> constants . find (hash)).second ->clone ());
150149 }
151150 return last_tok = new identifier_token (id_buf, hash);
152151 }
@@ -324,22 +323,20 @@ token* lexer::tokenize_statement(bool interactive_mode) {
324323 match_tok (read_token (), TOKEN_IDENTIFIER);
325324 identifier_token* id = (identifier_token*)last_tok;
326325 id->no_delete ();
327- group_stack.push_back ((char *)id->get_identifier ());
326+ lexer_state-> group_stack .push_back ((char *)id->get_identifier ());
328327 delete id;
329328 read_token ();
330329 return nullptr ;
331330 }
332331 case TOKEN_END_GROUP:
333- if (group_stack.empty ()) {
332+ if (lexer_state-> group_stack .empty ()) {
334333 throw ERROR_UNEXPECTED_TOKEN;
335334 }
336- delete[] group_stack.back ();
337- group_stack.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 ();
335+ delete[] lexer_state->group_stack .back ();
336+ lexer_state->group_stack .pop_back ();
337+ for (auto i = lexer_state->to_exclude .begin (); i != lexer_state->to_exclude .end (); ++i)
338+ lexer_state->namespace_register .insert (*i);
339+ lexer_state->to_exclude .clear ();
343340 read_token ();
344341 return nullptr ;
345342 case TOKEN_CONST_KW: {
@@ -350,7 +347,7 @@ token* lexer::tokenize_statement(bool interactive_mode) {
350347 delete last_tok;
351348 match_tok (read_token (), TOKEN_VALUE);
352349 value_token* value_tok = (value_token*)last_tok;
353- constants-> insert (std::pair<unsigned long , value*>(id->id_hash , value_tok->get_value ()));
350+ lexer_state-> constants . insert (std::pair<unsigned long , value*>(id->id_hash , value_tok->get_value ()));
354351 delete id;
355352 delete value_tok;
356353 read_token ();
@@ -539,13 +536,13 @@ variable_access_token* lexer::tokenize_var_access(identifier_token* identifier)
539536}
540537
541538identifier_token* lexer::apply_groups (identifier_token* id, bool creating) {
542- if (group_stack.empty ()) {
539+ if (lexer_state-> group_stack .empty ()) {
543540 if (creating) {
544- group_excluded_ids-> insert (id->id_hash );
541+ lexer_state-> namespace_register . insert (id->id_hash );
545542 }
546543 return id;
547544 }
548- else if (group_excluded_ids-> count (id->id_hash )) {
545+ else if (lexer_state-> namespace_register . count (id->id_hash )) {
549546 return id;
550547 }
551548
@@ -558,7 +555,7 @@ identifier_token* lexer::apply_groups(identifier_token* id, bool creating) {
558555 for (size_t i = 0 ; i < strlen (base_id); i++)
559556 chars.push_back (base_id[i]);
560557
561- for (auto group_kw = group_stack.rbegin (); group_kw != group_stack.rend (); ++group_kw) {
558+ for (auto group_kw = lexer_state-> group_stack .rbegin (); group_kw != lexer_state-> group_stack .rend (); ++group_kw) {
562559 chars.push_back (' @' );
563560 for (size_t i = 0 ; i < strlen (*group_kw); i++)
564561 chars.push_back ((*group_kw)[i]);
@@ -573,7 +570,7 @@ identifier_token* lexer::apply_groups(identifier_token* id, bool creating) {
573570 identifier_token* new_id = new identifier_token (id_buf, insecure_hash (id_buf));
574571
575572 if (creating)
576- to_exclude.push_back (new_id->id_hash );
573+ lexer_state-> to_exclude .push_back (new_id->id_hash );
577574
578575 return new_id;
579576}
0 commit comments