oils-for-unix / oils

Oils is our upgrade path from bash to a better language and runtime. It's also for Python and JavaScript users who avoid shell!
http://www.oilshell.org/
Other
2.85k stars 159 forks source link

Kebab-Case Identifiers in Expression Mode #2088

Open PossiblyAShrub opened 1 month ago

PossiblyAShrub commented 1 month ago

From Zulip: #language-design>Kebab-Case literal syntax

I'm finding that getVar("my-proc") feels really jarring. It's nice for the dynamic case, but I'd like to somehow reference my-proc without getVar...

Rust has a r#ident syntax for restricted keywords:

error: expected identifier, found keyword `else`
  --> $DIR/keyword-else-as-identifier.rs:4:9
   |
LL |     let else = "foo";
   |         ^^^^ expected identifier, found keyword
   |
help: escape `else` to use it as an identifier
   |
LL |     let r#else = "foo";
   |         ++

error: aborting due to 1 previous error

Could we extend this so we can write y#my-proc or y#else?

Current ideas are:

andychu commented 1 month ago

This kind of thing is also useful for metaprogramming

for example in mycpp we have to special case flag.extern, derived from --extern, as flag.extern_

Because extern is a C++ keyword

We also have the same issue with Python keywords

So if we provide a function quoteName() or ${x|yshName}, which does the correct quoting, then it will make metaprogramming slightly cleaner


This is slightly related to the thread with Julian about 4 ways to generate procs dynamically

Although I guess in that case it was mostly foo-$suffix, which is usually OK