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

    Hey @jensim, I can think of two ways to go about this. I think the easiest might be to do your changes and re-format the files for the appropriate indentation (I think you have lots of options here with existing tools).

    There's probably a way to get comby to rewrite it while preserving whitespace, but it means you have to match carefully on tags or blocks to dance around rewriting things that could erase whitespace, here's some examples that might help your case: https://gist.github.com/rvantonder/324a4f1c3a46b15628b72745679bf821

    5 replies
    Stephen Gutekanst
    @slimsag
    Hello :) I'm wondering about integrating Comby search syntax into another search syntax and have a few questions (I'll put details in a thread to avoid spamming)
    18 replies
    ben.txt
    @bentxt
    Hi, comby looks very interesting but even after reading the documentation I'm not sure how far you can go with it. Could you use Comby for adding macros to a language? Or could you generate language bindings from a header file? I think in this cases it would be useful to execute not just one but a sequence of match/rewrite pairs for a target. Is this possible?
    Rijnard van Tonder
    @rvantonder

    I'm not sure how far you can go with it

    Hey @bentxt. I'm not really sure either :-) I think generating bindings could work, it all depends on how much you need to take into account for the use case (e.g., do the bindings need type info? something else?). You could use it for macros--I'm not sure that I would embed it in a language, but would work well for general search-replace things.

    To execute a sequence of match/rewrites you could use a config file: https://comby.dev/docs/configuration#toml-format

    ben.txt
    @bentxt
    Thanks alot for the example, it works great. Why do you have doubts about using as a macro (code transformation) tool?
    ben.txt
    @bentxt
    And another question about your example: Is it possible to recursively transform captured sections ('body' in this case)? Something like rule='where rewrite :[body] xyz?
    Rijnard van Tonder
    @rvantonder

    Why do you have doubts about using as a macro (code transformation) tool?

    I guess it depends where it fits into a toolchain :-) I think it fits well into a preprocessing script, standalone find-replace, or a custom template generation tool. If I were designing a language from scratch with a macro system though, I don't think it's best to, for example, use comby as an external dependency for implementing that macro system--in this case I would rather (eventually) write the macro system for such a language because it would probably be more powerful with language-specific taken into account. But comby could probably work well to prototype things at a very early stage.

    Is it possible to recursively transform captured sections ('body' in this case)?

    If I follow you correctly, sure, have a look at https://comby.dev/docs/advanced-usage#rewrite-expressions. rewrite expressions cannot nest themselves, but usually it's possible to do multiple rewrites to match on a subpart to change. Let me know if you have a specific example.

    ben.txt
    @bentxt
    For example: transform "swap(swap(a,b),swap(c,d))" to "swap(swap(d,c),swap(b,a))"
    ben.txt
    @bentxt
    this is my attempt , which only transforms the inner expressions https://pastebin.com/1JR6v6kc
    ben.txt
    @bentxt
    Ok, I think I have a sligthly better solution, but it still doesn't seem to be recursive, nested captures are getting "unpacked": https://pastebin.com/2BvAwAqN
    Murphy Randle
    @mrmurphy
    Hey, folks! I'm getting a drastically different result when I run my experiment in comby.live (in the browser) vs running it on the same content on-disk. The matches behave differently, though I did the copy-paste from the browser, and the rules look visually correct. Does anyone know if comby.live is using an old version of comby, maybe? And 1.0.0 possibly changed the matching algorithm or something?
    I have a recursive pattern to match, so I'm planning to run comby on the file multiple times. In the browser, the outer occurrence matches, and the replacement works as expected. From the CLI, the inner occurrence matches, not the outer occurrence, and the replacement doesn't work as expected.
    Rijnard van Tonder
    @rvantonder
    Hey @mrmurphy it's possible there's a difference--I think comby.live is not yet running 1.0.0. The main change is that holes, in some languages, will not match across newlines in 1.0.0. If you add
    -match-newline-at-toplevel
    to your CLI command, you should get the same matching behavior as comby.live.
    Murphy Randle
    @mrmurphy
    Thank you @rvantonder !
    Woo! Yeah that indeed fixed it for me
    thanks!
    Rijnard van Tonder
    @rvantonder
    Great. And sorry for the confusion--this change is part of ironing out some issues and things should be clearer soon. comby.live isn't ready to go to 1.0.0 yet so I will add this as a default flag for the copy button.
    Murphy Randle
    @mrmurphy
    That's no problem!
    I have one other super important question :D
    I'm trying to do some massive transformations on Reason source code, and mostly it's working great, but the Reason grammar doesn't understand how to identify the end of a scope within a case expression
    so Reason's case expressions aren't wrapped with braces by default, and refmt strips the braces, so all of my case expressions look like this:
            switch (maybeExisting) {
            | Some(syncable) =>
              let%Pom syncable = SyncableRepo.loadBlob(syncable);
              resolved(syncable);
            | None => Serbet.Abort.notFound("Syncable not found for user")
            };
    The transformation I'm trying to do looks for let%Pom, and transforms all of the following lines in the block
    so I want my match expression to stop when it reaches the line where the next case is declared: None => Serbet....
    instead, the matcher swallows all lines until the closing brace, engulfing the None => case entirely
    is this something that I can change if I fork the Reason matcher and modify the language definition? or is that too sophisticated for Comby's matcher to handle?
    Rijnard van Tonder
    @rvantonder
    My clarifying question is: do things go wrong if you try and match up to the first | (which should terminate matching at the place you want it to)?
    Murphy Randle
    @mrmurphy
    Unfortunately, yes, because there maybe nested switch expressions
    At least, I think it would break in that case, let me try
    Hmm, actually that's okay!
    Rijnard van Tonder
    @rvantonder
    yeah, in general, it makes sense that nesting could break it, but in this case, I think reason will force you to put braces around a nested switch statement (since otherwise Reason wouldn't know it is nested). Because those braces are nested, comby won't match the | inside them, it will match over the entire nested part (skipping any | inside it).
    Murphy Randle
    @mrmurphy
    Yeah, I think that will work well, fantastic! Is there a way to ask comby to repeat a transformation on a file until there are no matches left, to help with recursion?
    2 replies
    Rijnard van Tonder
    @rvantonder
    If you did run into a case where nesting breaks, you can write your own definition, but I'm not sure that it would've helped.
    1 reply
    cal
    @cal101

    Explicit comment token missing?

    Dear Rijnard van Tonder!

    Thank you for comby!
    It is a great idea to take the lexical similarities of computer languages
    and put them into a usable tool.

    Comby feels like the missing link between grep-like-tools and syntactic
    and semantic AST rewriting tools (or at least it's cousin ;-).

    Solving a problem I solved with other tools before (grep/sed/perl,
    syntactic AST-rewriting, refactoring level plugin) is a good way for me
    to get a feeling of a tool.

    So I applied comby to migration of a java test suite from an older
    test framework to a newer one.

    Most of that works good with standard comment handling of tacking it to some
    other match or leaving it alone outside some match.

    The migration involves the following replacement problem adding an annotation:

    Input:

    class ATest extends SomeTestSupport {
    /* my important test blabla /
    public void testSomethhing() {
    assertEquals(3, 1 + 2);
    }
    }

    Output to reach:

    class ATest extends SomeTestSupport {
    /* my important test blabla /
    @Test
    public void testSomethhing() {
    assertEquals(3, 1 + 2);
    }
    }

    The only version that mostly worked implied starting with a generic hole ":[before]"
    but for the known reasons that makes parsing of some other files far too slow.

    I was not able to find any pattern to match the above inside "{" "}" so I used top level
    patterns.

    All usable patterns I found loose the comment before the method.

    Do you have any trick for keeping the comment?

    It would be nice to have a kind of epsilon token for a comment ":[mycomment#]" that
    makes it able to name and reference the "room" between "real" (non-epsilon) tokens or white space.
    Maybe ":[mycomment##]" for all comments at that location.

    My experiments involved some explicit whitespace matching using regexp holes
    but that seems to change the overall parsing behavior in ways not obvious ways for me.
    That made me wonder if there should be a syntax to name and reference the standard whitespace "token"
    of the current language: ":[myws ]".

    And a combination of both with ":[myws# ]".

    The online matching was a good help. I suggest giving it a more prominent place in the documentation
    on the first sides or with some entry in the side menue.

    Thank you for reading so far!
    And hopefully you have a pattern tip for me.

    cal

    1 reply
    Yawar Quadir Amin
    @yamin-oanda
    hi, i am trying to use comby in review mode but it fails to apply patches. setting export DEBUG_COMBY=1 has seemingly no effect. i always just get a message: Error attempting patch, command exited with -7. Run the command again with DEBUG_COMBY=1 set in the environment for more info. Press any key to continue, or exit now (Ctrl-C).
    the command i'm using: comby -review 'Some(:[x])' ':[x].?' src/test/scala/com/oanda/sfb/rates/CandleExchangeRatesSpec.scala
    this is from the project root
    Yawar Quadir Amin
    @yamin-oanda
    i also tried using just -diff but the output diff can't be applied with git...
    it seems because the diff headers have the absolute path of the files, instead of the relative paths
    Yawar Quadir Amin
    @yamin-oanda
    working around that for now by going into the exact directory
    Rijnard van Tonder
    @rvantonder
    @yamin-oanda the patches are applied using patch -p0, so there's some issue with that failing. Could you tell me what you see after you do this:
    comby 'Some(:[x])' ':[x].?' src/test/scala/com/oanda/sfb/rates/CandleExchangeRatesSpec.scala -diff > p.patch 
    patch -p0 --verbose < p.patch
    Yawar Quadir Amin
    @yamin-oanda
    thanks! i'll try that
    btw comby is really cool. thanks for making it :-)
    Yawar Quadir Amin
    @yamin-oanda
    yes–patch -p0 works! thanks
    4 replies
    Raphaël Duchaîne
    @duchainer
    Hi, seems to be a great tool to add to my emacs toolbelt, but is comby.dev down for anybody else? I can use comby.live no problem but can't seem to access anything on the comby.dev domain.
    2 replies
    Jens
    @jensim
    I was making a long set of pipes in bash today, and found myself wanting to use comby in the pipe to mutate and output, would have been a nice fit this time. But I do t see an stdout option to accompany the stdin one
    14 replies
    Maybe I just missed something.. Did not read the comby -help | grep stdout, just the comby.dev search
    Rijnard van Tonder
    @rvantonder
    Sounds like -stdout should work for you!
    Oskar Hermansson
    @oskar
    Hi! There is language support for C# in comby but it doesn't look like it's available on the playground / comby.live. Any particular reason for that?
    Oskar Hermansson
    @oskar
    Would it be enough to just extend this list? :) https://github.com/comby-tools/comby-ui/blob/master/LanguageExtension.elm