cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
From: Julia Lawall <julia.lawall@lip6.fr>
To: Wen Yang <yellowriver2010@hotmail.com>
Cc: cocci@systeme.lip6.fr
Subject: Re: [Cocci] [PATCH] Python scripts also support comments metavar
Date: Sun, 2 Jun 2019 10:38:43 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.21.1906021038020.10641@hadrien> (raw)
In-Reply-To: <MAXPR01MB39833362F9B533717A9DE485B21B0@MAXPR01MB3983.INDPRD01.PROD.OUTLOOK.COM>

Applied, thanks.

julia

On Sun, 2 Jun 2019, Wen Yang wrote:

> Extending the comment support to python
>
> Signed-off-by: Wen Yang <yellowriver2010@hotmail.com>
> ---
>  demos/comments.cocci     | 28 +++++++++++++++++++++++++++-
>  python/coccilib/elems.py |  6 ++++++
>  python/yes_pycocci.ml    | 22 +++++++++++++++++++++-
>  3 files changed, 54 insertions(+), 2 deletions(-)
>
> diff --git a/demos/comments.cocci b/demos/comments.cocci
> index cdca955b..abfcc6b8 100644
> --- a/demos/comments.cocci
> +++ b/demos/comments.cocci
> @@ -33,4 +33,30 @@ Printf.printf "c3a: %s\n\n" (String.concat " " c3a);
>  Printf.printf "c4b: %s\n" (String.concat " " c4b);
>  Printf.printf "c4m: %s\n" (String.concat " " c4m);
>  Printf.printf "c4a: %s\n\n" (String.concat " " c4a);
> -Printf.printf "-------------------\n"
> \ No newline at end of file
> +Printf.printf "-------------------\n"
> +
> +@script:python@
> +c1 << r.c1;
> +c2 << r.c2;
> +c3 << r.c3;
> +c4 << r.c4;
> +@@
> +
> +print("python test begin ...")
> +print("c1b: ", c1[0].before)
> +print("c1m: ", c1[0].middle)
> +print("c1a: ", c1[0].after)
> +
> +print("c2b: ", c2[0].before)
> +print("c2m: ", c2[0].middle)
> +print("c2a: ", c2[0].after)
> +
> +print("c3b: ", c3[0].before)
> +print("c3m: ", c3[0].middle)
> +print("c3a: ", c3[0].after)
> +
> +print("c4b: ", c4[0].before)
> +print("c4m: ", c4[0].middle)
> +print("c4a: ", c4[0].after)
> +
> +print("python test end \n")
> diff --git a/python/coccilib/elems.py b/python/coccilib/elems.py
> index ddb508b0..4d11a79a 100644
> --- a/python/coccilib/elems.py
> +++ b/python/coccilib/elems.py
> @@ -11,6 +11,12 @@ class Location:
>                  self.line_end = line_end
>                  self.column_end = column_end
>
> +class Comment:
> + def __init__(self, comment_before, comment_middle, comment_after):
> +                self.before = comment_before
> +                self.middle = comment_middle
> +                self.after = comment_after
> +
>  class ElemBase:
>          def __init__(self):
>                  pass
> diff --git a/python/yes_pycocci.ml b/python/yes_pycocci.ml
> index 0e0e654c..038ad2a9 100644
> --- a/python/yes_pycocci.ml
> +++ b/python/yes_pycocci.ml
> @@ -366,7 +366,27 @@ let construct_variables mv e =
>         let pylocs = Py.Tuple.of_list locs in
>         let _ = build_variable py pylocs in
>         ()
> -    | Some (_, Ast_c.MetaComValList l) -> failwith "comments not yet supported"
> +    | Some (_, Ast_c.MetaComValList l) ->
> +       let coms =
> +	 List.map
> +	   (function (bef, mid, aft) ->
> +            let com_strings l =
> +              List.rev
> +                (List.fold_left
> +                   (fun prev cur ->
> +                     match cur with
> +                       (Token_c.TComment,_) -> (Token_c.str_of_token cur) :: prev
> +                     | (Token_c.TCommentCpp _,_) -> (Token_c.str_of_token cur) :: prev
> +                     | _ -> prev)
> +                   [] l) in
> +	     pycocci_instantiate_class "coccilib.elems.Comment"
> +	       (Py.Tuple.of_list_map Py.String.of_string
> +		  [String.concat "\n" (com_strings bef);
> +		   String.concat "\n" (com_strings mid);
> +		   String.concat "\n" (com_strings aft)])) l in
> +       let pycoms = Py.Tuple.of_list coms in
> +       let _ = build_variable py pycoms in
> +       ()
>      | Some (_,binding) ->
>         let _ =
>  	 build_variable py
> --
> 2.21.0
>
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

           reply	other threads:[~2019-06-02  8:39 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <MAXPR01MB39833362F9B533717A9DE485B21B0@MAXPR01MB3983.INDPRD01.PROD.OUTLOOK.COM>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.21.1906021038020.10641@hadrien \
    --to=julia.lawall@lip6.fr \
    --cc=cocci@systeme.lip6.fr \
    --cc=yellowriver2010@hotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).