Giter Site home page Giter Site logo

Comments (6)

kimjisena avatar kimjisena commented on May 4, 2024 1

Thanks for building ain. Totally love it! I also liked your post on atomic commits.

from ain.

jonaslu avatar jonaslu commented on May 4, 2024 1

Thanks for those kind words!

from ain.

jonaslu avatar jonaslu commented on May 4, 2024

Hi, thanks for reporting!

There is no current way of escaping # yet. I'll think of what makes more sense - escaping it like \# everywhere or leaving it within quotes.

In the meantime - since this is JSON - you can get around this particular case by using unicode escaping like so:

{
  "email": "[email protected]",
  "password": "0x143\u0023",
  "user_type": "tenant"
}

from ain.

jonaslu avatar jonaslu commented on May 4, 2024

Hi!

I've thought about this and I'd like to keep things such as quoting and escaping out of the way as much as possible in ain. Quoting is only mandatory in 4 places, whitespace in arguments to executables, backend-options, $EDITOR and template-names when piping. Quoting is needed there, while the rest of the template is plain text.

So for escaping comments, I'm thinking one syntax everywhere including inside quotes is simpler than one syntax outside quotes (the majority of the cases) and yet another syntax inside quotes. More syntaxes to keep in your head. The quotes in your JSON-example are accidental because it's JSON, it's not quotes ain knows or cares about.

So, here's my idea. Things that have meaning to ain are #, ${, $( and [Headings] on a new line. All will be escaped with a backtick (`). The backtick is visually non-intrusive and unlikely to occur in elsewhere in the template. Escaping the backtick itself is only necessary if you want a literal backtick immediately followed by one of the four cases that have meaning to ain.

`# <- Escaped comment. Outputted as #
\`# <- Escaped ` immediately followed by a comment
`${ <- Escaped envvar. Outputted as ${
\`${ <- Escaped ` immediately followed by an actual envvar expression
`${ <- Escaped executable. Outputted as $(
\`${ <- Escaped ` immediately followed by an actual executable expression

And for symmetry (although escaping a section (e g \[Headers]) is already supported and we'll keep that but not mention it):

`[Headers] <- Escaped section if preceded only by whitespace on a line.
\`[Headers] <- Literal ` followed by the literal [Headers] preceded only by whitespace on a line.

The backtick enables escaping only in the cases above, everywhere else it's interpreted verbatim and no escaping of it is needed. E g abc`123 is passed as abc`123 and no \` is needed. Only in the rare cases above.

This way quoting gets out of the way as much as possible. Escaped comments are 97% of what people will use. %3 might need the escaped $( and ${ and I'll bet no-one will need the escaped backtick followed by a literal comment, envvar or executable expression.

Makes sense?

from ain.

kimjisena avatar kimjisena commented on May 4, 2024

Hi @jonaslu!

Thanks for taking your time to think about this.
Based on your explanation above, I think that approach would work okay.

from ain.

jonaslu avatar jonaslu commented on May 4, 2024

Done in commit 4917c65

from ain.

Related Issues (9)

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.