Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Rijnard van Tonder
    @rvantonder
    Ah OK, cool. So yes I think it is to do with that first :[?string] which is similar to starting a match with :[_] and this is usually not something the pattern actually wants to do. For example, it means here that "potentially match anything or nothing before a :[[var]]", which means a lot of different cases might end up being checked. I'm pretty sure there is a better way to do this--do you have a concrete code to show what type of thing might be optional in the :[?string] :[[var]] part?
    Rijnard van Tonder
    @rvantonder

    For example, I suspect starting with something like this could help:

    String :[[v]] = "SELECT :[_]"

    and then expand it to cover cases where there is append with +, or something more specific inside the SELECT string

    Juan Luis Guerrero Minero
    @juanluelguerre
    Ok, understood, I'm going to review it according your explanations. I'll let you know if I can get it ;) Thanks a lot !
    Sergey Kostyaev
    @s-kostyaev
    Hi all.
    I have a question: how to mathch * as part of hole?
    it doesn't work for me
    I have created simple wrapper for Emacs - https://github.com/s-kostyaev/comby.el
    And now trying to implement simple refactoring for golang like this:
          (defun my-go-extract-function (beg end)
            (interactive "r")
            (let ((default-directory (project-root (project-current)))
                  (sel (buffer-substring-no-properties beg end))
                  (name (read-string "function name: "))
                  (comby-show-changes nil))
              (comby-run (concat "{:[before]" sel ":[after]}")
                         (concat "{:[before]\n" name "()\n:[after]}\n\n"
                                 "func " name "() {\n" sel "\n}")
                         ".go"
                         :changed-file-func #'my-comby-go-after-file-change)))
    
          (defun my-go-extract-method (beg end)
            (interactive "r")
            (let ((default-directory (project-root (project-current)))
                  (sel (buffer-substring-no-properties beg end))
                  (name (read-string "method name: "))
                  (comby-show-changes nil))
              (comby-run (concat "func (:[name] :[type]) :[definition] {:[before]" sel ":[after]}")
                         (concat "func (:[name] :[type]) :[definition] {:[before]\n:[name]." name "()\n:[after]}\n\n"
                                 "func (:[name] :[type]) " name "() {\n" sel "\n}")
                         ".go"
                         :changed-file-func #'my-comby-go-after-file-change)))
    Sergey Kostyaev
    @s-kostyaev
    first one works good enough. But second one creates new method with value receiver instead of pointer receiver (a MyType) instead of (a *MyType)
    Matching * works outside of the [hole], but I would like to use it for both pointer receiver and value receiver)
    Sergey Kostyaev
    @s-kostyaev
    And thank you for this cool project!
    Rijnard van Tonder
    @rvantonder

    Hey @s-kostyaev that looks really cool! Could you give an example of the match template and code that don't work for you when trying to match *? It works for me and in the playground (example: https://bit.ly/312dXEJ), and I'm wondering if maybe the way that the pattern is constructed in this part is maybe not doing what's expected:

    func (:[name] :[type]) :[definition] {:[before]" sel ":[after]}

    Like, maybe this concatenation of sel and before/after is causing some problem.

    Just another debugging though, the other thing to check is to make sure to invoke comby to parse the file or selection as Go
    Rijnard van Tonder
    @rvantonder
    For making sure the file is parsed with the right parser, it is safe to assume you can use the file extension and pass it like -matcher .go or -matcher .py. If comby doesn't recognize the extension, you can use -matcher .generic.
    sogaiu
    @sogaiu
    @s-kostyaev comby.el looks neat -- thanks for making and sharing it!
    Sergey Kostyaev
    @s-kostyaev
    I have found the root of my problem. It match first definition of method. Can I make :[prevCode] greedy?
    Rijnard van Tonder
    @rvantonder
    I'm not sure I follow, do you need :[prevCode] for something? You can ignore the things to not match by using just the match template starting with func. If I'm missing something can you explain what you're trying to get in the result?
    Example, without :[prevCode] bit.ly/3hL9V9X
    OK I think I follow what the problem is, if you want that match template to match each function
    Sergey Kostyaev
    @s-kostyaev
    I want to match last one before v.Y = v.Y * f - the selection in that case
    Rijnard van Tonder
    @rvantonder
    Yep, the issue is with using returnValues. What you're looking for is the smallest match (closes), but the holes used here will continue matching more, from left-to-right (and returnValues captures things you're not interested in). In general, this is not a question of greediness/laziness, even if returnValues was greedy, the semantics means that it will continue matching left to right, just like .* and .*? does not mean it will match the smallest (tightest) matching string: https://stackoverflow.com/a/21478871
    In general, with the regex problem, you can either use lookahead/look-behind (if the engine supports it) or try make matching more restricted. Usually it is complex and problematic to use lookahead/lookbehind.
    So then the question is what can we do about this in Comby? Based on what is currently possible, my suggestion is to restrict matches. What this means is that you will unfortunately need to use multiple match templates, but all of them together will precisely match what you care about (for function extraction/rewriting and so on).
    Sergey Kostyaev
    @s-kostyaev
    So I can't write "general match pattern" for this case?
    Rijnard van Tonder
    @rvantonder

    These three variants, together, will give you precise matches:
    func (:[name] :[type]) :[methodName.](:[args]) {:[body]}
    func (:[name] :[type]) :[methodName.](:[args]) :[[return]] {:[body]}
    func (:[name] :[type]) :[methodName.](:[args]) (:[multipleReturns]) {:[body]}

    This will guarantee that methodName matches identifiers and not across lines/whitespace. We need three variants to match the three syntactic variants that are possible for Go return values (nothing, one value, or many).

    So I can't write "general match pattern" for this case?

    I don't think it's possible to do that with Comby's current capabilities. I know the multi-pattern thing is awkward, but optional holes are not good enough to deal with this problem

    The good news I can offer is that I'll soon at regular expressions to holes, and then you should be able to right one general pattern, as follows:
    Sergey Kostyaev
    @s-kostyaev

    The good news I can offer is that I'll soon at regular expressions to holes, and then you should be able to right one general pattern

    I look forward to it

    For now I can try to implement look-behind on Emacs side and use one of this 3 patterns. Thank you.
    Rijnard van Tonder
    @rvantonder

    Ok :-) Just to show you what the regex solution would look like, you would do something like this to match the optional receiver part:

    func (:[receiver]) :[[method]](:[args]) :[ret~[\w\s,()]*]{:[body]}

    In this case the ret hole matches the regex [\w\s,()]*, so something that 'looks like' a return value, and is optional. Of course, you will lose the structural properties of matching balanced things here, so it is good to be careful, but it would work well in this case.

    it is possible to use on the https://staging.comby.live server, here's the example:

    This message was deleted
    Whoops that link won't work it doesn't use staging.
    Ok sorry about this, but just go to this link and make it point to staging.comby.live instead of comby.live: bit.ly/3fPQM4z (I'll fix the link sharing here later)
    If you build from source you can also develop against this regex-supported version of comby, you can grab it from this branch: comby-tools/comby#162. The syntax works like I described, the only reason I haven't merged it yet is because there are some whitespace cases to fix.
    Sergey Kostyaev
    @s-kostyaev
    Thank you) I think I'll try this branch.
    Rijnard van Tonder
    @rvantonder
    Sounds good :-)
    Hopefully I can release this in the next week or two 🤞
    Sergey Kostyaev
    @s-kostyaev
    Will wait)
    Rijnard van Tonder
    @rvantonder
    Ok, I can ping you and I'll let you know. Otherwise, I can just release/merge soon and fix the missing parts after, as they are fairly specific and not so important to handle.
    Sergey Kostyaev
    @s-kostyaev
    As you wish) I already subscribed to this PR.
    Sergey Kostyaev
    @s-kostyaev
    @rvantonder , do I need some flag to use regex-hole? I can't make it work:
    %  comby -match-only 'func (:[name] :[type]) :[[method]](:[?args]) :[ret~[\w\s,()]*] {:[before]}' '' .go
    %  comby -match-only 'func (:[name] :[type]) :[[method]](:[?args]) :[ret] {:[before]}' '' .go
    /home/feofan/go/src/playground/at-2020-06-22-124608/snippet.go:25:func (v Vertex) Print() {\n    fmt.Printf("%+v\n", v)\n}\n\nfunc (v *Vertex) Scale(f float64) {\n    v.X = v.X * f\n    v.Y = v.Y * f\n    v.Z = v.Z * f\n}
    Also, it fail checks and I disable it to build this branch:
    ==> Starting build()...
    Nothing to do.
    ==> Starting check()...
         patdiff (internal) (exit 1)
    (cd _build/default && /home/feofan/.opam/4.09.1/bin/patdiff -keep-whitespace -location-style omake -unrefined test/common/test_pipeline.ml test/common/test_pipeline.ml.corrected)
    ------ test/common/test_pipeline.ml
    ++++++ test/common/test_pipeline.ml.corrected
    File "test/common/test_pipeline.ml", line 37, characters 0-1:
     |      ; substitute_in_place = true
     |      ; disable_substring_matching = false
     |      }
     |  ; output_printer = (fun _ -> ())
     |  ; interactive_review = None
     |  }
     |
     |let%expect_test "interactive_paths" =
     |  let _, count =
     |    let scheduler = Scheduler.create ~number_of_workers:0 () in
     |    Pipeline.with_scheduler scheduler ~f:(
     |      Pipeline.process_paths_for_interactive
     |        ~sequential:false
     |        ~f:(fun ~input: _ ~path:_ -> (None, 0)) [])
     |  in
     |  print_string (Format.sprintf "%d" count);
    -|  [%expect_exact {|0|}]
    +|  [%expect.unreachable]
    +|[@@expect.uncaught_exn {|
    +|  (* CR expect_test_collector: This test expectation appears to contain a backtrace.
    +|     This is strongly discouraged as backtraces are fragile.
    +|     Please change this test to not include a backtrace. *)
    +|
    +|  (Division_by_zero)
    +|  Raised at file "src/procs/hack_bucket.ml", line 40, characters 16-51
    +|  Called from file "src/procs/hack_bucket.ml", line 49, characters 14-41
    +|  Called from file "src/interface/scheduler.ml", line 59, characters 10-59
    +|  Called from file "lib/pipeline/pipeline.ml", line 268, characters 6-17
    +|  Called from file "lib/pipeline/pipeline.ml", line 260, characters 15-26
    +|  Called from file "lib/pipeline/pipeline.ml", line 260, characters 15-26
    +|  Called from file "test/common/test_pipeline.ml", line 31, characters 4-165
    +|  Called from file "collector/expect_test_collector.ml", line 225, characters 12-19 |}]
     |
     |let%expect_test "launch_editor" =
     |  let configuration =
     |    { configuration
     |      with interactive_review =
     |             Some
     |               { editor = "vim"
     |               ; default_is_accept = true
     |               }
     |    }
     |  in
     |  let result =
     |    try Pipeline.run matcher configuration; "passed"
     |    with _exc -> "Not a tty"
     |  in
     |  print_string result;
    make: *** [Makefile:28: test] Error 1
    ==> ERROR: A failure occurred in check().
        Aborting...
    Rijnard van Tonder
    @rvantonder

    @s-kostyaev you'll have to remove the space space between :[ret...] and {:[before]}, so that it is just :[ret...]{:[before]}. This is because otherwise comby will try match "space" then then the regex and then space again, which doesn't match the case where there is only one space. Sorry that's not intuitive, that's part of what I'm trying to make easier.

    For the crash: ah, I have to rebase the branch to make those tests pass. It should run OK without the passing checks though.

    Sergey Kostyaev
    @s-kostyaev
    I'll try, thanks.
    Sergey Kostyaev
    @s-kostyaev
    Thank you, @rvantonder ! It works like a charm!
    Vasilij Schneidermann
    @wasamasa
    Hello, having issues building this thing on Arch.
    I've tried building from source with the stock (4.10) and recommended (4.09) version of Ocaml. Stock build fails with an Ocaml syntax error, 4.09 build fails with an error from gcc. Now I've tried building https://aur.archlinux.org/packages/comby/ and get an error for Comby sources:
    ∗ installed shell.v0.12.0
    ∗ installed patdiff.git
    Done.
    
    <><> lwt.4.5.0 installed successfully <><><><><><><><><><><><><><><><><><><><><>
    => Lwt 5.0.0 will make some breaking changes in December 2019. See
         https://github.com/ocsigen/lwt/issues/584
    
    <><> bisect_ppx.git installed successfully ><><><><><><><><><><><><><><><><><><>
    => Bisect_ppx 2.0.0 has deprecated some command-line options. See
         https://github.com/aantron/bisect_ppx/releases/tag/2.0.0
    File "lib/rewriter/rewrite_template.ml", line 22, characters 4-12:
    22 |   | Ok label -> List.find_map label ~f:ident
             ^^^^^^^^
    Error: This pattern matches values of type
             ('a, 'b) Core._result = ('a, 'b) Stdlib.result
           but a pattern was expected which matches values of type
             consume:Angstrom.Consume.t ->
             (string option list, string) Stdlib.result
    make: *** [Makefile:10: release] Error 1
    ==> ERROR: A failure occurred in build().
        Aborting...
    Vasilij Schneidermann
    @wasamasa
    The main difference with this PKGBUILD is that it builds with 4.09.1 which fixed a bad interaction with gcc 10, so you might want to recommend that version instead of 4.09
    Vasilij Schneidermann
    @wasamasa
    It builds now after applying this patch: comby-tools/comby@995e786