GithubHelp home page GithubHelp logo

Comments (5)

rvantonder avatar rvantonder commented on June 8, 2024

Hi @jacobbednarz! I would do it with a rewrite rule.

You can add this to the command line invocation with

-rule 'where rewrite :[topic] { :[x]s -> :[x] }'

Basically, this rule fires and rewrites topic if :[x]s matches and leaves it untouched otherwise.

Docs for this: https://comby.dev/docs/advanced-usage#rewrite-expressions

I thought about and tried regex with lookahead (comby supports perl regex in that syntax) and things like boundary assertions (but those don't seem to pan out and probably misleading / tricky behavior to reason about)

from comby.

jacobbednarz avatar jacobbednarz commented on June 8, 2024

ah thank you! I didn't even click that a rule could be applicable here. appreciate it!

from comby.

jacobbednarz avatar jacobbednarz commented on June 8, 2024

sorry for reusing this issue but i've got some behaviour here that i'm not sure about - https://bit.ly/3vGPy9f.

my expectation is that /zones/{foo}/rulesets/phases/{bar}/entrypoint/versions/{baz} becomes /zones/{zone_id}/rulesets/phases/{phase_id}/entrypoint/versions/{version_id} however, for some reason, the "s" in the middle of these words is being targeted. am i holding this wrong? or is there a different syntax i should be using here instead?

from comby.

rvantonder avatar rvantonder commented on June 8, 2024

hey @jacobbednarz, good question, it seems I simplified this in my head too early 😄

I'll give a workaround before the longer explanation. It is a bit trickier to grok but I think it works in the general case:

https://bit.ly/47G5PbN

Basically, we make the / of the path part of the match, and then we can use that context to chop off an s before / (and not just any s, which is what was happening before). Note the changes to the rule and the output pattern.

Strictly speaking you only need to match the trailing / so this also works:

https://bit.ly/48HAua6

Long explanation,

What was happening before is that, the way comby matches something like :[x]s is "match as much as possible until you see the thing after it (in this case s)". So when it matches against phases, it matches up to pha, sees an s after it, and stops. so we end up with two :[x]s -> :[x] happening twice for phases -> [pha][e]. But what we really want is only the last s. How do we know what is "last"? It turns out it's difficult to use regex or comby to say what is "last", and we don't have a "chop suffix" function or something like that yet. But based on your pattern, we know that a / means the s before it is "last", so we are using that fact to chop the suffix. Hope that helps

from comby.

jacobbednarz avatar jacobbednarz commented on June 8, 2024

ah, that makes perfect sense! thanks again 🥇

from comby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.