Giter Club home page Giter Club logo

Comments (15)

casey avatar casey commented on July 30, 2024 1

If this is supported, I'm inclined to do it with python's f-string syntax: f'some string with{{interpolation}}'

from just.

crabmusket avatar crabmusket commented on July 30, 2024 1

I'm working around this using replace:

value := env_var('VALUE')
result := replace('here is _, _ a pair of values', '_', value)

It's acceptable if you're only using one value multiple times like I am; it would get gnarly with multiple values and replacements.

from just.

casey avatar casey commented on July 30, 2024

This does introduce the odd scenario where you can have interpolation inside a string inside an interpolation inside a string, etc, etc, etc.

from just.

casey avatar casey commented on July 30, 2024

Closing. If anyone wants this, comment and I'll reopen it!

from just.

casey avatar casey commented on July 30, 2024

Maybe thinking that we should do this. Reopening.

from just.

kwshi avatar kwshi commented on July 30, 2024

Interesting how nobody has taken this on yet! I am quite interested in having this and have some basic experience working w/ lexers/parsers for other things, so maybe I'll try to take a look soon-ish and see if I can help make this happen!

from just.

casey avatar casey commented on July 30, 2024

I started working on this, in-progress branch here.

I marked this as "good first issue", but I think that's misleading, because it's super hard!

I've gotten lexing and parsing mostly working, but I haven't done evaluation, i.e. actually evaluating the fragments, concatenating them, and, in the case of format backticks, evaluating the result.

If your interested, you could pick up the branch as a starting point. I'm not sure when I'm going to work on it again.

from just.

pyrsmk avatar pyrsmk commented on July 30, 2024

Is there any news on the subject?

edit: without this I'm forced to go back to make 😅

from just.

casey avatar casey commented on July 30, 2024

Is there any news on the subject?

This is a big feature, so time to implementation is unknown.

from just.

ngirard avatar ngirard commented on July 30, 2024

Could this crate be any helpful ?

MiniJinja -- Powerful but minimal dependency template engine for Rust

Announcement on r/rust (2021-09-24).

MiniJinja is a powerful but minimal dependency template engine for Rust which is based on the syntax and behavior of the Jinja2 template engine for Python.

It's implemented on top of serde and only has it as a single dependency. It supports a range of features from Jinja2 including inheritance, filters and more. The goal is that it should be possible to use some templates in Rust programs without the fear of pulling in complex dependencies for a small problem. Additionally it tries not to re-invent something but stay in line with prior art to leverage an already existing ecosystem of editor integrations.

Cheers

from just.

casey avatar casey commented on July 30, 2024

Could this crate be any helpful ?

MiniJinja -- Powerful but minimal dependency template engine for Rust

The template language isn't so much the hard part, it's the rest of the integration, so a crate wouldn't be a huge help.

from just.

pyrsmk avatar pyrsmk commented on July 30, 2024

For those who might be interested, I developed a simple task system based on the Ruby language.

I needed something effective, pretty simple to use and quick to develop for a project. It already proved itself to be quite powerful : https://github.com/pyrsmk/run

from just.

kallangerard avatar kallangerard commented on July 30, 2024

Is a format expression an easier compromise? I can live without interpolation if there's a string.format(str, args*) method available.

foo := "github.com"
api_uri := "api/v2"
foo_url := string_format("https://%s/%s", foo, api_uri)

from just.

regmicmahesh avatar regmicmahesh commented on July 30, 2024

i'm hoping for this addition.

from just.

akiross avatar akiross commented on July 30, 2024

I'm also interested in this kind of functionality (edit: I'm interested in substitution in backticks in particular), but actually I don't care that this is provided using backticks: for my current use case, a function could be fine as well. Would something like an eval(string) function be simpler to implement? In that way, we could compose strings and use variables inside expressions:

world := "World!"

greet arg=world:
    echo "Hello {{ eval("echo " + arg) }}"

I took a quick look at the code and if the implementation is performed trivially, one could implement a new eval function that basically replicates what is being done in run_backtick, although it seems that there is no access to Settings from the FunctionContext (and I didn't investigate if that's something that belongs in there).

Edit 2:
I would also consider functions to substitute in strings. I think it's a simpler approach that would provide the feature in backward-compatible way and does not rely on the parser.

from just.

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.