Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Ben Briggs
    @ben-eb
    Yeah, I don't know how difficult that'd be to implement in a language agnostic way. Thanks for your insights!
    Rijnard van Tonder
    @rvantonder
    I think there's a way, it probably means handing over more user control/configuration over the parsing steps.
    Jason Keene
    @jasonkeene
    Hello, I just discovered Comby and am loving it! I'm looking for help trying to match the middle case in this example: http://bit.ly/33fiEL8
    It involves matching a sub expression that may or may not be nested at different levels of {} delimiters. Is there any way to match no matter how many levels the sub expression might be?
    Jason Keene
    @jasonkeene
    I was thinking I might be able to use the regex matching syntax to match { but I can't get it to work :/
    Rijnard van Tonder
    @rvantonder

    Hey @jasonkeene glad it's working for you. Right, so by default when the template contains {...} and then a pattern inside, it will only match at that top level of {...}. The only way right now to match a pattern inside {...} in a way that doesn't care about the level of matching is to use a match or rewrite rule. Here's what I think you're aiming for:

    func Test:[a](:[b] *testing.T):[c] {:[body]}

    with a rewrite rule:

    where rewrite :[body] {
    "if x == y { return:[e] }" -> "skipCond(:[b])"
    }

    Link: https://bit.ly/35jIrUL

    When a rule fires on some matched content like :[body], it doesn't care about the level of nesting (it's as if that content is extracted and then running comby only on that part). A side effect here is that you don't need to :[d] or :[f] parts which were basically 'anything' in the previous template--and also, the previous template would stop matching at the first if x == y as well, while the rule will continue and match all instances.

    This use case comes up often enough that it makes sense for me to introduce an inline notation to express 'match this expression inside these {...}at any level' so you don't need to write out a separate rule. Related tools like Coccinelle use a kind of notation like <... stuff ...> to express this, and I'm thinking about something similar in comby, something like, say,

    func func Test:[a](:[b] *testing.T):[c] {
    <... if x == y { return:[e] } ...>
    }

    where this syntax just means that the rule above is created for you :-) Still TBD

    Jason Keene
    @jasonkeene
    So awesome! Thanks for the pointers. I will do more reading on rewrite functionality.
    Stefan Buck
    @stefanbuck

    Hello, looks like comby 0.18 introduced a breaking change, but I guess this was intended . The simplify of matching for :[hole]: is causing different outputs when using comby 0.15.0 vs. 0.18.3.

    Given the follwoing input file

    <button>Single line</button>
    <button>
        Multi-line
    </button>

    You can use this bash script to compare output of comby 0.15.0 and 0.18.3.

    COMBY_M="<button>:[hole]</button>"
    COMBY_R="<button>###:[hole]###</button>"
    
    echo 'Output comby-0.15.0\n'
    comby-0.15.0 "$COMBY_M" "$COMBY_R" ./test.html -stdout
    
    echo '\n---------------------\nOutput comby-0.18.3\n'
    comby-0.18.3 "$COMBY_M" "$COMBY_R" ./test.html -stdout

    Both comby calls should produce the same output, but 0.18.3 behaves different which seems to be related to the change introduced in 0.18.0.

    Output comby-0.15.0
    
    <button>###Single line###</button>
    <button>###
        Multi-line
    ###</button>
    
    ---------------------
    Output comby-0.18.3
    
    <button>###Single line###</button>
    <button>
        Multi-line
    </button>

    I wonder how I can replicate the same output with a single match template.

    Rijnard van Tonder
    @rvantonder

    @stefanbuck Ah, you're right! Shoot, it wasn't intended to be a breaking change, I (wrongly) assumed that the single/multiline change would preserve all previous behaviors. I'm going to revert this change and make the new behavior available under a flag.

    Separately, I'll then bump the major version where this flag/behavior is enabled by default, since I do think enabling it is a better default behavior for the vast majority of use cases. The new default behavior won't better for your HTML case yet (in which case, the flag will need to be turned off if you decide to use the new major version), however I will make it work by default for the XML/HTML case at a later point, it just needs some bigger changes.

    Thanks for feedback!

    Stefan Buck
    @stefanbuck
    Cheers, thanks for the quick reply @rvantonder
    Murphy Randle
    @mrmurphy
    Hey folks! Here's a quick question. I'm trying to match everything that comes after a pattern to the end of the block. I've read the docs, and I think I'm doing it the way i'm supposed to, but it's not working how I'd expect:
    I want all these lines to be matched in blue:
    image.png
    and I thought that :[rest] would match until a closing block character, including newlines
    oh wait, I did it!
    had to increase the matching pattern to include the braces
    Volkan Unsal
    @volkanunsal
    Hi everyone. I'm trying to use the template file to process a file in the current directory. But I keep getting errors like this one: Could not read required match file in .
    This is the command I'm using comby -config . -f .js. And there is a file named index.js in the current directory.
    Rijnard van Tonder
    @rvantonder

    Hey @volkanunsal! Are you using a configuration file like this: https://comby.dev/docs/configuration

    or a directory layout like this: https://comby.dev/docs/cheat-sheet#run-multiple-search-and-replace-templates

    For configuration files, you'll have to point to -config ./your-file.toml. For directories, the directory (in this case, the current one) would need to contain a file called match with the pattern.

    Volkan Unsal
    @volkanunsal
    Ahhhh... so that's what the match file is. I totally didn't get that was the name of the file and thought perhaps it wasn't matching anything.
    After correcting the command to comby -config comby.toml -f .jsx it seems to be working. :)
    Rijnard van Tonder
    @rvantonder
    Yeah, there are two modes for that flag, so it's a bit confusing. Hope you got your pattern working now
    Monty Zukowski
    @montyz
    Hello, is comby suitable for distinguishing between different types of constants? I'd like to match a function call like setScore(:[1]) and then take different actions based on whether [:1 is a string literal, an integer, a decimal, or an expression. I see that pattern matching can use text or regex. Is there a way to dig a little deeper into comby's type of the match?
    Monty Zukowski
    @montyz
    Here's a stab at it https://bit.ly/36vdHRo. The issue right now is that I want setScore(4/3) to evaluate to true, but it matches against | ":[_~\\d+]" -> false because I guess it's matching against the prefix. Not sure how to get around that.
    Monty Zukowski
    @montyz
    This is a little better https://bit.ly/2SiuQFN I'm not so happy with how I did it, but I can't think of an alternative way.
    Rijnard van Tonder
    @rvantonder

    Hey @montyz . Casing out on syntax, like you're doing, is the only way to achieve this right now. Using a program's actual type information is something I've wanted to incorporate for a while, but depends a lot on the language. I'm curious what language you are working in, it might be a good fit for combining type info that way.

    For the rules, I think what you came up with is likely the closest you can get right now. The trouble you're having is that match will try find that pattern anywhere in the string (and like you say, matches the prefix). To control that, a helpful answer I want to give you is that you can use regex anchors ^...$ to match whether something is only digits (i.e., integer) and everything else should be checked (which seems to be what you're trying to do?). Unfortunately, that's missing from comby, but I coded up a fix here, and the rule becomes a lot simpler: https://github.com/comby-tools/comby/commit/cbdeaf8e1b4bb86557d6d60418568c0a3f1aca77#diff-f7592766e6cb7ff52ef4395d4e49389aR276-R279

    Monty Zukowski
    @montyz
    I'm working with JavaScript
    ah yeah that's helpful, thanks!
    Rijnard van Tonder
    @rvantonder
    I'll publish a release in the next day or two with the change.
    Monty Zukowski
    @montyz
    OK, thanks!
    Volkan Unsal
    @volkanunsal
    Thanks Rijnard. I got it working.
    I had another question for you, though. Is it possible to use "not" syntax in the -exclude flag. e.g.
    comby -config comby.toml -f .jsx -i -exclude '!*.comby.*'
    That is to say, don't include any files that don't have comby in the file name.
    Volkan Unsal
    @volkanunsal
    Actually, this is not so important. I can save the files with a different extension. :)
    Rijnard van Tonder
    @rvantonder

    That's probably best for now. -exclude '!...' sounds like a double negation so what you're probably really after is a way to include file paths like .*comby.*\.jsx? Piping results of a command like :

    find . -name "*comby*.jsx"is maybe another way. But yeah, there's no flag to do this only with comby right now

    Oliver Joseph Ash
    @OliverJAsh
    I am trying to convert a.pipe(b, c) to pipe(a, b, c). This should include versions like this.a.pipe(b, c) and this.a().pipe(b, c). It should not include versions like const object = { ...pipe(a, b, c) }.
    Can anyone recommend a way to match this precisely? I thought :[a.].pipe(:[b]) would do it, but it doesn't match new lines as I would want it to, and it incorrectly matches the object spread example I gave.
    For context the language is JavaScript/TS. Essentially the match should work on any call expression for a method called pipe
    Rijnard van Tonder
    @rvantonder

    Hey @OliverJAsh. Good question. Your intuition about :[a.] is good. The reason that doesn't work is because it doesn't match special syntax like (). There is an undocumented way to get what you want. It's undocumented because I was experimenting with more ways to match constructs like that one, but haven't settled on a suitable syntax yet :-).

    You can do so by changing :[a.] to :[a:e]: https://bit.ly/36JpYC6. You can think of the :e syntax meaning ' match an expression-like element'. It matches contiguous sequences of (...), {...}, [...] as well as characters matched by :[a.].

    Oliver Joseph Ash
    @OliverJAsh

    Awesome thank you @rvantonder. Do you have any ideas how I can get it to match new lines as well? E.g.

    this
      .a()
      .pipe(b, c)

    bit.ly/34Hhc4W

    Oliver Joseph Ash
    @OliverJAsh
    Unfortunately it looks like :[a:e] still matches the object spread example I gave bit.ly/3iLfIeB
    Rijnard van Tonder
    @rvantonder

    @OliverJAsh there isn't a very elegant way to deal with negating { matching-pattern } but in general you may be able to get away with using regex. Here's an example where you optionally match on leading or trailing { }s around your expression, and can use a rule to filter the match based on whether, say, start matched {, or the empty string: https://bit.ly/36OCuQD. Whether this works for you depends on whether that assumption is strong enough to filter out unwanted matches.

    I think it's real tricky to deal with matching that pattern over newlines. You can certainly tweak the matching to include newlines, but the problem is that it's difficult to distinguish statements like these in Comby:

    first.statement()
    second.statement()
      .across()
      .newline()

    , because it doesn't know enough about the JS grammar to understand the rules for sequencing with . and how it can spread over newlines/whitespace. The way I came up with would be to deal with this syntax in its own way, but I'm not sure that it'll work for you and it's crude. The idea is basically to say "OK, a chain can be something like an identifier followed by one or more lines that perform an access like .foo that must be prefixed by <whitespace><dot>". Once all that syntax is matched, I use a rule to rewrite the ones that call pipe https://bit.ly/3dg2mGs. I don't know if this works in general, it's just my attempt to deal with multi-line chains like this, and Comby might just not be a good fit for this problem until there's a way to teach it more about JS :-)

    Rijnard van Tonder
    @rvantonder
    Update, you'll probably want to use something more like https://bit.ly/2I6vd4e to match valid starts of an access chain.
    Oliver Joseph Ash
    @OliverJAsh
    Thank you for your help! <£
    <3
    AJ ONeal
    @coolaj86

    Is there a way to do text transformation?

    I have an application with hundreds of routes that look like this:

    app.get("/foo/bar", auth, (req, res) => {
      // ... do stuff
    })

    I want to convert them to something like this:

    app.get("/foo/bar", auth, getFooBar);
    function getFooBar (req, res) {
      // ... do stuff
    }
    AJ ONeal
    @coolaj86
    I'm close, but I don't see any docs for updating the strings bit.ly/38iqKH1
    Rijnard van Tonder
    @rvantonder

    @coolaj86 nice idea. Unfortunately there's no builtin for capitalizing strings/letters. That's something worth mentioning in the docs, so I'll update it. Capitalizing strings came up before a handful of times, so it might be something worth adding.

    Anyway, right now there is only a workaround using a rewrite rule--it works, but it's a bit silly :-) Assuming your routes are alphanumeric, you can rewrite parts of a string like /f to F for each letter. Here's a short version for getFooBar so you get the idea:

    where 
    match :[path] {| ":[fn]" -> true },
    rewrite :[fn] { "/f:[[w]]" -> "F:[w]" },
    rewrite :[fn] { "/b:[[w]]" -> "B:[w]" }

    https://bit.ly/362jA6I (expand the where... box.)

    I went ahead and made you a config file for your refactor with a rule that translates all the letters--I might just make a rule like this a builtin somewhere :-) See https://gist.github.com/rvantonder/01b930f7e5d081a5c84f6074fbf3bd13

    (FYI I generated the tedious part of the rule using comby https://bit.ly/323bNo4)

    AJ ONeal
    @coolaj86
    @rvantonder Thanks. There were a few things like that that I needed to do so I ran some JavaScript and RegExp.
    Rijnard van Tonder
    @rvantonder
    Cool @coolaj86 :-) I'd be interested to know what that ended up looking like, maybe I can more directly support that sort of thing
    AJ ONeal
    @coolaj86

    @rvantonder I found some bugs (Ithink), but I don't know if they're worth fixing:

    There was some code like this

    app.get('/*', foo)

    and it seemed to treat the string '/*' as a comment block.

    There was also a regex that it failed to ignore, it was something like this:

    app.get(/\(.*\)/, foo)

    and it seems to have interpreted the stuff in the regex as a closing ).

    I'll find out what it actually is and post the example.