All of lore.kernel.org
 help / color / mirror / Atom feed
* [cocci] Does SmPL support regex groups?
@ 2022-03-08 23:15 Eric Wheeler
  2022-03-09  5:55 ` Julia Lawall
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Eric Wheeler @ 2022-03-08 23:15 UTC (permalink / raw)
  To: cocci

Hi all,

I would like to replace this:

	void on_struct_save_as_gnuplot_activate(
	    GtkMenuItem     *menuitem,
	    gpointer         user_data)
	{
	  file_chooser = Open_Filechooser( GTK_FILE_CHOOSER_ACTION_SAVE,
	      "*.gplot", NULL, "untitled.gplot", rc_config.working_dir );
	}

And extract the extension ".gplot" as an identifier and pass it to the 
function get_nec_filename_stem, like so:

	void on_struct_save_as_gnuplot_activate(
	    GtkMenuItem     *menuitem,
	    gpointer         user_data)
	{
	  file_chooser = Open_Filechooser( GTK_FILE_CHOOSER_ACTION_SAVE,
	      "*.gplot", NULL, get_nec_filename_stem(newfn, ".gplot", PATH_MAX), rc_config.working_dir );
	}

The SmPL patch below works for what I want statically, but notice the 
commented `expression E`:

Is there a way to regex-group `expression E =~` with a parenthesis and then specify
something like E[0] to pick up the grouped regex match?

	@ replace_untitled @
	identifier F;
	parameter list PL;
	expression list EL1, EL2;
	//expression E =~ "\"untitled\.(.*)\"";
	@@

	F(PL)
	{
	+   char newfn[PATH_MAX];
	    ...
	    file_chooser = Open_Filechooser(EL1,
	-       "untitled.gplot",
	+       get_nec_filename_stem(newfn, ".gplot", PATH_MAX), 
		EL2);
	    ...
	}


This doesn't work, but it explains what I'm trying to do:

	@ replace_untitled @
	identifier F;
	parameter list PL;
	expression list EL1, EL2;
	expression E =~ "untitled.(.*)";
	@@

	F(PL)
	{   
	+   char newfn[PATH_MAX];
	    ...
	    file_chooser = Open_Filechooser(EL1,
	-       E,
	+       get_nec_filename_stem(newfn, E[0], PATH_MAX),
		EL2);
	    ...
	}

It replaces as follows and does match "untitled.(.*)", but of course [0] is incorrect SmPL grammar:

	@@ -250,10 +253,13 @@ on_struct_save_as_gnuplot_activate(
	     GtkMenuItem     *menuitem,
	     gpointer         user_data)
	 {
	+  char newfn[PATH_MAX];
	   /* Open file chooser to save structure image */
	   SetFlag( STRUCT_GNUPLOT_SAVE );
	   file_chooser = Open_Filechooser( GTK_FILE_CHOOSER_ACTION_SAVE,
	-      "*.gplot", NULL, "untitled.gplot", rc_config.working_dir );
	+      "*.gplot", NULL,
	+      get_nec_filename_stem(newfn, "untitled.gplot"[0], PATH_MAX),
	+      rc_config.working_dir );
	 }

I tried something like this:
	expression F =~ "\..*";
	expression E =~ "untitled" ##F;
but that is invalid too.

Ideas?


--
Eric Wheeler

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2022-03-23  6:01 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-08 23:15 [cocci] Does SmPL support regex groups? Eric Wheeler
2022-03-09  5:55 ` Julia Lawall
2022-03-09 20:56   ` Eric Wheeler
2022-03-09 21:20     ` Julia Lawall
2022-03-10  2:25       ` Eric Wheeler
2022-03-10  6:12         ` Julia Lawall
2022-03-10  9:16         ` Markus Elfring
2022-03-10 22:03           ` Eric Wheeler
2022-03-11 11:12             ` Nicolas Palix
2022-03-11 12:39               ` Julia Lawall
2022-03-12  7:00               ` Markus Elfring
2022-03-10  8:39       ` Markus Elfring
2022-03-09 18:38 ` Markus Elfring
2022-03-09 20:51   ` Eric Wheeler
2022-03-09 21:16     ` Markus Elfring
2022-03-22 14:30 ` Nicolas Palix
2022-03-22 19:26   ` Markus Elfring
2022-03-23  6:00   ` Eric Wheeler

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.