diff options
author | HampusM <hampus@hampusmat.com> | 2023-03-05 14:04:22 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-03-05 14:04:22 +0100 |
commit | 57ab49b24ed34fcddadb1a293511ee74a066e026 (patch) | |
tree | a6f847be39fd3f110e728f2d3da8da4fb11fd50c /src/repeat.rs | |
parent | bcb50c3d6de52207541969bfeba0701073c56232 (diff) |
refactor: simplify replacing identifiers
Diffstat (limited to 'src/repeat.rs')
-rw-r--r-- | src/repeat.rs | 39 |
1 files changed, 10 insertions, 29 deletions
diff --git a/src/repeat.rs b/src/repeat.rs index 2f55ee8..5d9ece7 100644 --- a/src/repeat.rs +++ b/src/repeat.rs @@ -19,18 +19,12 @@ pub fn for_each_opengl_command_impl( opengl_registry: &Registry, ) -> TokenStream { - let gl_func_ident_index_paths = input_stream - .find_all_ident(&Ident::new(OPENGL_CMD_IDENT_REPLACE, Span::call_site())); - - let gl_func_ret_type_index_paths = input_stream - .find_all_ident(&Ident::new(OPENGL_CMD_RET_TYPE_REPLACE, Span::call_site())); - let out: TokenStream = opengl_registry .commands() .iter() .map(|gl_command| { - let stream = input_stream.replace_tokens( - &gl_func_ident_index_paths, + let stream = input_stream.replace_ident( + &Ident::new(OPENGL_CMD_IDENT_REPLACE, Span::call_site()), &TokenTree::Ident(Ident::new( gl_command.prototype().name(), Span::call_site(), @@ -39,19 +33,16 @@ pub fn for_each_opengl_command_impl( let return_type = gl_command.prototype().return_type(); - let stream = stream.replace_tokens( - &gl_func_ret_type_index_paths, + let stream = stream.replace_ident( + &Ident::new(OPENGL_CMD_RET_TYPE_REPLACE, Span::call_site()), &TokenTree::Group(Group::new( Delimiter::None, TokenStream::from_str(&fix_type(return_type)).unwrap(), )), ); - let gl_func_args_paths = stream - .find_all_ident(&Ident::new(OPENGL_CMD_ARGS_REPLACE, Span::call_site())); - - let stream = stream.replace_tokens( - &gl_func_args_paths, + let stream = stream.replace_ident( + &Ident::new(OPENGL_CMD_ARGS_REPLACE, Span::call_site()), &TokenTree::Group(Group::new( Delimiter::None, TokenStream::from_str( @@ -71,13 +62,8 @@ pub fn for_each_opengl_command_impl( )), ); - let gl_func_arg_names_paths = stream.find_all_ident(&Ident::new( - OPENGL_CMD_ARG_NAMES_REPLACE, - Span::call_site(), - )); - - let stream = stream.replace_tokens( - &gl_func_arg_names_paths, + let stream = stream.replace_ident( + &Ident::new(OPENGL_CMD_ARG_NAMES_REPLACE, Span::call_site()), &TokenTree::Group(Group::new( Delimiter::None, TokenStream::from_str( @@ -92,13 +78,8 @@ pub fn for_each_opengl_command_impl( )), ); - let gl_func_arg_types_paths = stream.find_all_ident(&Ident::new( - OPENGL_CMD_ARG_TYPES_REPLACE, - Span::call_site(), - )); - - stream.replace_tokens( - &gl_func_arg_types_paths, + stream.replace_ident( + &Ident::new(OPENGL_CMD_ARG_TYPES_REPLACE, Span::call_site()), &TokenTree::Group(Group::new( Delimiter::None, TokenStream::from_str( |